tachybase_todo/packages/plugins/@nocobase/plugin-multi-app-manager/src/client/MultiAppManagerProvider.tsx
jack zhang 35b06cbfa0
refactor: plugin settings manager (#2712)
* feat: add settingsCenter

* fix: style bug

* chore: optimized code

* refactor: settingCenter Auth

* feat: add aclSnippet option

* refactor: all plugin's setting center api

* feat: add plugin with name

* docs: add settings-center doc

* fix: settings center menu sort by name

* fix: change setting center layout

* fix: change hello sort

* test: add SettingsCenter.ts test case

* fix: bug

* fix: acl bug

* fix: bug

* fix: bug and 404 page

* fix: test bug

* fix: test bug

* fix: bug

* fix: locale

* fix: styling

* fix: rename settingsCenter to pluginSettingsManager

* fix: styling

* fix: e2e bug

* fix: e2e bug

* fix: locale

* feat: update docs

* fix: update

---------

Co-authored-by: chenos <chenlinxh@gmail.com>
2023-11-13 11:01:18 +08:00

65 lines
1.7 KiB
TypeScript

import { Icon, PinnedPluginListProvider, SchemaComponentOptions, useApp, useRequest } from '@nocobase/client';
import { Button, Dropdown } from 'antd';
import React from 'react';
import { Link } from 'react-router-dom';
import { AppNameInput } from './AppNameInput';
import { usePluginUtils } from './utils';
const MultiAppManager = () => {
const { data, run } = useRequest<{
data: any[];
}>(
{
resource: 'applications',
action: 'listPinned',
},
{
manual: true,
},
);
const { t } = usePluginUtils();
const app = useApp();
const items = [
...(data?.data || []).map((app) => {
let link = `/apps/${app.name}/admin/`;
if (app.options?.standaloneDeployment && app.cname) {
link = `//${app.cname}`;
}
return {
key: app.name,
label: (
<a href={link} target="_blank" rel="noopener noreferrer">
{app.displayName || app.name}
</a>
),
};
}),
{
key: '.manager',
label: <Link to={app.pluginSettingsManager.getRoutePath('multi-app-manager')}>{t('Manage applications')}</Link>,
},
];
return (
<Dropdown
onOpenChange={(visible) => {
run();
}}
menu={{ items }}
>
<Button title={'Apps'} icon={<Icon type={'AppstoreOutlined'} />} />
</Dropdown>
);
};
export const MultiAppManagerProvider = (props) => {
return (
<PinnedPluginListProvider
items={{
am: { order: 201, component: 'MultiAppManager', pin: true },
}}
>
<SchemaComponentOptions components={{ MultiAppManager, AppNameInput }}>{props.children}</SchemaComponentOptions>
</PinnedPluginListProvider>
);
};