Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
font-family: var(--pf-t--global--font--family--body);
}

.pf-v6-c-code-block__actions-item {
// we are overriding some default PatternFly positioning here - it's only necessary for the first two items
.pf-chatbot__message-code-block-default-action {
display: flex;
align-items: center;
justify-content: space-between;
Expand All @@ -39,7 +40,7 @@
font-weight: var(--pf-t--global--font--weight--body--bold);
}

.pf-chatbot__button--copy.pf-v6-c-button {
.pf-v6-c-code-block__actions-item > .pf-v6-c-button.pf-m-plain {
color: var(--pf-t--color--white); // same in light + dark theme

&:hover,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export interface CodeBlockMessageProps {
expandedText?: string;
/** Link text applied to expandable toggle when collapsed */
collapsedText?: string;
/** Custom actions added to header of code block, after any default actions such as the "copy" action. */
customActions?: React.ReactNode;
}

const DEFAULT_EXPANDED_TEXT = 'Show less';
Expand All @@ -51,6 +53,7 @@ const CodeBlockMessage = ({
expandableSectionToggleProps,
expandedText = DEFAULT_EXPANDED_TEXT,
collapsedText = DEFAULT_COLLAPSED_TEXT,
customActions,
...props
}: CodeBlockMessageProps) => {
const [copied, setCopied] = useState(false);
Expand Down Expand Up @@ -114,7 +117,7 @@ const CodeBlockMessage = ({
// Setup code block header
const actions = (
<>
<CodeBlockAction>
<CodeBlockAction className="pf-chatbot__message-code-block-default-action">
{language && <div className="pf-chatbot__message-code-block-language">{language}</div>}
<Button
ref={buttonRef}
Expand All @@ -127,6 +130,7 @@ const CodeBlockMessage = ({
</Button>
<Tooltip id={tooltipID} content="Copy" position="top" triggerRef={buttonRef} />
</CodeBlockAction>
{customActions}
</>
);

Expand Down
20 changes: 19 additions & 1 deletion packages/module/src/Message/Message.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import userEvent from '@testing-library/user-event';
import { monitorSampleAppQuickStart } from './QuickStarts/monitor-sampleapp-quickstart';
import { monitorSampleAppQuickStartWithImage } from './QuickStarts/monitor-sampleapp-quickstart-with-image';
import rehypeExternalLinks from '../__mocks__/rehype-external-links';
import { AlertActionLink } from '@patternfly/react-core';
import { AlertActionLink, Button, CodeBlockAction } from '@patternfly/react-core';
import { DeepThinkingProps } from '../DeepThinking';

const ALL_ACTIONS = [
Expand Down Expand Up @@ -612,6 +612,24 @@ describe('Message', () => {
);
expect(screen.getByRole('button', { name: 'test' })).toBeTruthy();
});
it('should be able to add custom actions to CodeMessage', () => {
render(
<Message
avatar="./img"
role="user"
name="User"
content={CODE_MESSAGE}
codeBlockProps={{
customActions: (
<CodeBlockAction>
<Button>New custom action</Button>
</CodeBlockAction>
)
}}
/>
);
expect(screen.getByRole('button', { name: /New custom action/i })).toBeTruthy();
});
it('should handle hasRoundAvatar correctly when it is true', () => {
render(<Message avatar="./img" role="user" name="User" content="Hi" hasRoundAvatar />);
expect(screen.getByRole('img')).toBeTruthy();
Expand Down
23 changes: 2 additions & 21 deletions packages/module/src/Message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import {
AvatarProps,
ButtonProps,
ContentVariants,
ExpandableSectionProps,
ExpandableSectionToggleProps,
FormProps,
Label,
LabelGroupProps,
Timestamp,
Truncate
} from '@patternfly/react-core';
import MessageLoading from './MessageLoading';
import CodeBlockMessage from './CodeBlockMessage/CodeBlockMessage';
import CodeBlockMessage, { CodeBlockMessageProps } from './CodeBlockMessage/CodeBlockMessage';
import TextMessage from './TextMessage/TextMessage';
import FileDetailsLabel from '../FileDetailsLabel/FileDetailsLabel';
import ResponseActions, { ActionProps } from '../ResponseActions/ResponseActions';
Expand Down Expand Up @@ -114,24 +112,7 @@ export interface MessageProps extends Omit<HTMLProps<HTMLDivElement>, 'role'> {
/** Label for the English "Loading message," displayed to screenreaders when loading a message */
loadingWord?: string;
/** Props for code blocks */
codeBlockProps?: {
/** Aria label applied to code blocks */
'aria-label'?: string;
/** Class name applied to code blocks */
className?: string;
/** Whether code blocks are expandable */
isExpandable?: boolean;
/** Length of text initially shown in expandable code blocks; defaults to 10 characters */
maxLength?: number;
/** Additional props passed to expandable section if isExpandable is applied */
expandableSectionProps?: Omit<ExpandableSectionProps, 'ref'>;
/** Additional props passed to expandable toggle if isExpandable is applied */
expandableSectionToggleProps?: ExpandableSectionToggleProps;
/** Link text applied to expandable toggle when expanded */
expandedText?: string;
/** Link text applied to expandable toggle when collapsed */
collapsedText?: string;
};
codeBlockProps?: CodeBlockMessageProps;
/** Props for quick responses */
quickResponses?: QuickResponse[];
/** Props for quick responses container */
Expand Down
Loading