Skip to content

Commit

Permalink
Backport PR #11610: overrides.json definition takes precedence (#11980)
Browse files Browse the repository at this point in the history
  • Loading branch information
fcollonval committed Feb 3, 2022
1 parent 5f72935 commit 4ebddba
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
19 changes: 13 additions & 6 deletions packages/application-extension/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -998,25 +998,32 @@ namespace Private {
*/
function populate(schema: ISettingRegistry.ISchema) {
loaded = {};
schema.properties!.contextMenu.default = Object.keys(registry.plugins)
const pluginDefaults = Object.keys(registry.plugins)
.map(plugin => {
const items =
registry.plugins[plugin]!.schema['jupyter.lab.menus']?.context ??
[];
loaded[plugin] = items;
return items;
})
.concat([
schema['jupyter.lab.menus']?.context ?? [],
schema.properties!.contextMenu.default as any[]
])
.concat([schema['jupyter.lab.menus']?.context ?? []])
.reduceRight(
(
acc: ISettingRegistry.IContextMenuItem[],
val: ISettingRegistry.IContextMenuItem[]
) => SettingRegistry.reconcileItems(acc, val, true),
[]
)! // flatten one level
)!;

// Apply default value as last step to take into account overrides.json
// The standard default being [] as the plugin must use `jupyter.lab.menus.context`
// to define their default value.
schema.properties!.contextMenu.default = SettingRegistry.reconcileItems(
pluginDefaults,
schema.properties!.contextMenu.default as any[],
true
)!
// flatten one level
.sort((a, b) => (a.rank ?? Infinity) - (b.rank ?? Infinity));
}

Expand Down
21 changes: 14 additions & 7 deletions packages/mainmenu-extension/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -916,21 +916,28 @@ namespace Private {
*/
function populate(schema: ISettingRegistry.ISchema) {
loaded = {};
schema.properties!.menus.default = Object.keys(registry.plugins)
const pluginDefaults = Object.keys(registry.plugins)
.map(plugin => {
const menus =
registry.plugins[plugin]!.schema['jupyter.lab.menus']?.main ?? [];
loaded[plugin] = menus;
return menus;
})
.concat([
schema['jupyter.lab.menus']?.main ?? [],
schema.properties!.menus.default as any[]
])
.concat([schema['jupyter.lab.menus']?.main ?? []])
.reduceRight(
(acc, val) => SettingRegistry.reconcileMenus(acc, val, true),
[]
) // flatten one level
schema.properties!.menus.default as any[]
);

// Apply default value as last step to take into account overrides.json
// The standard default being [] as the plugin must use `jupyter.lab.menus.main`
// to define their default value.
schema.properties!.menus.default = SettingRegistry.reconcileMenus(
pluginDefaults,
schema.properties!.menus.default as any[],
true
)
// flatten one level
.sort((a, b) => (a.rank ?? Infinity) - (b.rank ?? Infinity));
}

Expand Down

0 comments on commit 4ebddba

Please sign in to comment.