Skip to content

Commit

Permalink
cda: use aliases in the first feature section of docs (digital-asset#…
Browse files Browse the repository at this point in the history
…12720)

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
Robin Krom authored Feb 3, 2022
1 parent c34f042 commit 9e1fe24
Showing 1 changed file with 34 additions and 35 deletions.
69 changes: 34 additions & 35 deletions templates/create-daml-app-test-resources/messaging.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
diff --git templates/create-daml-app/daml/User.daml templates/create-daml-app-test-resources/daml/User.daml
index a1789d5..a007b95 100644
--- templates/create-daml-app/daml/User.daml
+++ templates/create-daml-app-test-resources/daml/User.daml
@@ -27,6 +27,16 @@ template User with
diff -Naur templates/create-daml-app/daml/User.daml templates/create-daml-app-test-resources/daml/User.daml
--- templates/create-daml-app/daml/User.daml 2022-02-02 17:09:01.301176478 +0100
+++ templates/create-daml-app-test-resources/daml/User.daml 2022-02-02 17:17:07.624855269 +0100
@@ -27,6 +27,16 @@
create this with following = userToFollow :: following
-- FOLLOW_END

Expand All @@ -19,7 +18,7 @@ index a1789d5..a007b95 100644
-- ALIAS_BEGIN
template Alias with
username: Party
@@ -46,3 +56,12 @@ template Alias with
@@ -45,3 +55,12 @@
archive self
create this with alias = newAlias
-- ALIAS_END
Expand All @@ -32,21 +31,21 @@ index a1789d5..a007b95 100644
+ where
+ signatory sender, receiver
+-- MESSAGE_END
diff --git templates/create-daml-app/ui/src/components/MainView.tsx templates/create-daml-app/ui/src/components/MainView.tsx
--- templates/create-daml-app/ui/src/components/MainView.tsx
+++ templates/create-daml-app/ui/src/components/MainView.tsx
@@ -8,6 +8,10 @@ import { User } from '@daml.js/create-daml-app';
import { useParty, useLedger, useStreamFetchByKey, useStreamQueries } from '@daml/react';
diff -Naur templates/create-daml-app/ui/src/components/MainView.tsx templates/create-daml-app-test-resources/ui/src/components/MainView.tsx
--- templates/create-daml-app/ui/src/components/MainView.tsx 2022-02-02 17:09:01.309176539 +0100
+++ templates/create-daml-app-test-resources/ui/src/components/MainView.tsx 2022-02-02 17:47:40.054336940 +0100
@@ -8,6 +8,10 @@
import { useParty, useLedger, useStreamFetchByKeys, useStreamQueries } from '@daml/react';
import UserList from './UserList';
import PartyListEdit from './PartyListEdit';
+// IMPORTS_BEGIN
+import MessageEdit from './MessageEdit';
+import MessageList from './MessageList';
+// IMPORTS_END

// USERS_BEGIN
const MainView: React.FC = () => {
@@ -78,6 +82,22 @@ const MainView: React.FC = () => {
@@ -88,6 +92,23 @@
/>
{/* USERLIST_END */}
</Segment>
Expand All @@ -61,21 +60,19 @@ diff --git templates/create-daml-app/ui/src/components/MainView.tsx templates/cr
+ </Header>
+ <MessageEdit
+ followers={followers.map(follower => follower.username)}
+ partyToAlias={partyToAlias}
+ />
+ <Divider />
+ <MessageList />
+ <MessageList partyToAlias={partyToAlias}/>
+ </Segment>
+ {/* MESSAGES_SEGMENT_END */}
</Grid.Column>
</Grid.Row>
</Grid>
diff --git templates/create-daml-app/ui/src/components/MessageEdit.tsx templates/create-daml-app/ui/src/components/MessageEdit.tsx
--- /dev/null
+++ templates/create-daml-app/ui/src/components/MessageEdit.tsx
@@ -0,0 +1,70 @@
+// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
diff -Naur templates/create-daml-app/ui/src/components/MessageEdit.tsx templates/create-daml-app-test-resources/ui/src/components/MessageEdit.tsx
--- templates/create-daml-app/ui/src/components/MessageEdit.tsx 1970-01-01 01:00:00.000000000 +0100
+++ templates/create-daml-app-test-resources/ui/src/components/MessageEdit.tsx 2022-02-03 12:42:06.144235635 +0100
@@ -0,0 +1,69 @@
+// MESSAGEEDIT_BEGIN
+import React from 'react'
+import { Form, Button } from 'semantic-ui-react';
Expand All @@ -85,12 +82,13 @@ diff --git templates/create-daml-app/ui/src/components/MessageEdit.tsx templates
+
+type Props = {
+ followers: Party[];
+ partyToAlias: Map<string, string>;
+}
+
+/**
+ * React component to edit a message to send to a follower.
+ */
+const MessageEdit: React.FC<Props> = ({followers}) => {
+const MessageEdit: React.FC<Props> = ({followers, partyToAlias}) => {
+ const sender = useParty();
+ const [receiver, setReceiver] = React.useState<string | undefined>();
+ const [content, setContent] = React.useState("");
Expand All @@ -115,13 +113,14 @@ diff --git templates/create-daml-app/ui/src/components/MessageEdit.tsx templates
+
+ return (
+ <Form onSubmit={submitMessage}>
+ <Form.Dropdown
+ selection
+ <Form.Select
+ fluid
+ search
+ className='test-select-message-receiver'
+ placeholder="Select a follower"
+ options={followers.map(follower => ({ key: follower, text: follower, value: follower }))}
+ placeholder={receiver ? partyToAlias.get(receiver) ?? receiver : "Select a follower"}
+ value={receiver}
+ onChange={event => setReceiver(event.currentTarget.textContent ?? undefined)}
+ options={followers.map(follower => ({ key: follower, text: partyToAlias.get(follower) ?? follower, value: follower }))}
+ onChange={(event, data) => setReceiver(data.value?.toString())}
+ />
+ <Form.Input
+ className='test-select-message-content'
Expand All @@ -143,23 +142,23 @@ diff --git templates/create-daml-app/ui/src/components/MessageEdit.tsx templates
+
+export default MessageEdit;
+// MESSAGEEDIT_END
diff --git templates/create-daml-app/ui/src/components/MessageList.tsx templates/create-daml-app/ui/src/components/MessageList.tsx
--- /dev/null
+++ templates/create-daml-app/ui/src/components/MessageList.tsx
diff -Naur templates/create-daml-app/ui/src/components/MessageList.tsx templates/create-daml-app-test-resources/ui/src/components/MessageList.tsx
--- templates/create-daml-app/ui/src/components/MessageList.tsx 1970-01-01 01:00:00.000000000 +0100
+++ templates/create-daml-app-test-resources/ui/src/components/MessageList.tsx 2022-02-02 17:47:13.646655436 +0100
@@ -0,0 +1,33 @@
+// Copyright (c) 2022 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+// MESSAGELIST_BEGIN
+import React from 'react'
+import { List, ListItem } from 'semantic-ui-react';
+import { User } from '@daml.js/create-daml-app';
+import { useStreamQueries } from '@daml/react';
+
+type Props = {
+ partyToAlias: Map<string, string>
+}
+/**
+ * React component displaying the list of messages for the current user.
+ */
+const MessageList: React.FC = () => {
+const MessageList: React.FC<Props> = ({partyToAlias}) => {
+ const messagesResult = useStreamQueries(User.Message);
+
+ return (
Expand All @@ -170,7 +169,7 @@ diff --git templates/create-daml-app/ui/src/components/MessageList.tsx templates
+ <ListItem
+ className='test-select-message-item'
+ key={message.contractId}>
+ <strong>{sender} &rarr; {receiver}:</strong> {content}
+ <strong>{partyToAlias.get(sender) ?? sender} &rarr; {partyToAlias.get(receiver) ?? receiver}:</strong> {content}
+ </ListItem>
+ );
+ })}
Expand Down

0 comments on commit 9e1fe24

Please sign in to comment.