Skip to content

Commit

Permalink
display message based on error type
Browse files Browse the repository at this point in the history
  • Loading branch information
ericlln committed Jan 21, 2025
1 parent 3af5215 commit c4a7bdc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
9 changes: 7 additions & 2 deletions packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ export interface IrisGridState {
frozenColumns: readonly ColumnName[];
showOverflowModal: boolean;
showNoPastePermissionModal: boolean;
noPastePermissionError: string;
overflowText: string;
overflowButtonTooltipProps: CSSProperties | null;
expandCellTooltipProps: CSSProperties | null;
Expand Down Expand Up @@ -875,6 +876,7 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
frozenColumns,
showOverflowModal: false,
showNoPastePermissionModal: false,
noPastePermissionError: '',
overflowText: '',
overflowButtonTooltipProps: null,
expandCellTooltipProps: null,
Expand Down Expand Up @@ -3858,9 +3860,10 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
});
}

handleOpenNoPastePermissionModal(): void {
handleOpenNoPastePermissionModal(errorMessage: string): void {
this.setState({
showNoPastePermissionModal: true,
noPastePermissionError: errorMessage,
});
}

Expand Down Expand Up @@ -4291,6 +4294,7 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
columnHeaderGroups,
showOverflowModal,
showNoPastePermissionModal,
noPastePermissionError,
overflowText,
overflowButtonTooltipProps,
expandCellTooltipProps,
Expand Down Expand Up @@ -5018,7 +5022,8 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
<ContextActions actions={this.contextActions} />
<NoPastePermissionModal
isOpen={showNoPastePermissionModal}
handleClose={this.handleCloseNoPastePermissionModal}
onClose={this.handleCloseNoPastePermissionModal}
errorMessage={noPastePermissionError}
/>
</div>
);
Expand Down
16 changes: 7 additions & 9 deletions packages/iris-grid/src/NoPastePermissionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ import {

export type NoPastePermissionModalProps = {
isOpen: boolean;
handleClose: () => void;
onClose: () => void;
errorMessage: string;
};

export function NoPastePermissionModal({
isOpen,
handleClose,
onClose,
errorMessage,
}: NoPastePermissionModalProps): JSX.Element {
const pasteShortcutText = GLOBAL_SHORTCUTS.PASTE.getDisplayText();
return (
<Modal isOpen={isOpen} toggle={handleClose} centered>
<Modal isOpen={isOpen} toggle={onClose} centered>
<ModalHeader closeButton={false}>No Paste Permission</ModalHeader>
<ModalBody>
<p>
For security reasons your browser does not allow access to your
clipboard on click, or requested clipboard permissions have been
denied.
</p>
<p>{errorMessage}</p>
<p>You can still use {pasteShortcutText} to paste.</p>
</ModalBody>
<ModalFooter>
<Button kind="primary" onClick={handleClose}>
<Button kind="primary" onClick={onClose}>
Dismiss
</Button>
</ModalFooter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ import {
import Log from '@deephaven/log';
import type { DebouncedFunc } from 'lodash';
import {
ClipboardPermissionsDeniedError,
ClipboardUnavailableError,
TextUtils,
assertNotEmpty,
assertNotNaN,
Expand Down Expand Up @@ -483,12 +485,22 @@ class IrisGridContextMenuHandler extends GridMouseHandler {
group: IrisGridContextMenuHandler.GROUP_COPY,
order: 50,
action: async () => {
const text = await readFromClipboard();
if (text !== null) {
try {
const text = await readFromClipboard();
const items = text.split('\n').map(row => row.split('\t'));
await grid.pasteValue(items);
} else {
irisGrid.handleOpenNoPastePermissionModal();
} catch (err) {
if (err instanceof ClipboardUnavailableError) {
irisGrid.handleOpenNoPastePermissionModal(
'For security reasons your browser does not allow access to your clipboard on click.'
);
} else if (err instanceof ClipboardPermissionsDeniedError) {
irisGrid.handleOpenNoPastePermissionModal(
'Requested clipboard permissions have not been granted, please grant them and try again.'
);
} else {
throw err;
}
}
},
});
Expand Down

0 comments on commit c4a7bdc

Please sign in to comment.