blob: 0667e0b293e31810e35858b2d5933287e1300617 [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 { GeaflowHeader } 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': 'GeaflowHeader',
'x-async': false,
'x-index': 1,
'x-component-props': {},
},
},
};
return (
<SchemaInitializer.Item
{...props}
icon={<TableOutlined />}
onClick={() => {
insert(schema);
}}
title="GeaflowHeader"
/>
);
};
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 === ' GeaflowHeader'
);
if (!hasCustomBlock) {
children.push({
key: ' GeaflowHeader',
type: 'item',
title: ' GeaflowHeader',
component: PluginBlockInitializer,
});
}
return (
<SchemaComponentOptions
components={{
PluginDesigner,
PluginBlockInitializer,
GeaflowHeader,
}}
>
<SchemaInitializerContext.Provider value={items}>
{props.children}
</SchemaInitializerContext.Provider>
</SchemaComponentOptions>
);
});