Skip to content

Commit ca0a5d6

Browse files
authored
Merge pull request #6387 from voxel51/josh/explore-modal-close-selection-clear
Stop propagation of the Escape event when looker is a Modal [FOEPD-862]
2 parents 8f83069 + 633d88b commit ca0a5d6

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

app/packages/core/src/components/Grid/useEscape.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,17 @@ const useEscape = () => {
1818
}
1919

2020
const modal = await snapshot.getPromise(fos.modalSelector);
21-
modal === null && reset(fos.selectedSamples);
21+
const selectedSampleIds = await snapshot.getPromise(
22+
fos.selectedSamples
23+
);
24+
// TODO: modal is always `null` here right after a modal closes, so this isn't the condition we want
25+
if (modal === null && selectedSampleIds.size > 0) {
26+
if (
27+
confirm("Are you sure you want to clear your current selection?")
28+
) {
29+
reset(fos.selectedSamples);
30+
}
31+
}
2232
},
2333
[]
2434
)

app/packages/looker/src/elements/common/looker.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,18 @@ export class LookerElement<State extends BaseState> extends BaseElement<
3030
SHORTCUTS,
3131
error,
3232
options: { shouldHandleKeyEvents },
33+
config: { isModal },
3334
} = state;
3435
if (!error && e.key in SHORTCUTS) {
3536
const matchedControl = SHORTCUTS[e.key] as Control;
3637
const enabled =
3738
shouldHandleKeyEvents || matchedControl.alwaysHandle;
3839
if (enabled) {
3940
matchedControl.action(update, dispatchEvent, e.key, e.shiftKey);
41+
42+
if (e.key === "Escape" && isModal) {
43+
e.stopPropagation();
44+
}
4045
}
4146
}
4247

app/packages/looker/src/state.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export interface BaseConfig {
223223
id: string;
224224
name: string;
225225
};
226+
isModal?: boolean;
226227
}
227228

228229
export interface FrameConfig extends BaseConfig {

app/packages/state/src/hooks/useCreateLooker.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export default <T extends AbstractLooker<BaseState>>(
159159
thumbnail,
160160
view,
161161
shouldHandleKeyEvents: isModal,
162+
isModal,
162163
};
163164

164165
let sampleMediaFilePath = urls[mediaField];

e2e-pw/src/oss/specs/selection.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ test.describe.serial("selection", () => {
7171
// verify selection clears on escape
7272
await grid.toggleSelectFirstSample();
7373
await grid.assert.isSelectionCountEqualTo(1);
74+
page.once("dialog", (dialog) => dialog.accept());
7475
await page.press("body", "Escape");
7576
await grid.assert.isSelectionCountEqualTo(0);
7677

0 commit comments

Comments
 (0)