blob: 14186b2fe0126f8317ac402c2de450236ab27197 [file] [log] [blame]
import React, { useContext } from 'react';
import { TableOutlined } from '@ant-design/icons';
import {
SchemaComponentOptions,
SchemaInitializer,
SchemaInitializerContext,
} from '@tugraph/openpiece-client';
// @ts-ignore
import { UserManage } from '@@plugins/src/components/console/geaflow';
import { PluginDesigner } from './PluginDesigner';
export const PluginBlockInitializer = (props) => {
const { insert } = props;
const schema = {
type: 'void',
'x-component': 'CardItem',
'x-designer': 'PluginDesigner',
properties: {
row1: {
type: 'void',
'x-component': 'UserManage',
'x-async': false,
'x-index': 1,
'x-component-props': {},
},
},
};
return (
<SchemaInitializer.Item
{...props}
icon={<TableOutlined />}
onClick={() => {
insert(schema);
}}
title="UserManage"
/>
);
};
export default React.memo((props) => {
const items = useContext(SchemaInitializerContext) as any;
const children = items?.BlockInitializers?.items?.[1]?.children ?? [];
const hasCustomBlock = children?.find(
(d) => d.key === ' UserManage'
);
if (!hasCustomBlock) {
children.push({
key: ' UserManage',
type: 'item',
title: ' UserManage',
component: PluginBlockInitializer,
});
}
return (
<SchemaComponentOptions
components={{
PluginDesigner,
PluginBlockInitializer,
UserManage,
}}
>
<SchemaInitializerContext.Provider value={items}>
{props.children}
</SchemaInitializerContext.Provider>
</SchemaComponentOptions>
);
});