Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: disable top input when no access #87

Merged
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
35 changes: 35 additions & 0 deletions public/chat_header_button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,39 @@ describe('<HeaderChatButton />', () => {
});
expect(screen.getByLabelText('chat input')).toHaveFocus();
});

it('should disable chat input when no access', () => {
render(
<HeaderChatButton
application={applicationServiceMock.createStartContract()}
userHasAccess={false}
contentRenderers={{}}
actionExecutors={{}}
assistantActions={{} as AssistantActions}
currentAccount={{ username: 'test_user', tenant: 'test_tenant' }}
/>
);
expect(screen.getByLabelText('chat input')).toBeDisabled();
});

it('should not focus on chat input when no access and pressing global shortcut', () => {
render(
<HeaderChatButton
application={applicationServiceMock.createStartContract()}
userHasAccess={false}
contentRenderers={{}}
actionExecutors={{}}
assistantActions={{} as AssistantActions}
currentAccount={{ username: 'test_user', tenant: 'test_tenant' }}
/>
);
expect(screen.getByLabelText('chat input')).not.toHaveFocus();
fireEvent.keyDown(document.body, {
key: '/',
code: 'NumpadDivide',
charCode: 111,
metaKey: true,
});
expect(screen.getByLabelText('chat input')).not.toHaveFocus();
});
});
6 changes: 5 additions & 1 deletion public/chat_header_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
};

useEffect(() => {
if (!props.userHasAccess) {
return;
}
const onGlobalMouseUp = (e: KeyboardEvent) => {
if (e.metaKey && e.key === '/') {
inputRef.current?.focus();
Expand All @@ -134,7 +137,7 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
return () => {
document.removeEventListener('keydown', onGlobalMouseUp);
};
}, []);
}, [props.userHasAccess]);

return (
<>
Expand Down Expand Up @@ -179,6 +182,7 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
)}
</span>
}
disabled={!props.userHasAccess}
Copy link
Member

Choose a reason for hiding this comment

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

Have you tested if the click handler on line 161 is also disabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We only disable the chat input in this PR. Do we need to disable the dashboard assistant icon? I think the icon still can be clicked before the chat input added.

Copy link
Member

Choose a reason for hiding this comment

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

Then user can still click the icon to display the flyout, that also makes sense to me.

/>
</div>
<ChatContext.Provider value={chatContextValue}>
Expand Down
Loading