import { observer, useFieldSchema } from '@formily/react'; import { Action, ActionBar, SchemaComponent, SchemaComponentProvider, SchemaInitializer, useDesignable } from '@nocobase/client'; import { Switch } from 'antd'; import React from 'react'; const ActionInitializerButton = observer((props: any) => { return ( Configure actions ); }); const useCurrentActionSchema = (action: string) => { const fieldSchema = useFieldSchema(); const { remove } = useDesignable(); const schema = fieldSchema.reduceProperties((buf, s) => { if (s['x-action'] === action) { return s; } return buf; }); return { schema, exists: !!schema, remove() { schema && remove(schema); }, }; }; const ActionInitializerItem = (props) => { const { title, schema, insert } = props; const { exists, remove } = useCurrentActionSchema(schema['x-action']); return ( { if (exists) { return remove(); } insert({ type: 'void', 'x-component': 'Action', ...schema, }); }} >
{title}
); }; export default function App() { return ( ); }