Skip to content

Commit

Permalink
Allow to omit the root attribute in settings (#26)
Browse files Browse the repository at this point in the history
* Allow to omit the `root` attribute in settings,

and populate it when loading settings from current root

* Fix integration test
  • Loading branch information
krassowski authored Mar 21, 2024
1 parent 74e63f2 commit 6ce4b99
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
5 changes: 3 additions & 2 deletions schema/favorites.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
"type": "string"
},
"root": {
"type": "string"
"type": "string",
"description": "Root path used for filtering out favourites from instances of JupyterLab launched in a different root directory. If not given the favourite will be shown if the associated file exists."
}
},
"required": ["root", "path"],
"required": ["path"],
"type": "object"
}
},
Expand Down
12 changes: 9 additions & 3 deletions src/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ISettingRegistry } from '@jupyterlab/settingregistry';
import { CommandRegistry } from '@lumino/commands';
import { Contents } from '@jupyterlab/services';
import { IFavorites, SettingIDs, CommandIDs } from './token';
import { getName } from './utils';
import { getName, Optional } from './utils';

export class FavoritesManager {
favoritesMenu: Menu;
Expand Down Expand Up @@ -188,11 +188,17 @@ export class FavoritesManager {
}

private async loadFavorites() {
const favorites = await this._settingsRegistry.get(
const setting = await this._settingsRegistry.get(
SettingIDs.favorites,
'favorites'
);
this.favorites = (favorites.composite ?? []) as IFavorites.Favorite[];
const favorites = (setting.composite ?? []) as Optional<
IFavorites.Favorite,
'root'
>[];
this.favorites = favorites.map(favorite => {
return { ...favorite, root: favorite.root ?? this.serverRoot };
});
}

private async loadShowWidget() {
Expand Down
2 changes: 2 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ export function getPinnerActionDescription(showRemove: boolean): string {
export function mergePaths(root: string, path: string): string {
return PathExt.join(root, path);
}

export type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
2 changes: 1 addition & 1 deletion ui-tests/tests/jupyterlab_favorites.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test.beforeEach(async ({ page }) => {
.getByRole('tab', { name: 'untitled.txt' })
.waitFor();
await page.activity.closeAll();
await page.getByRole('button', { name: 'New Folder' }).click();
await page.getByTitle('New Folder').click();
await page.locator('.jp-DirListing-editor').press('Escape');
});

Expand Down

0 comments on commit 6ce4b99

Please sign in to comment.