tachybase_todo/packages/client/src/acl/ACLShortcut.tsx

56 lines
1.4 KiB
TypeScript
Raw Normal View History

2022-01-19 15:14:00 +08:00
import { LockOutlined } from '@ant-design/icons';
import { ISchema, useForm } from '@formily/react';
2022-01-30 19:28:42 +08:00
import { uid } from '@formily/shared';
import React, { useState } from 'react';
2022-03-06 16:19:18 +08:00
import { useTranslation } from 'react-i18next';
import { PluginManager } from '../plugin-manager';
2022-02-10 12:06:48 +08:00
import { ActionContext, SchemaComponent, useActionContext } from '../schema-component';
2022-02-17 01:06:42 +08:00
import * as components from './Configuration';
2022-01-19 15:14:00 +08:00
const useCloseAction = () => {
2022-02-10 12:06:48 +08:00
const { setVisible } = useActionContext();
2022-01-19 15:14:00 +08:00
const form = useForm();
return {
async run() {
setVisible(false);
form.submit((values) => {
console.log(values);
});
},
};
};
const schema: ISchema = {
type: 'object',
properties: {
2022-01-30 19:28:42 +08:00
[uid()]: {
2022-01-19 15:14:00 +08:00
'x-component': 'Action.Drawer',
type: 'void',
2022-03-06 16:19:18 +08:00
title: '{{t("Roles & Permissions")}}',
2022-01-19 15:14:00 +08:00
properties: {
hello1: {
type: 'void',
2022-01-30 19:28:42 +08:00
'x-component': 'RoleTable',
2022-01-19 15:14:00 +08:00
},
},
},
},
};
export const ACLShortcut = () => {
2022-01-19 15:14:00 +08:00
const [visible, setVisible] = useState(false);
2022-03-06 16:19:18 +08:00
const { t } = useTranslation();
2022-01-19 15:14:00 +08:00
return (
2022-02-10 12:06:48 +08:00
<ActionContext.Provider value={{ visible, setVisible }}>
<PluginManager.Toolbar.Item
icon={<LockOutlined />}
2022-03-06 16:19:18 +08:00
title={t('Roles & Permissions')}
2022-01-19 15:14:00 +08:00
onClick={() => {
setVisible(true);
}}
/>
2022-02-17 01:06:42 +08:00
<SchemaComponent components={components} scope={{ useCloseAction }} schema={schema} />
2022-02-10 12:06:48 +08:00
</ActionContext.Provider>
2022-01-19 15:14:00 +08:00
);
};