2022-02-07 23:30:24 +08:00
|
|
|
import { observer } from '@formily/react';
|
|
|
|
import { Action, ActionBar, SchemaComponent, SchemaComponentProvider, SchemaInitializer } from '@nocobase/client';
|
2022-02-07 21:52:51 +08:00
|
|
|
import React from 'react';
|
|
|
|
|
2022-02-07 23:30:24 +08:00
|
|
|
const InitializerButton = observer((props: any) => {
|
2022-02-07 21:52:51 +08:00
|
|
|
return (
|
|
|
|
<SchemaInitializer.Button
|
|
|
|
wrap={(schema) => schema}
|
2022-02-07 23:30:24 +08:00
|
|
|
insertPosition={'beforeEnd'}
|
|
|
|
style={{ marginLeft: 8 }}
|
2022-02-07 21:52:51 +08:00
|
|
|
items={[
|
|
|
|
{
|
2022-02-07 23:30:24 +08:00
|
|
|
title: 'Enable actions',
|
2022-02-07 21:52:51 +08:00
|
|
|
children: [
|
|
|
|
{
|
2022-02-07 23:30:24 +08:00
|
|
|
title: 'Create',
|
|
|
|
key: 'create',
|
|
|
|
component: 'ActionInitializer',
|
|
|
|
schema: {
|
|
|
|
'x-align': 'left',
|
|
|
|
},
|
2022-02-07 21:52:51 +08:00
|
|
|
},
|
|
|
|
{
|
2022-02-07 23:30:24 +08:00
|
|
|
title: 'Update',
|
|
|
|
key: 'update',
|
|
|
|
component: 'ActionInitializer',
|
2022-02-07 21:52:51 +08:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
>
|
|
|
|
Configure actions
|
|
|
|
</SchemaInitializer.Button>
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2022-02-07 23:30:24 +08:00
|
|
|
const ActionInitializer = (props) => {
|
|
|
|
const { title, schema, insert } = props;
|
2022-02-07 21:52:51 +08:00
|
|
|
return (
|
|
|
|
<SchemaInitializer.Item
|
|
|
|
onClick={(info) => {
|
|
|
|
insert({
|
|
|
|
type: 'void',
|
|
|
|
title: info.key,
|
2022-02-07 23:30:24 +08:00
|
|
|
'x-component': 'Action',
|
|
|
|
...schema,
|
2022-02-07 21:52:51 +08:00
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
2022-02-07 23:30:24 +08:00
|
|
|
{title}
|
2022-02-07 21:52:51 +08:00
|
|
|
</SchemaInitializer.Item>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function App() {
|
|
|
|
return (
|
2022-02-07 23:30:24 +08:00
|
|
|
<SchemaComponentProvider components={{ ActionBar, Action, ActionInitializer, InitializerButton }}>
|
2022-02-07 21:52:51 +08:00
|
|
|
<SchemaComponent
|
|
|
|
schema={{
|
|
|
|
type: 'void',
|
|
|
|
name: 'page',
|
2022-02-07 23:30:24 +08:00
|
|
|
'x-component': 'ActionBar',
|
|
|
|
'x-initializer': 'InitializerButton',
|
2022-02-07 21:52:51 +08:00
|
|
|
properties: {
|
2022-02-07 23:30:24 +08:00
|
|
|
action1: {
|
2022-02-07 21:52:51 +08:00
|
|
|
type: 'void',
|
|
|
|
title: 'Test1',
|
2022-02-07 23:30:24 +08:00
|
|
|
'x-component': 'Action',
|
2022-02-07 21:52:51 +08:00
|
|
|
},
|
2022-02-07 23:30:24 +08:00
|
|
|
action2: {
|
2022-02-07 21:52:51 +08:00
|
|
|
type: 'void',
|
|
|
|
title: 'Test2',
|
2022-02-07 23:30:24 +08:00
|
|
|
'x-component': 'Action',
|
2022-02-07 21:52:51 +08:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</SchemaComponentProvider>
|
|
|
|
);
|
|
|
|
}
|