Skip to content

Commit 101cafe

Browse files
andrewfulton9krassowskigithub-actions[bot]
authored
Add settings and menu items to toggle display of each section (#71)
* Allows all sections to enabled/disabled * lint * Add test for hinding show console section from quick settings menu * Update src/launcher.tsx Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com> * Update src/commands.ts Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com> * Update schema/plugin.json Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com> * update language to match section headers * update test * update quicksettings image * update test * Update Playwright Snapshots * Align lettercase in command labels * Update Playwright Snapshots --------- Co-authored-by: Michał Krassowski <5832902+krassowski@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 52045c8 commit 101cafe

File tree

9 files changed

+158
-35
lines changed

9 files changed

+158
-35
lines changed

schema/plugin.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,24 @@
5656
"type": "string"
5757
}
5858
},
59+
"createEmptySection": {
60+
"type": "boolean",
61+
"title": "Show \"Create Empty\" section",
62+
"default": true
63+
},
5964
"starredSection": {
6065
"type": "boolean",
61-
"title": "Show starred section"
66+
"title": "Show \"Starred\" section"
67+
},
68+
"launchNotebookSection": {
69+
"type": "boolean",
70+
"title": "Show \"Launch New Notebook\" section",
71+
"default": true
72+
},
73+
"launchConsoleSection": {
74+
"type": "boolean",
75+
"title": "Show \"Launch New Console\" section",
76+
"default": true
6277
},
6378
"searchAllSections": {
6479
"type": "boolean",

src/commands.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,58 @@ export function addCommands(
7676
await settings.set('columnOrder', order);
7777
}
7878
});
79+
app.commands.addCommand(CommandIDs.showCreateEmpty, {
80+
isToggleable: true,
81+
isToggled: () => {
82+
return settings.composite
83+
.createEmptySection as ISettingsLayout['createEmptySection'];
84+
},
85+
label: trans.__('Show "Create Empty" Section'),
86+
execute: async () => {
87+
const createEmptySection = settings.composite
88+
.createEmptySection as ISettingsLayout['createEmptySection'];
89+
await settings.set('createEmptySection', !createEmptySection);
90+
}
91+
});
7992
app.commands.addCommand(CommandIDs.showStarred, {
8093
isToggleable: true,
8194
isToggled: () => {
8295
return settings.composite
8396
.starredSection as ISettingsLayout['starredSection'];
8497
},
85-
label: trans.__('Show Starred Section'),
98+
label: trans.__('Show "Starred" Section'),
8699
execute: async () => {
87100
const starredSection = settings.composite
88101
.starredSection as ISettingsLayout['starredSection'];
89102
await settings.set('starredSection', !starredSection);
90103
}
91104
});
105+
app.commands.addCommand(CommandIDs.showNotebookLauncher, {
106+
isToggleable: true,
107+
isToggled: () => {
108+
return settings.composite
109+
.launchNotebookSection as ISettingsLayout['launchNotebookSection'];
110+
},
111+
label: trans.__('Show "Launch New Notebook" Section'),
112+
execute: async () => {
113+
const launchNotebookSection = settings.composite
114+
.launchNotebookSection as ISettingsLayout['launchNotebookSection'];
115+
await settings.set('launchNotebookSection', !launchNotebookSection);
116+
}
117+
});
118+
app.commands.addCommand(CommandIDs.showConsoleLauncher, {
119+
isToggleable: true,
120+
isToggled: () => {
121+
return settings.composite
122+
.launchConsoleSection as ISettingsLayout['launchConsoleSection'];
123+
},
124+
label: trans.__('Show "Launch New Console" Section'),
125+
execute: async () => {
126+
const launchConsoleSection = settings.composite
127+
.launchConsoleSection as ISettingsLayout['launchConsoleSection'];
128+
await settings.set('launchConsoleSection', !launchConsoleSection);
129+
}
130+
});
92131
app.commands.addCommand(CommandIDs.searchAllSections, {
93132
isToggleable: true,
94133
isToggled: () => {

src/components/quick-settings.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ export function QuickSettings(props: {
1212
const { commands } = props;
1313

1414
const menu = new MenuSvg({ commands: commands });
15+
menu.addItem({ command: CommandIDs.showCreateEmpty });
1516
menu.addItem({ command: CommandIDs.showStarred });
17+
menu.addItem({ command: CommandIDs.showNotebookLauncher });
18+
menu.addItem({ command: CommandIDs.showConsoleLauncher });
1619
menu.addItem({ command: CommandIDs.searchAllSections });
1720
menu.addItem({ command: CommandIDs.openSettings });
1821

src/launcher.tsx

Lines changed: 80 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,29 @@ function LauncherBody(props: {
4545
props;
4646
const [query, updateQuery] = React.useState<string>('');
4747
const [, forceUpdate] = React.useReducer(x => x + 1, 0);
48+
const [showCreateEmpty, updateCreateEmpty] = React.useState<
49+
ISettingsLayout['createEmptySection']
50+
>(
51+
props.settings.composite
52+
.createEmptySection as ISettingsLayout['createEmptySection']
53+
);
4854
const [showStarred, updateShowStarred] = React.useState<
4955
ISettingsLayout['starredSection']
5056
>(
5157
props.settings.composite.starredSection as ISettingsLayout['starredSection']
5258
);
59+
const [showNotebookLauncher, updateShowNotebookLauncher] = React.useState<
60+
ISettingsLayout['launchNotebookSection']
61+
>(
62+
props.settings.composite
63+
.launchNotebookSection as ISettingsLayout['launchNotebookSection']
64+
);
65+
const [showConsole, updateShowConsole] = React.useState<
66+
ISettingsLayout['launchConsoleSection']
67+
>(
68+
props.settings.composite
69+
.launchConsoleSection as ISettingsLayout['launchConsoleSection']
70+
);
5371

5472
const [searchAll, updateSearchAll] = React.useState<
5573
ISettingsLayout['searchAllSections']
@@ -59,11 +77,27 @@ function LauncherBody(props: {
5977
);
6078

6179
const syncSettings = () => {
80+
const newShowCreateEmpty = props.settings.composite
81+
.createEmptySection as ISettingsLayout['createEmptySection'];
82+
if (showCreateEmpty !== newShowCreateEmpty) {
83+
updateCreateEmpty(newShowCreateEmpty);
84+
}
6285
const newStarred = props.settings.composite
6386
.starredSection as ISettingsLayout['starredSection'];
6487
if (showStarred !== newStarred) {
6588
updateShowStarred(newStarred);
6689
}
90+
const newShowConsole = props.settings.composite
91+
.launchConsoleSection as ISettingsLayout['launchConsoleSection'];
92+
if (showConsole !== newShowConsole) {
93+
updateShowConsole(newShowConsole);
94+
}
95+
const newShowNotebook = props.settings.composite
96+
.launchNotebookSection as ISettingsLayout['launchNotebookSection'];
97+
if (showNotebookLauncher !== newShowNotebook) {
98+
updateShowNotebookLauncher(newShowNotebook);
99+
}
100+
67101
const newSearchAll = props.settings.composite
68102
.searchAllSections as ISettingsLayout['searchAllSections'];
69103
if (searchAll !== newSearchAll) {
@@ -80,9 +114,18 @@ function LauncherBody(props: {
80114

81115
if (favouritesChanged) {
82116
const updateIfNeeded = () => {
117+
if (showCreateEmpty) {
118+
forceUpdate();
119+
}
83120
if (showStarred) {
84121
forceUpdate();
85122
}
123+
if (showNotebookLauncher) {
124+
forceUpdate();
125+
}
126+
if (showConsole) {
127+
forceUpdate();
128+
}
86129
};
87130
React.useEffect(() => {
88131
favouritesChanged.connect(updateIfNeeded);
@@ -110,8 +153,9 @@ function LauncherBody(props: {
110153
const startCollapsed = props.settings.composite
111154
.collapsedSections as ISettingsLayout['collapsedSections'];
112155

113-
const builtinSections: ISectionOptions[] = [
114-
{
156+
const builtinSections: ISectionOptions[] = [];
157+
if (showCreateEmpty) {
158+
builtinSections.push({
115159
className: 'jp-Launcher-openByType',
116160
title: trans.__('Create Empty'),
117161
icon: fileIcon,
@@ -125,8 +169,36 @@ function LauncherBody(props: {
125169
item.label.toLowerCase().indexOf(query.toLowerCase()) !== -1
126170
)
127171
.map(item => <TypeCard item={item} trans={trans} />)
128-
},
129-
{
172+
});
173+
}
174+
if (showStarred) {
175+
builtinSections.push({
176+
className: 'jp-Launcher-openByKernel',
177+
title: trans.__('Starred'),
178+
icon: starIcon,
179+
id: 'starred',
180+
rank: 2,
181+
render: () =>
182+
starred.length > 0 ? (
183+
<KernelTable
184+
items={starred}
185+
commands={props.commands}
186+
showSearchBox={!searchAll}
187+
showWidgetType={true}
188+
query={query}
189+
settings={props.settings}
190+
trans={trans}
191+
onClick={item => item.execute()}
192+
favouritesChanged={props.favouritesChanged}
193+
lastUsedChanged={props.lastUsedChanged}
194+
/>
195+
) : (
196+
trans.__('No starred items')
197+
)
198+
});
199+
}
200+
if (showNotebookLauncher) {
201+
builtinSections.push({
130202
className: 'jp-Launcher-openByKernel jp-Launcher-launchNotebook',
131203
title: trans.__('Launch New Notebook'),
132204
icon: notebookIcon,
@@ -145,8 +217,10 @@ function LauncherBody(props: {
145217
lastUsedChanged={props.lastUsedChanged}
146218
/>
147219
)
148-
},
149-
{
220+
});
221+
}
222+
if (showConsole) {
223+
builtinSections.push({
150224
className: 'jp-Launcher-openByKernel jp-Launcher-launchConsole',
151225
title: trans.__('Launch New Console'),
152226
icon: consoleIcon,
@@ -165,32 +239,6 @@ function LauncherBody(props: {
165239
lastUsedChanged={props.lastUsedChanged}
166240
/>
167241
)
168-
}
169-
];
170-
if (showStarred) {
171-
builtinSections.push({
172-
className: 'jp-Launcher-openByKernel',
173-
title: trans.__('Starred'),
174-
icon: starIcon,
175-
id: 'starred',
176-
rank: 2,
177-
render: () =>
178-
starred.length > 0 ? (
179-
<KernelTable
180-
items={starred}
181-
commands={props.commands}
182-
showSearchBox={!searchAll}
183-
showWidgetType={true}
184-
query={query}
185-
settings={props.settings}
186-
trans={trans}
187-
onClick={item => item.execute()}
188-
favouritesChanged={props.favouritesChanged}
189-
lastUsedChanged={props.lastUsedChanged}
190-
/>
191-
) : (
192-
'No starred items'
193-
)
194242
});
195243
}
196244
const allSections = [...builtinSections, ...props.sections];

src/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,21 @@ export namespace CommandIDs {
2828
export const create = 'launcher:create';
2929
export const moveColumn = 'launchpad:table-move-column';
3030
export const toggleColumn = 'launchpad:table-toggle-column';
31+
export const showCreateEmpty = 'launchpad:show-create-empty';
3132
export const showStarred = 'launchpad:show-starred';
33+
export const showNotebookLauncher = 'launchpad:show-notebook-launcher';
34+
export const showConsoleLauncher = 'launchpad:show-console-launcher';
3235
export const searchAllSections = 'launchpad:search-all-sections';
3336
export const openSettings = 'launchpad:open-settings';
3437
}
3538

3639
export interface ISettingsLayout {
3740
hiddenColumns: Record<string, 'visible' | 'hidden'>;
3841
columnOrder: string[];
42+
createEmptySection: boolean;
3943
starredSection: boolean;
44+
launchNotebookSection: boolean;
45+
launchConsoleSection: boolean;
4046
collapsedSections: Record<string, 'collapsed' | 'expanded'>;
4147
searchAllSections: boolean;
4248
utilityCommands: string[];

ui-tests/tests/jupyterlab_new_launcher.spec.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,23 @@ test.describe('Quick Settings', () => {
101101
const launcher = page.locator('.jp-LauncherBody');
102102
await page.locator('.jp-Launcher-QuickSettings').click();
103103
await page
104-
.locator('.lm-Menu-itemLabel:text("Show Starred Section")')
104+
.locator('.lm-Menu-itemLabel:text(\'Show "Starred" Section\')')
105105
.click();
106106
const starredSection = page.locator(
107107
'.jp-CollapsibleSection-Title:has-text("starred")'
108108
);
109109
await expect(starredSection).toBeVisible();
110110
});
111+
112+
test('hide console from quick settings', async ({ page }) => {
113+
const launcher = page.locator('.jp-LauncherBody');
114+
await page.locator('.jp-Launcher-QuickSettings').click();
115+
await page
116+
.locator('.lm-Menu-itemLabel:text(\'Show "Launch New Console" Section\')')
117+
.click();
118+
const starredSection = page.locator(
119+
'.jp-CollapsibleSection-Title:has-text("Launch New Console")'
120+
);
121+
await expect(starredSection).toHaveCount(0);
122+
});
111123
});
4.93 KB
Loading
806 Bytes
Loading
809 Bytes
Loading

0 commit comments

Comments
 (0)