Skip to content

🎥 Make videos programmatically with React

Fix quick switcher action labels and result keys

Jonny Burgere0e8de64eed3
diff --git a/packages/studio/src/components/composition-menu-items.ts b/packages/studio/src/components/composition-menu-items.ts
index d4aba9cb9f..d1bf7a3276 100644
--- a/packages/studio/src/components/composition-menu-items.ts
+++ b/packages/studio/src/components/composition-menu-items.ts
@@ -239,7 +239,7 @@ export const getCompositionMenuItems = ({
openGitSource({folder: false, location: resolvedLocation});
}
},
- quickSwitcherLabel: `Open composition in ${defaultOpenInName}`,
+ quickSwitcherLabel: `Composition: Open in ${defaultOpenInName}`,
subMenu: null,
type: 'item' as const,
value:
@@ -259,7 +259,7 @@ export const getCompositionMenuItems = ({
label: 'Open composition in...',
leftItem: null,
onClick: () => undefined,
- quickSwitcherLabel: null,
+ quickSwitcherLabel: 'Composition',
subMenu: {
items: compositionOpenInMenuItems,
leaveLeftSpace: true,
@@ -285,7 +285,7 @@ export const getCompositionMenuItems = ({
openComponentInGitSource().catch(() => undefined);
}
},
- quickSwitcherLabel: `Open composition component in ${defaultOpenInName}`,
+ quickSwitcherLabel: `Component: Open in ${defaultOpenInName}`,
subMenu: null,
type: 'item' as const,
value:
@@ -305,7 +305,7 @@ export const getCompositionMenuItems = ({
label: 'Open component in...',
leftItem: null,
onClick: () => undefined,
- quickSwitcherLabel: null,
+ quickSwitcherLabel: 'Component',
subMenu: {
items: componentOpenInMenuItems,
leaveLeftSpace: true,
diff --git a/packages/studio/src/components/get-open-in-menu-items.tsx b/packages/studio/src/components/get-open-in-menu-items.tsx
index 777ae59ad2..c57f4c2343 100644
--- a/packages/studio/src/components/get-open-in-menu-items.tsx
+++ b/packages/studio/src/components/get-open-in-menu-items.tsx
@@ -45,7 +45,7 @@ export const getConfigureDefaultAppsMenuItems = ({
label: <span style={menuLabel}>Configure default apps...</span>,
leftItem: null,
onClick: onConfigureApps,
- quickSwitcherLabel: null,
+ quickSwitcherLabel: 'Configure default apps...',
subMenu: null,
type: 'item' as const,
value: 'change-default-apps',
@@ -113,7 +113,7 @@ export const getOpenInMenuItems = ({
onOpenInEditor(editor.id);
}
},
- quickSwitcherLabel: null,
+ quickSwitcherLabel: `Open in ${editor.name}`,
subMenu: null,
type: 'item' as const,
value: editor.id,
@@ -129,7 +129,7 @@ export const getOpenInMenuItems = ({
leftItem: <CodingAgentIcon codingAgentId={codingAgent.id} size={18} />,
onClick: () =>
onOpenInCodingAgent(codingAgent.id, codingAgent.nameWithType),
- quickSwitcherLabel: null,
+ quickSwitcherLabel: `Open in ${codingAgent.nameWithType}`,
subMenu: null,
type: 'item' as const,
value: `coding-agent-${codingAgent.id}`,
@@ -155,7 +155,7 @@ export const getOpenInMenuItems = ({
onOpenInGitSource();
}
},
- quickSwitcherLabel: null,
+ quickSwitcherLabel: 'Open in GitHub.com',
subMenu: null,
type: 'item' as const,
value: 'github',
@@ -175,7 +175,7 @@ export const getOpenInMenuItems = ({
onOpenInFileExplorer();
}
},
- quickSwitcherLabel: null,
+ quickSwitcherLabel: `Open in ${fileManagerName}`,
subMenu: null,
type: 'item' as const,
value: 'file-explorer',
@@ -222,7 +222,7 @@ export const getOpenInMenuItems = ({
label: <span style={menuLabel}>{terminal.name}</span>,
leftItem: <TerminalIcon terminalId={terminal.id} size={18} />,
onClick: () => onOpenInTerminal?.(terminal.id),
- quickSwitcherLabel: null,
+ quickSwitcherLabel: `Open in ${terminal.name}`,
subMenu: null,
type: 'item' as const,
value: `terminal-${terminal.id}`,
@@ -242,7 +242,7 @@ export const getOpenInMenuItems = ({
label: <span style={menuLabel}>{gitClient.name}</span>,
leftItem: <GitClientIcon gitClientId={gitClient.id} size={18} />,
onClick: () => onOpenInGitClient(gitClient.id),
- quickSwitcherLabel: null,
+ quickSwitcherLabel: `Open in ${gitClient.name}`,
subMenu: null,
type: 'item' as const,
value: `git-client-${gitClient.id}`,
diff --git a/packages/studio/src/helpers/use-menu-structure.tsx b/packages/studio/src/helpers/use-menu-structure.tsx
index ebe445cdd6..32ee7ef3ea 100644
--- a/packages/studio/src/helpers/use-menu-structure.tsx
+++ b/packages/studio/src/helpers/use-menu-structure.tsx
@@ -1230,6 +1230,7 @@ const itemToSearchResult = (
item: SelectionItem,
setSelectedModal: (value: React.SetStateAction<ModalState | null>) => void,
prefixes: string[],
+ path: string[],
): TQuickSwitcherResult[] => {
if (item.disabled) {
return [];
@@ -1242,24 +1243,37 @@ const itemToSearchResult = (
return null;
}
- return itemToSearchResult(subItem, setSelectedModal, [
- ...prefixes,
- getItemLabel(item),
- ]);
+ return itemToSearchResult(
+ subItem,
+ setSelectedModal,
+ [...prefixes, getItemLabel(item)],
+ [...path, subItem.id],
+ );
})
.flat(1)
.filter(NoReactInternals.truthy);
}
+ const label = getItemLabel(item);
+ const distinctPrefixes = prefixes.filter(
+ (prefix, index) => prefix !== prefixes[index + 1],
+ );
+ if (
+ distinctPrefixes.length > 0 &&
+ label.startsWith(`${distinctPrefixes.at(-1)}: `)
+ ) {
+ distinctPrefixes.pop();
+ }
+
return [
{
type: 'menu-item',
- id: item.id,
+ id: path.join(':'),
onSelected: () => {
setSelectedModal(null);
item.onClick(item.id, null);
},
- title: [...prefixes, getItemLabel(item)].join(': '),
+ title: [...distinctPrefixes, label].join(': '),
},
];
};
@@ -1275,7 +1289,12 @@ export const makeSearchResults = (
return null;
}
- return itemToSearchResult(item, setSelectedModal, []);
+ return itemToSearchResult(
+ item,
+ setSelectedModal,
+ [],
+ [menu.id, item.id],
+ );
});
})
.flat(Infinity)
diff --git a/packages/studio/src/test/composition-menu-items.test.ts b/packages/studio/src/test/composition-menu-items.test.ts
index 66357c7f03..651f72910e 100644
--- a/packages/studio/src/test/composition-menu-items.test.ts
+++ b/packages/studio/src/test/composition-menu-items.test.ts
@@ -5,6 +5,7 @@ import {
getCompositionContextMenuItems,
getCompositionMenuItems,
} from '../components/composition-menu-items';
+import {makeSearchResults} from '../helpers/use-menu-structure';
const originalWindowDescriptor = Object.getOwnPropertyDescriptor(
globalThis,
@@ -379,4 +380,53 @@ test('interactive composition context menus list GitHub as an alternative', () =
'change-default-apps',
]),
);
+
+ const searchResults = makeSearchResults(
+ [
+ {
+ id: 'composition',
+ label: 'Composition',
+ leaveLeftPadding: false,
+ items,
+ },
+ ],
+ () => undefined,
+ );
+ expect(searchResults.map((result) => result.title)).toContain(
+ 'Composition: Open in Cursor',
+ );
+ expect(searchResults.map((result) => result.title)).toContain(
+ 'Component: Open in Cursor',
+ );
+
+ const mobileSearchResults = makeSearchResults(
+ [
+ {
+ id: 'remotion',
+ label: 'Remotion',
+ leaveLeftPadding: false,
+ items: [
+ {
+ id: 'composition',
+ value: 'composition',
+ label: 'Composition',
+ quickSwitcherLabel: null,
+ type: 'item',
+ onClick: () => undefined,
+ keyHint: null,
+ leftItem: null,
+ subMenu: {
+ items,
+ leaveLeftSpace: true,
+ preselectIndex: 0,
+ },
+ },
+ ],
+ },
+ ],
+ () => undefined,
+ );
+ expect(mobileSearchResults.map((result) => result.title)).toContain(
+ 'Composition: Open in Cursor',
+ );
});
diff --git a/packages/studio/src/test/quick-switcher-menu-results.test.ts b/packages/studio/src/test/quick-switcher-menu-results.test.ts
new file mode 100644
index 0000000000..eb93ab8b0e
--- /dev/null
+++ b/packages/studio/src/test/quick-switcher-menu-results.test.ts
@@ -0,0 +1,47 @@
+import {expect, test} from 'bun:test';
+import type {Menu} from '../components/Menu/MenuItem';
+import type {ComboboxValue} from '../components/NewComposition/ComboBox';
+import {makeSearchResults} from '../helpers/use-menu-structure';
+
+test('nested actions with the same item ID have unique search result keys', () => {
+ const openInEditor: ComboboxValue = {
+ id: 'open-in-editor',
+ value: 'open-in-editor',
+ label: 'Editor',
+ quickSwitcherLabel: 'Editor',
+ type: 'item',
+ onClick: () => undefined,
+ keyHint: null,
+ leftItem: null,
+ subMenu: null,
+ };
+ const menu: Menu = {
+ id: 'composition',
+ label: 'Composition',
+ leaveLeftPadding: false,
+ items: ['Open composition in...', 'Open component in...'].map(
+ (label, index): ComboboxValue => ({
+ id: index === 0 ? 'open-composition-in' : 'open-component-in',
+ value: index === 0 ? 'open-composition-in' : 'open-component-in',
+ label,
+ quickSwitcherLabel: null,
+ type: 'item',
+ onClick: () => undefined,
+ keyHint: null,
+ leftItem: null,
+ subMenu: {
+ items: [openInEditor],
+ leaveLeftSpace: true,
+ preselectIndex: false,
+ },
+ }),
+ ),
+ };
+
+ const results = makeSearchResults([menu], () => undefined);
+ expect(results.map((result) => result.title)).toEqual([
+ 'Open composition in...: Editor',
+ 'Open component in...: Editor',
+ ]);
+ expect(new Set(results.map((result) => result.id)).size).toBe(results.length);
+});