Skip to content

Commit

Permalink
feat: add Admin.generalIndexItems extender
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Oct 12, 2024
1 parent 77f3685 commit cdaca88
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
23 changes: 22 additions & 1 deletion extensions/package-manager/js/src/admin/extend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,26 @@ export default [
help: app.translator.trans('flarum-extension-manager.admin.settings.task_retention_days_help'),
type: 'number',
}))
.page(SettingsPage),
.page(SettingsPage)
.generalIndexItems('settings', () => [
{
id: 'minimum-stability',
label: app.translator.trans('flarum-extension-manager.admin.composer.minimum_stability.label', {}, true),
help: app.translator.trans('flarum-extension-manager.admin.composer.minimum_stability.help', {}, true),
},
{
id: 'repositories',
label: app.translator.trans('flarum-extension-manager.admin.composer.repositories.label', {}, true),
help: app.translator.trans('flarum-extension-manager.admin.composer.repositories.help', {}, true),
},
{
id: 'composer-auth',
label: app.translator.trans('flarum-extension-manager.admin.auth_config.title', {}, true),
},
{
id: 'updates',
label: app.translator.trans('flarum-extension-manager.admin.updater.updater_title', {}, true),
help: app.translator.trans('flarum-extension-manager.admin.updater.updater_help', {}, true),
},
]),
];
25 changes: 24 additions & 1 deletion framework/core/js/src/common/extenders/Admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import IExtender, { IExtensionModule } from './IExtender';
import type AdminApplication from '../../admin/AdminApplication';
import type { CustomExtensionPage, SettingConfigInternal } from '../../admin/utils/AdminRegistry';
import type { PermissionConfig, PermissionType } from '../../admin/components/PermissionGrid';
import Mithril from 'mithril';
import type Mithril from 'mithril';
import type { GeneralIndexItem } from '../../admin/states/GeneralSearchIndex';

export default class Admin implements IExtender<AdminApplication> {
protected settings: { setting?: () => SettingConfigInternal; customSetting?: () => Mithril.Children; priority: number }[] = [];
protected permissions: { permission: () => PermissionConfig; type: PermissionType; priority: number }[] = [];
protected customPage: CustomExtensionPage | null = null;
protected generalIndexes: { settings?: () => GeneralIndexItem[]; permissions?: () => GeneralIndexItem[] } = {};

/**
* Register a setting to be shown on the extension's settings page.
Expand Down Expand Up @@ -45,6 +47,15 @@ export default class Admin implements IExtender<AdminApplication> {
return this;
}

/**
* Register a custom general search index entry.
*/
generalIndexItems(type: 'settings' | 'permissions', items: () => GeneralIndexItem[]) {
this.generalIndexes[type] = items;

return this;
}

extend(app: AdminApplication, extension: IExtensionModule) {
app.registry.for(extension.name);

Expand All @@ -59,5 +70,17 @@ export default class Admin implements IExtender<AdminApplication> {
if (this.customPage) {
app.registry.registerPage(this.customPage);
}

app.generalIndex.for(extension.name);

Object.keys(this.generalIndexes).forEach((key) => {
if (key !== 'settings' && key !== 'permissions') return;

const callback = this.generalIndexes[key];

if (callback) {
app.generalIndex.add(key, callback());
}
});
}
}

0 comments on commit cdaca88

Please sign in to comment.