Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a setting to show search box by kernel tables #13

Merged
merged 3 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -34,3 +34,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.
Loading