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