Skip to content

Commit 0019c2e

Browse files
authored
Merge pull request #298 from rebeccaalpert/truncation
fix(Message): Truncate very long names
2 parents 08956ec + 2baf80a commit 0019c2e

File tree

5 files changed

+27
-6
lines changed

5 files changed

+27
-6
lines changed

packages/module/patternfly-docs/content/extensions/virtual-assistant/examples/Messages/BotMessage.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
33
import patternflyAvatar from './patternfly_avatar.jpg';
44

5-
export const AttachmentMenuExample: React.FunctionComponent = () => {
5+
export const BotMessageExample: React.FunctionComponent = () => {
66
const markdown = `
77
Here is some YAML code:
88
@@ -62,18 +62,26 @@ export default MessageLoading;
6262

6363
return (
6464
<>
65+
<Message name="Bot" role="bot" avatar={patternflyAvatar} content={`Text-based message from a bot named "Bot"`} />
6566
<Message
6667
name="Bot"
6768
role="bot"
6869
avatar={patternflyAvatar}
69-
content="Example content with updated timestamp text"
70+
content={`Text-based message from a bot named "Bot," with updated timestamp`}
7071
timestamp="1 hour ago"
7172
/>
7273
<Message name="Bot" role="bot" avatar={patternflyAvatar} content={markdown} />
7374
<Message name="Bot" role="bot" avatar={patternflyAvatar} content={orderedList} />
7475
<Message name="Bot" role="bot" avatar={patternflyAvatar} content={unorderedList} />
7576
<Message name="Bot" role="bot" avatar={patternflyAvatar} content={moreComplexList} />
7677
<Message name="Bot" role="bot" avatar={patternflyAvatar} content="Example content" isLoading />
78+
<Message role="bot" avatar={patternflyAvatar} content="Text-based message from a nameless bot" />
79+
<Message
80+
name="Default Openshift Container Platform Assistant That Can Help With Any Query You Might Need Help With"
81+
role="bot"
82+
avatar={patternflyAvatar}
83+
content="Text-based message, where the bot's name is truncated"
84+
/>
7785
</>
7886
);
7987
};

packages/module/patternfly-docs/content/extensions/virtual-assistant/examples/Messages/Messages.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ Messages from the chatbot will be marked with an "AI" label to clearly communica
5050

5151
<br />
5252

53-
By default, a date and timestamp is displayed with each message. You can update `timestamp` with a different [date and time format](/ux-writing/numerics) as needed.
53+
By default, a date and timestamp is displayed with each message. We recommend using the `timestamp` prop in real chatbots, since it will allow you to set persistent dates and times on messages, even if the messages re-render. You can update `timestamp` with a different [date and time format](/ux-writing/numerics) as needed.
5454

5555
```js file="./BotMessage.tsx"
5656

packages/module/patternfly-docs/content/extensions/virtual-assistant/examples/Messages/UserMessage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React from 'react';
33
import Message from '@patternfly/virtual-assistant/dist/dynamic/Message';
44
import userAvatar from './user_avatar.jpg';
55

6-
export const AttachmentMenuExample: React.FunctionComponent = () => {
6+
export const UserMessageExample: React.FunctionComponent = () => {
77
const markdown = `A paragraph with *emphasis* and **strong importance**.
88
99
> A block quote with ~strikethrough~ and a URL: https://reactjs.org.

packages/module/src/Message/Message.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
gap: var(--pf-t--global--spacer--lg);
1616
padding-bottom: var(--pf-t--global--spacer--2xl);
1717

18+
// Name
19+
// --------------------------------------------------------------------------
20+
.pf-v6-c-truncate {
21+
--pf-v6-c-truncate--MinWidth: 0ch;
22+
--pf-v6-c-truncate__start--MinWidth: 0ch;
23+
}
1824
// Avatar
1925
// --------------------------------------------------------------------------
2026
.pf-v6-c-avatar {
@@ -61,6 +67,9 @@
6167
}
6268

6369
// Timestamp
70+
.pf-v6-c-timestamp {
71+
flex: 1 0 max-content;
72+
}
6473
time {
6574
font-size: var(--pf-t--global--font--size--xs);
6675
}

packages/module/src/Message/Message.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import React from 'react';
66

77
import Markdown from 'react-markdown';
88
import remarkGfm from 'remark-gfm';
9-
import { Avatar, Label, LabelGroup, LabelGroupProps, LabelProps, Timestamp } from '@patternfly/react-core';
9+
import { Avatar, Label, LabelGroup, LabelGroupProps, LabelProps, Timestamp, Truncate } from '@patternfly/react-core';
1010
import MessageLoading from './MessageLoading';
1111
import CodeBlockMessage from './CodeBlockMessage/CodeBlockMessage';
1212
import TextMessage from './TextMessage/TextMessage';
@@ -116,7 +116,11 @@ export const Message: React.FunctionComponent<MessageProps> = ({
116116
<Avatar src={avatar ?? DEFAULTS[role].avatar} alt="" />
117117
<div className="pf-chatbot__message-contents">
118118
<div className="pf-chatbot__message-meta">
119-
<span className="pf-chatbot__message-name">{name}</span>
119+
{name && (
120+
<span className="pf-chatbot__message-name">
121+
<Truncate content={name} />
122+
</span>
123+
)}
120124
{role === 'bot' && (
121125
<Label variant="outline" isCompact>
122126
{botWord}

0 commit comments

Comments
 (0)