Skip to content

Conversation

@lyjeileen
Copy link
Collaborator

@lyjeileen lyjeileen commented May 2, 2024

Changes

  • Add copy and action component

(I added a note in the MessageSpace's story and asked people to refer to MessageCanvas for the usage of getActionsComponent and getProfileComponent. It's showing ()={} right now in the MessageSpace's stories. I thought about overwriting the original code, but the message array is quite long and we will have a lot of duplicate code.

Screenshots

Screenshot 2024-05-02 at 1 16 11 PM

Video

May-06-2024 10-59-00

{props.getActionsComponent(props.message)}
</Card>
)}
{props.getActionsComponent && props.getActionsComponent(props.message)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be changed. The component is expected to be several supported actions. Styling should be set here for the container.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to have the border in the messageCanvas, we need to hide it when no button is returned by props.getActionsComponent. Is it ok that I change the type of getActionsComponent from (message: ThreadableMessage) => ReactNode to (message: ThreadableMessage) => ReactNode | undefined?

Comment on lines 17 to 19
if (message.data.text) {
navigator.clipboard.writeText(message.data.text)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should indicate the text was copied using tooltip or something similar

.then(() => {
setTooltipContent('Copied')
setTimeout(() => {
setTooltipContent('Copy')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setTooltipContent('Copy')
setTooltipContent('Copy Text')

@lyjeileen lyjeileen requested review from Shiti and kaseyvee May 6, 2024 18:04
description: {
component:
'The `Message Canvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.',
'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. The examples of actions are listed below:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.',
Copy link
Collaborator

@kaseyvee kaseyvee May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"The examples of actions are listed below:" > "Listed below are actions you can import from the library to use in your application:"

Or something similar or mentioned somewhere that let's people know we've exposed this action.

Suggested change
'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. The examples of actions are listed below:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.',
'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. Listed below are actions you can import from the library to use in your application:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.',

message: ThreadableMessage
}

export default function Copy(props: CopyProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this to CopyText instead?

Suggested change
export default function Copy(props: CopyProps) {
export default function CopyText(props: CopyProps) {

Comment on lines 19 to 20
/** A function that returns a single React element which contains message actions. For example, this could be a list of buttons for different actions (e.g. copy, delete, save, etc.). The function may also return no element if no actions are applicable or available for a particular message. */
getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/** A function that returns a single React element which contains message actions. For example, this could be a list of buttons for different actions (e.g. copy, delete, save, etc.). The function may also return no element if no actions are applicable or available for a particular message. */
getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined
/** A function that returns a single React element which may be composed of several actions supported for the message, such as editing, copying, and deleting, etc.
* In case no actions are applicable or available for a particular message, the function may return `undefined`.
* This approach offers flexibility in tailoring message interactions to specific application requirements.
* To define individual message actions, developers can extend the `Action` component's functionality.
* One such example is the CopyText component.
*/
getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined

getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined
}

export default function MessageCanvas(props: MessageCanvasProps) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export default function MessageCanvas(props: MessageCanvasProps) {
/**
The `MessageCanvas` component serves as a container for displaying messages within a chat interface.
It provides a structured layout for rendering message content along with sender information and timestamp details.
This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.
*/
export default function MessageCanvas(props: MessageCanvasProps) {

tags: ['autodocs'],
parameters: {
layout: 'centered',
docs: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should not use this and instead write JsDoc Comments for the component as recommended on Storybook docs

We recommend using JSDoc comments for descriptions, and only use the parameters.docs.description.X properties in situations where comments are not possible to write for some reason, or where you want the description shown in Storybook to be different from the comments. Comments provide a better writing experience as you don’t have to worry about indentation, and they are more discoverable for other developers that are exploring the story/component sources.

https://storybook.js.org/docs/api/doc-block-description#writing-descriptions

},
}

const baseMessage = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I notice a lot of duplicate code in the stories here, is it possible to clean it up using the constants/variables defined here.

import Copy from '../messageCanvas/actions/copy/copy'
import MessageSpace from './messageSpace'

export default {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding description here for each field is not required if we use JsDoc Comments. We can also avoid duplicate things if we define an interface for the shared props between MessageSpace and MessageCanvas, for example,

export interface MessageContainerProps {
  /** Profile icon to be shown before sender's name. */
  getProfileComponent?: (message: ThreadableMessage) => ReactNode
  /** A function that returns a single React element which may be composed of several actions supported for the message, such as editing, copying, and deleting, etc.
   * In case no actions are applicable or available for a particular message, the function may return `undefined`.
   * This approach offers flexibility in tailoring message interactions to specific application requirements.
   * To define individual message actions, developers can extend the `Action` component's functionality.
   * One such example is the CopyText component.
   */
  getActionsComponent?: (message: ThreadableMessage) => ReactNode | undefined
}

export interface MessageCanvasProps extends MessageContainerProps {
  /** Message information to be displayed. Please see the `MessageSpace` docs for more information about the `ThreadableMessage` interface. */
  message: ThreadableMessage
  /** React component to be displayed in the message canvas. */
  children: ReactNode
}

Copy link
Collaborator Author

@lyjeileen lyjeileen May 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will extend MessageContainerProps, but we still need to provide details about ThreadableMessage for messages field

@lyjeileen lyjeileen requested a review from Shiti May 6, 2024 22:29
@Shiti Shiti merged commit c218731 into rustic-ai:main May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants