Skip to content

Commit

Permalink
Add a setting to show search box by kernel tables (#13)
Browse files Browse the repository at this point in the history
* Show search box by the tables

* Add a test

* Add snapshot
  • Loading branch information
krassowski authored May 7, 2024
1 parent 2e41fef commit 10c0148
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 19 deletions.
5 changes: 5 additions & 0 deletions schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
5 changes: 3 additions & 2 deletions src/components/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>('');
if (props.showSearchBox) {
const [_query, _updateQuery] = React.useState<string>('');
query = _query;
updateQuery = _updateQuery;
} else {
Expand Down Expand Up @@ -285,7 +286,7 @@ export function KernelTable(props: {
{props.showSearchBox ? (
<div className="jp-Launcher-searchBox">
<FilterBox
placeholder={trans.__('Filter')}
placeholder={trans.__('Filter kernels')}
updateFilter={(_, query) => {
updateQuery(query ?? '');
}}
Expand Down
49 changes: 32 additions & 17 deletions src/launcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -104,16 +117,18 @@ function LauncherBody(props: {
))}
</div>
</div>
<div className="jp-Launcher-searchBox">
<FilterBox
placeholder={trans.__('Filter')}
updateFilter={(_, query) => {
updateQuery(query ?? '');
}}
initialQuery={''}
useFuzzyFilter={false}
/>
</div>
{searchAll ? (
<div className="jp-Launcher-searchBox">
<FilterBox
placeholder={trans.__('Filter')}
updateFilter={(_, query) => {
updateQuery(query ?? '');
}}
initialQuery={''}
useFuzzyFilter={false}
/>
</div>
) : null}
<CollapsibleSection
className="jp-Launcher-openByType"
title={trans.__('Create Empty')}
Expand Down Expand Up @@ -141,7 +156,7 @@ function LauncherBody(props: {
<KernelTable
items={starred}
commands={props.commands}
showSearchBox={false}
showSearchBox={!searchAll}
showWidgetType={true}
query={query}
settings={props.settings}
Expand All @@ -162,7 +177,7 @@ function LauncherBody(props: {
<KernelTable
items={props.notebookItems}
commands={props.commands}
showSearchBox={false}
showSearchBox={!searchAll}
query={query}
settings={props.settings}
trans={trans}
Expand All @@ -178,7 +193,7 @@ function LauncherBody(props: {
<KernelTable
items={props.consoleItems}
commands={props.commands}
showSearchBox={false}
showSearchBox={!searchAll}
query={query}
settings={props.settings}
trans={trans}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface ISettingsLayout {
columnOrder: string[];
starredSection: boolean;
collapsedSections: Record<string, 'collapsed' | 'expanded'>;
searchAllSections: boolean;
}

export interface IItem extends ILauncher.IItemOptions {
Expand Down
19 changes: 19 additions & 0 deletions ui-tests/tests/jupyterlab_new_launcher.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 10c0148

Please sign in to comment.