Skip to content
Merged
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
177 changes: 86 additions & 91 deletions pages/prompt-input/simple.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import AppContext, { AppContextType } from '../app/app-context';
import labels from '../app-layout/utils/labels';
import { i18nStrings } from '../file-upload/shared';
import ScreenshotArea from '../utils/screenshot-area';

const MAX_CHARS = 2000;

Expand All @@ -28,7 +29,6 @@ type DemoContext = React.Context<
isReadOnly: boolean;
isInvalid: boolean;
hasWarning: boolean;
hasText: boolean;
hasSecondaryContent: boolean;
hasSecondaryActions: boolean;
hasPrimaryActions: boolean;
Expand All @@ -50,7 +50,6 @@ export default function PromptInputPage() {
isReadOnly,
isInvalid,
hasWarning,
hasText,
hasSecondaryActions,
hasSecondaryContent,
hasPrimaryActions,
Expand All @@ -63,19 +62,6 @@ export default function PromptInputPage() {
{ label: 'Item 3', dismissLabel: 'Remove item 3', disabled: isDisabled },
]);

useEffect(() => {
if (hasText) {
setTextareaValue(placeholderText);
}
}, [hasText]);

useEffect(() => {
if (textareaValue !== placeholderText) {
setUrlParams({ hasText: false });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Comment on lines -73 to -76
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The setUrlParams in this file were messing up with the screenshot testing as it's changing the url path on first render.

}, [textareaValue]);

useEffect(() => {
if (items.length === 0) {
ref.current?.focus();
Expand Down Expand Up @@ -164,7 +150,14 @@ export default function PromptInputPage() {
Infinite max rows
</Checkbox>
</FormField>
<button id="placeholder-text-button" onClick={() => setUrlParams({ hasText: true })}>
<button
id="placeholder-text-button"
onClick={() => {
if (textareaValue === '') {
setTextareaValue(placeholderText);
}
}}
>
Fill with placeholder text
</button>

Expand All @@ -187,93 +180,95 @@ export default function PromptInputPage() {
label={<span>User prompt</span>}
i18nStrings={{ errorIconAriaLabel: 'Error' }}
>
<PromptInput
data-testid="prompt-input"
ariaLabel="Chat input"
actionButtonIconName="send"
actionButtonAriaLabel="Submit prompt"
value={textareaValue}
onChange={(event: any) => setTextareaValue(event.detail.value)}
onAction={event => window.alert(`Submitted the following: ${event.detail.value}`)}
placeholder="Ask a question"
maxRows={hasInfiniteMaxRows ? -1 : 4}
disabled={isDisabled}
readOnly={isReadOnly}
invalid={isInvalid || textareaValue.length > MAX_CHARS}
warning={hasWarning}
ref={ref}
disableSecondaryActionsPaddings={true}
customPrimaryAction={
hasPrimaryActions ? (
<ButtonGroup
variant="icon"
items={[
{
type: 'icon-button',
id: 'record',
text: 'Record',
iconName: 'microphone',
disabled: isDisabled || isReadOnly,
},
{
type: 'icon-button',
id: 'submit',
text: 'Submit',
iconName: 'send',
disabled: isDisabled || isReadOnly,
},
]}
/>
) : undefined
}
secondaryActions={
hasSecondaryActions ? (
<Box padding={{ left: 'xxs', top: 'xs' }}>
<ScreenshotArea disableAnimations={true}>
<PromptInput
data-testid="prompt-input"
ariaLabel="Chat input"
actionButtonIconName="send"
actionButtonAriaLabel="Submit prompt"
value={textareaValue}
onChange={(event: any) => setTextareaValue(event.detail.value)}
onAction={event => window.alert(`Submitted the following: ${event.detail.value}`)}
placeholder="Ask a question"
maxRows={hasInfiniteMaxRows ? -1 : 4}
disabled={isDisabled}
readOnly={isReadOnly}
invalid={isInvalid || textareaValue.length > MAX_CHARS}
warning={hasWarning}
ref={ref}
disableSecondaryActionsPaddings={true}
customPrimaryAction={
hasPrimaryActions ? (
<ButtonGroup
ref={buttonGroupRef}
ariaLabel="Chat actions"
onFilesChange={({ detail }) => detail.id.includes('files') && setFiles(detail.files)}
variant="icon"
items={[
{
type: 'icon-file-input',
id: 'files',
text: 'Upload files',
multiple: true,
},
{
type: 'icon-button',
id: 'expand',
iconName: 'expand',
text: 'Go full page',
id: 'record',
text: 'Record',
iconName: 'microphone',
disabled: isDisabled || isReadOnly,
},
{
type: 'icon-button',
id: 'remove',
iconName: 'remove',
text: 'Remove',
id: 'submit',
text: 'Submit',
iconName: 'send',
disabled: isDisabled || isReadOnly,
},
]}
variant="icon"
/>
</Box>
) : undefined
}
secondaryContent={
hasSecondaryContent && files.length > 0 ? (
<FileTokenGroup
items={files.map(file => ({
file,
}))}
showFileThumbnail={true}
onDismiss={onDismiss}
i18nStrings={i18nStrings}
alignment="horizontal"
/>
) : undefined
}
/>
) : undefined
}
secondaryActions={
hasSecondaryActions ? (
<Box padding={{ left: 'xxs', top: 'xs' }}>
<ButtonGroup
ref={buttonGroupRef}
ariaLabel="Chat actions"
onFilesChange={({ detail }) => detail.id.includes('files') && setFiles(detail.files)}
items={[
{
type: 'icon-file-input',
id: 'files',
text: 'Upload files',
multiple: true,
},
{
type: 'icon-button',
id: 'expand',
iconName: 'expand',
text: 'Go full page',
disabled: isDisabled || isReadOnly,
},
{
type: 'icon-button',
id: 'remove',
iconName: 'remove',
text: 'Remove',
disabled: isDisabled || isReadOnly,
},
]}
variant="icon"
/>
</Box>
) : undefined
}
secondaryContent={
hasSecondaryContent && files.length > 0 ? (
<FileTokenGroup
items={files.map(file => ({
file,
}))}
showFileThumbnail={true}
onDismiss={onDismiss}
i18nStrings={i18nStrings}
alignment="horizontal"
/>
) : undefined
}
/>
</ScreenshotArea>
</FormField>
<div />
</ColumnLayout>
Expand Down
Loading