diff --git a/schema/plugin.json b/schema/plugin.json index 090c6d8..24d0379 100644 --- a/schema/plugin.json +++ b/schema/plugin.json @@ -29,6 +29,11 @@ "type": "boolean", "title": "Show starred section" }, + "searchAllSections": { + "type": "boolean", + "title": "Search in all sections", + "default": true + }, "collapsedSections": { "title": "Collapsed sections", "description": "Whether to start launcher with given section collapsed.", diff --git a/src/components/table.tsx b/src/components/table.tsx index e4566a4..614f529 100644 --- a/src/components/table.tsx +++ b/src/components/table.tsx @@ -55,8 +55,9 @@ export function KernelTable(props: { const { trans } = props; let query: string; let updateQuery: (value: string) => void; + // Note: state cannot be defined in conditionals, or React will error out when toggling it. + const [_query, _updateQuery] = React.useState(''); if (props.showSearchBox) { - const [_query, _updateQuery] = React.useState(''); query = _query; updateQuery = _updateQuery; } else { @@ -285,7 +286,7 @@ export function KernelTable(props: { {props.showSearchBox ? (
{ updateQuery(query ?? ''); }} diff --git a/src/launcher.tsx b/src/launcher.tsx index 071998f..c3870ea 100644 --- a/src/launcher.tsx +++ b/src/launcher.tsx @@ -44,11 +44,24 @@ function LauncherBody(props: { props.settings.composite.starredSection as ISettingsLayout['starredSection'] ); + const [searchAll, updateSearchAll] = React.useState< + ISettingsLayout['searchAllSections'] + >( + props.settings.composite + .searchAllSections as ISettingsLayout['searchAllSections'] + ); + const syncSettings = () => { - updateShowStarred( - props.settings.composite - .starredSection as ISettingsLayout['starredSection'] - ); + const newStarred = props.settings.composite + .starredSection as ISettingsLayout['starredSection']; + if (showStarred !== newStarred) { + updateShowStarred(newStarred); + } + const newSearchAll = props.settings.composite + .searchAllSections as ISettingsLayout['searchAllSections']; + if (searchAll !== newSearchAll) { + updateSearchAll(newSearchAll); + } }; React.useEffect(() => { @@ -104,16 +117,18 @@ function LauncherBody(props: { ))}
-
- { - updateQuery(query ?? ''); - }} - initialQuery={''} - useFuzzyFilter={false} - /> -
+ {searchAll ? ( +
+ { + updateQuery(query ?? ''); + }} + initialQuery={''} + useFuzzyFilter={false} + /> +
+ ) : null} ; + searchAllSections: boolean; } export interface IItem extends ILauncher.IItemOptions { diff --git a/ui-tests/tests/jupyterlab_new_launcher.spec.ts b/ui-tests/tests/jupyterlab_new_launcher.spec.ts index cf357fe..904b590 100644 --- a/ui-tests/tests/jupyterlab_new_launcher.spec.ts +++ b/ui-tests/tests/jupyterlab_new_launcher.spec.ts @@ -38,3 +38,22 @@ test.describe('With starred section', () => { ); }); }); + +test.describe('Filter individual', () => { + test.use({ + mockSettings: { + ...galata.DEFAULT_SETTINGS, + [SETTINGS_ID]: { + ...galata.DEFAULT_SETTINGS[SETTINGS_ID], + searchAllSections: false + } + } + }); + + test('search in individual sections', async ({ page }) => { + const launcher = page.locator('.jp-LauncherBody'); + expect(await launcher.screenshot()).toMatchSnapshot( + 'launcher-search-in-individual.png' + ); + }); +}); diff --git a/ui-tests/tests/jupyterlab_new_launcher.spec.ts-snapshots/launcher-search-in-individual-linux.png b/ui-tests/tests/jupyterlab_new_launcher.spec.ts-snapshots/launcher-search-in-individual-linux.png new file mode 100644 index 0000000..74ba5db Binary files /dev/null and b/ui-tests/tests/jupyterlab_new_launcher.spec.ts-snapshots/launcher-search-in-individual-linux.png differ