Skip to content

Commit 7970eae

Browse files
committed
Use separate menu for the Ask/Troubleshooting mode
Made-with: Cursor
1 parent 5d2d4c9 commit 7970eae

3 files changed

Lines changed: 75 additions & 62 deletions

File tree

locales/en/plugin__lightspeed-console-plugin.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"Approve": "Approve",
99
"Are you sure you want to erase the current chat conversation and start a new chat? This action cannot be undone.": "Are you sure you want to erase the current chat conversation and start a new chat? This action cannot be undone.",
1010
"Ask": "Ask",
11+
"Ask a question...": "Ask a question...",
1112
"Attach": "Attach",
1213
"Attach cluster info": "Attach cluster info",
1314
"Bad response": "Bad response",
@@ -31,6 +32,7 @@
3132
"Copy to clipboard": "Copy to clipboard",
3233
"Currently viewing": "Currently viewing",
3334
"Denial failed:": "Denial failed:",
35+
"Describe the issue you're troubleshooting...": "Describe the issue you're troubleshooting...",
3436
"Diagnosing issues and finding solutions": "Diagnosing issues and finding solutions",
3537
"Dismiss": "Dismiss",
3638
"Do not include personal information or other sensitive information in your feedback. Feedback may be used to improve Red Hat's products or services.": "Do not include personal information or other sensitive information in your feedback. Feedback may be used to improve Red Hat's products or services.",
@@ -102,12 +104,10 @@
102104
"Red Hat OpenShift Lightspeed": "Red Hat OpenShift Lightspeed",
103105
"Refresh": "Refresh",
104106
"Reject": "Reject",
105-
"Remove Troubleshooting mode": "Remove Troubleshooting mode",
106107
"Restore": "Restore",
107108
"Revert to original": "Revert to original",
108109
"Review required": "Review required",
109110
"Save": "Save",
110-
"Send a message...": "Send a message...",
111111
"Status": "Status",
112112
"Stay": "Stay",
113113
"Structured content": "Structured content",

src/components/Prompt.tsx

Lines changed: 62 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,13 @@ import { MessageBar } from '@patternfly/chatbot';
1414
import {
1515
Alert,
1616
AlertActionCloseButton,
17-
Divider,
1817
DropdownItem,
1918
DropdownList,
2019
Label,
20+
MenuToggle,
21+
Select,
22+
SelectList,
23+
SelectOption,
2124
Spinner,
2225
Title,
2326
Tooltip,
@@ -26,7 +29,7 @@ import {
2629
FileCodeIcon,
2730
FileUploadIcon,
2831
InfoCircleIcon,
29-
OutlinedQuestionCircleIcon,
32+
OutlinedCommentIcon,
3033
PlusIcon,
3134
TaskIcon,
3235
WrenchIcon,
@@ -128,6 +131,7 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
128131
const [isLogModalOpen, , openLogModal, closeLogModal] = useBoolean(false);
129132
const [isLoading, , setLoading, setLoaded] = useBoolean(false);
130133
const [isOpen, setIsOpen] = React.useState<boolean>(false);
134+
const [isModeMenuOpen, setIsModeMenuOpen] = React.useState<boolean>(false);
131135
const [streamController, setStreamController] = React.useState(new AbortController());
132136
const [validated, setValidated] = React.useState<'default' | 'error'>('default');
133137

@@ -286,34 +290,13 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
286290
<DropdownItem icon={<FileUploadIcon />} key="upload" value={AttachmentTypes.YAMLUpload}>
287291
{t('Upload from computer')}
288292
</DropdownItem>
289-
<Divider key="divider-1" />
290-
{isTroubleshooting ? (
291-
<DropdownItem
292-
description={t('Expert guidance and clear answers')}
293-
icon={<OutlinedQuestionCircleIcon />}
294-
id="ask"
295-
value="ask"
296-
>
297-
{t('Ask')}
298-
</DropdownItem>
299-
) : (
300-
<DropdownItem
301-
description={t('Diagnosing issues and finding solutions')}
302-
icon={<WrenchIcon />}
303-
id="troubleshooting"
304-
value="troubleshooting"
305-
>
306-
{t('Troubleshooting')}
307-
</DropdownItem>
308-
)}
309293
</DropdownList>,
310294
],
311295
[
312296
events.length,
313297
isEventsLoading,
314298
isLoading,
315299
isResourceContext,
316-
isTroubleshooting,
317300
kind,
318301
name,
319302
namespace,
@@ -327,17 +310,7 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
327310
(_ev: React.MouseEvent, attachmentType: string | number) => {
328311
setIsOpen(false);
329312

330-
if (attachmentType === 'ask') {
331-
// Delay update until menu fade out is complete
332-
requestAnimationFrame(() => {
333-
setTimeout(() => dispatch(setIsTroubleshooting(false)), 0);
334-
});
335-
} else if (attachmentType === 'troubleshooting') {
336-
// Delay update until menu fade out is complete
337-
requestAnimationFrame(() => {
338-
setTimeout(() => dispatch(setIsTroubleshooting(true)), 0);
339-
});
340-
} else if (attachmentType === AttachmentTypes.Events) {
313+
if (attachmentType === AttachmentTypes.Events) {
341314
openEventsModal();
342315
} else if (attachmentType === AttachmentTypes.Log) {
343316
openLogModal();
@@ -755,23 +728,61 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
755728
[dispatch, streamController, streamingResponseID],
756729
);
757730

731+
const modeMenuToggle = React.useCallback(
732+
(toggleRef: React.Ref<HTMLButtonElement>) => (
733+
<MenuToggle
734+
data-test="ols-plugin__mode-toggle"
735+
icon={isTroubleshooting ? <WrenchIcon /> : <OutlinedCommentIcon />}
736+
isExpanded={isModeMenuOpen}
737+
onClick={() => setIsModeMenuOpen(!isModeMenuOpen)}
738+
ref={toggleRef}
739+
variant="plainText"
740+
>
741+
{isTroubleshooting ? t('Troubleshooting') : t('Ask')}
742+
</MenuToggle>
743+
),
744+
[isModeMenuOpen, isTroubleshooting, t],
745+
);
746+
747+
const onModeMenuSelect = React.useCallback(
748+
(_ev: React.MouseEvent, value: string | number) => {
749+
dispatch(setIsTroubleshooting(value === 'troubleshooting'));
750+
setIsModeMenuOpen(false);
751+
},
752+
[dispatch],
753+
);
754+
758755
return (
759756
<div>
760757
{/* @ts-expect-error: TS2786 */}
761758
<MessageBar
762759
additionalActions={
763-
isTroubleshooting ? (
764-
<Label
765-
closeBtnAriaLabel={t('Remove Troubleshooting mode')}
766-
onClose={() => dispatch(setIsTroubleshooting(false))}
767-
>
768-
{t('Troubleshooting')}
769-
</Label>
770-
) : (
771-
// TODO: Workaround for PatternFly bug that causes attach menu to move. Remove once
772-
// issue is addressed in PatternFly.
773-
<div></div>
774-
)
760+
<Select
761+
isOpen={isModeMenuOpen}
762+
onOpenChange={setIsModeMenuOpen}
763+
onSelect={onModeMenuSelect}
764+
selected={isTroubleshooting ? 'troubleshooting' : 'ask'}
765+
toggle={modeMenuToggle}
766+
>
767+
<SelectList>
768+
<SelectOption
769+
description={t('Expert guidance and clear answers')}
770+
icon={<OutlinedCommentIcon />}
771+
isSelected={!isTroubleshooting}
772+
value="ask"
773+
>
774+
{t('Ask')}
775+
</SelectOption>
776+
<SelectOption
777+
description={t('Diagnosing issues and finding solutions')}
778+
icon={<WrenchIcon />}
779+
isSelected={isTroubleshooting}
780+
value="troubleshooting"
781+
>
782+
{t('Troubleshooting')}
783+
</SelectOption>
784+
</SelectList>
785+
</Select>
775786
}
776787
alwayShowSendButton
777788
attachButtonPosition="start"
@@ -796,7 +807,11 @@ const Prompt: React.FC<PromptProps> = ({ scrollIntoView }) => {
796807
isSendButtonDisabled={!query || query.trim().length === 0}
797808
onChange={(e) => onChange(e, e.target.value)}
798809
onSendMessage={onSubmit}
799-
placeholder={t('Send a message...')}
810+
placeholder={
811+
isTroubleshooting
812+
? t("Describe the issue you're troubleshooting...")
813+
: t('Ask a question...')
814+
}
800815
validated={validated}
801816
value={query}
802817
/>

tests/tests/lightspeed-install.cy.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const modal = '.ols-plugin__modal';
3737
const promptArea = `${popover} .ols-plugin__prompt`;
3838
const attachButton = `${promptArea} .pf-chatbot__button--attach`;
3939
const promptInput = `${promptArea} textarea`;
40-
const troubleshootingLabel = `${popover} [aria-label="Remove Troubleshooting mode"]`;
40+
const modeToggle = `${popover} [data-test="ols-plugin__mode-toggle"]`;
4141

4242
const podNamePrefix = 'console';
4343

@@ -361,34 +361,32 @@ spec:
361361
cy.get(promptInput).should('contain', PROMPT_NOT_SUBMITTED);
362362
});
363363

364-
it('Test Troubleshooting mode label persists after reopening the UI', () => {
364+
it('Test Troubleshooting mode persists after reopening the UI', () => {
365365
cy.visit('/search/all-namespaces');
366366
cy.get('h1').contains('Search').should('exist');
367367
cy.get(mainButton).click();
368368
cy.get(popover).should('exist');
369369

370-
cy.get(troubleshootingLabel).should('not.exist');
371-
cy.get(attachButton).click();
372-
cy.get(attachMenu).find('button').contains('Troubleshooting').click();
373-
cy.get(troubleshootingLabel).should('exist');
374-
cy.get(popover).should('include.text', 'Troubleshooting');
370+
cy.get(modeToggle).should('include.text', 'Ask');
371+
cy.get(modeToggle).click();
372+
cy.get(popover).find('button').contains('Troubleshooting').click();
373+
cy.get(modeToggle).should('include.text', 'Troubleshooting');
375374

376375
cy.get(minimizeButton).click();
377376
cy.get(popover).should('not.exist');
378377
cy.get(mainButton).click();
379378
cy.get(popover).should('exist');
380-
cy.get(troubleshootingLabel).should('exist');
381-
cy.get(popover).should('include.text', 'Troubleshooting');
379+
cy.get(modeToggle).should('include.text', 'Troubleshooting');
382380

383-
cy.get(attachButton).click();
384-
cy.get(attachMenu).find('button').contains('Ask').click();
385-
cy.get(troubleshootingLabel).should('not.exist');
381+
cy.get(modeToggle).click();
382+
cy.get(popover).find('button').contains('Ask').click();
383+
cy.get(modeToggle).should('include.text', 'Ask');
386384

387385
cy.get(minimizeButton).click();
388386
cy.get(popover).should('not.exist');
389387
cy.get(mainButton).click();
390388
cy.get(popover).should('exist');
391-
cy.get(troubleshootingLabel).should('not.exist');
389+
cy.get(modeToggle).should('include.text', 'Ask');
392390
});
393391

394392
describe('Streamed response', { tags: ['@response'] }, () => {

0 commit comments

Comments
 (0)