From 8c279f3008af05bcbc17afb8013758ae13d90f22 Mon Sep 17 00:00:00 2001 From: Sashank Aryal Date: Mon, 14 Oct 2024 21:36:21 +0545 Subject: [PATCH 1/3] fix shortcutToHelpItems --- app/packages/core/src/components/Modal/utils.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/packages/core/src/components/Modal/utils.ts b/app/packages/core/src/components/Modal/utils.ts index 2461570f9a..e20a1ec6a6 100644 --- a/app/packages/core/src/components/Modal/utils.ts +++ b/app/packages/core/src/components/Modal/utils.ts @@ -1,7 +1,13 @@ -export function shortcutToHelpItems(SHORTCUTS) { - const result = {}; - for (const k of SHORTCUTS) { - result[SHORTCUTS[k].shortcut] = SHORTCUTS[k]; +interface ShortcutItem { + shortcut: string; +} + +type Shortcuts = { [key: string]: ShortcutItem }; + +export function shortcutToHelpItems(SHORTCUTS: Shortcuts) { + const uniqueItems = {}; + for (const item of Object.values(SHORTCUTS)) { + uniqueItems[item.shortcut] = item; } - return Object.values(result); + return Object.values(uniqueItems); } From d112a648ae16ba3698df4dfd94bb3c654f9dc502 Mon Sep 17 00:00:00 2001 From: Sashank Aryal Date: Mon, 14 Oct 2024 22:47:09 +0545 Subject: [PATCH 2/3] add < > shortcuts in help modal --- .../looker/src/elements/common/actions.ts | 24 +++++++++++++++++++ app/packages/looker/src/lookers/image.ts | 16 ++++++++++++- app/packages/looker/src/state.ts | 1 + .../state/src/hooks/useCreateLooker.ts | 3 +++ 4 files changed, 43 insertions(+), 1 deletion(-) diff --git a/app/packages/looker/src/elements/common/actions.ts b/app/packages/looker/src/elements/common/actions.ts index 5775dda7f7..a8cdbffb84 100644 --- a/app/packages/looker/src/elements/common/actions.ts +++ b/app/packages/looker/src/elements/common/actions.ts @@ -405,6 +405,17 @@ export const nextFrame: Control = { }, }; +export const nextFrameNoOpControl: Control = { + title: "Next frame", + eventKeys: [".", ">"], + shortcut: ">", + detail: "Seek to the next frame", + alwaysHandle: true, + action: () => { + // no-op here, supposed to be implemented elsewhere + }, +}; + export const previousFrame: Control = { title: "Previous frame", eventKeys: [",", "<"], @@ -436,6 +447,17 @@ export const previousFrame: Control = { }, }; +export const previousFrameNoOpControl: Control = { + title: "Previous frame", + eventKeys: [",", "<"], + shortcut: "<", + detail: "Seek to the previous frame", + alwaysHandle: true, + action: () => { + // no-op here, supposed to be implemented elsewhere + }, +}; + export const playPause: Control = { title: "Play / pause", shortcut: "Space", @@ -662,6 +684,8 @@ const VIDEO = { const IMAVID = { ...COMMON, escape: videoEscape, + previousFrame: previousFrameNoOpControl, + nextFrame: nextFrameNoOpControl, }; export const VIDEO_SHORTCUTS = readActions(VIDEO); diff --git a/app/packages/looker/src/lookers/image.ts b/app/packages/looker/src/lookers/image.ts index 5e20d9670a..98780c519c 100644 --- a/app/packages/looker/src/lookers/image.ts +++ b/app/packages/looker/src/lookers/image.ts @@ -5,6 +5,10 @@ import { DEFAULT_IMAGE_OPTIONS, ImageState } from "../state"; import { AbstractLooker } from "./abstract"; import { LookerUtils } from "./shared"; +import { + nextFrameNoOpControl, + previousFrameNoOpControl, +} from "../elements/common/actions"; import { zoomToContent } from "../zoom"; export class ImageLooker extends AbstractLooker { @@ -21,11 +25,21 @@ export class ImageLooker extends AbstractLooker { ...options, }; + // if in dynamic groups mode, add < > shortcuts, too + let shortcuts = { ...COMMON_SHORTCUTS }; + if (config.isDynamicGroup) { + shortcuts = { + ...COMMON_SHORTCUTS, + previousFrameNoOpControl, + nextFrameNoOpControl, + }; + } + return { ...this.getInitialBaseState(), config: { ...config }, options, - SHORTCUTS: COMMON_SHORTCUTS, + SHORTCUTS: shortcuts, }; } diff --git a/app/packages/looker/src/state.ts b/app/packages/looker/src/state.ts index 84281f154a..e31eb20652 100644 --- a/app/packages/looker/src/state.ts +++ b/app/packages/looker/src/state.ts @@ -203,6 +203,7 @@ export interface BaseConfig { sampleId: string; symbol: symbol; fieldSchema: Schema; + isDynamicGroup: boolean; view: Stage[]; dataset: string; group?: { diff --git a/app/packages/state/src/hooks/useCreateLooker.ts b/app/packages/state/src/hooks/useCreateLooker.ts index 1fc1b748e3..1150346033 100644 --- a/app/packages/state/src/hooks/useCreateLooker.ts +++ b/app/packages/state/src/hooks/useCreateLooker.ts @@ -61,6 +61,8 @@ export default >( dynamicGroupAtoms.shouldRenderImaVidLooker(isModal) ); + const isDynamicGroup = useRecoilValue(dynamicGroupAtoms.isDynamicGroup); + // callback to get the latest promise inside another recoil callback // gets around the limitation of the fact that snapshot inside callback refs to the committed state at the time const getPromise = useRecoilCallback( @@ -128,6 +130,7 @@ export default >( sources: urls, frameNumber: create === FrameLooker ? frameNumber : undefined, frameRate, + isDynamicGroup, sampleId: sample._id, support: isClip ? sample.support : undefined, dataset, From b330944aee7fe804d33d63804335b519960d0ccb Mon Sep 17 00:00:00 2001 From: Benjamin Kane Date: Mon, 14 Oct 2024 14:29:07 -0400 Subject: [PATCH 3/3] add test for shortcuts --- app/packages/core/src/components/Modal/utils.test.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/packages/core/src/components/Modal/utils.test.ts diff --git a/app/packages/core/src/components/Modal/utils.test.ts b/app/packages/core/src/components/Modal/utils.test.ts new file mode 100644 index 0000000000..d764324867 --- /dev/null +++ b/app/packages/core/src/components/Modal/utils.test.ts @@ -0,0 +1,12 @@ +import { describe, expect, it } from "vitest"; +import { shortcutToHelpItems } from "./utils"; + +describe("shortcut processing test", () => { + it("parses unique shortcuts", () => { + const results = shortcutToHelpItems({ + one: { shortcut: "test" }, + two: { shortcut: "test" }, + }); + expect(results).toStrictEqual([{ shortcut: "test" }]); + }); +});