tachybase_todo/packages/plugins/export/src/client/ExportDesigner.tsx
SemmyWong d831a9b889
feat: plugin export (#479)
* feat: init export plugin

* feat: add client export

* fix: fix the word spell

* feat: export plugin done

* feat: init export plugin

* feat: add client export

* fix: fix the word spell

* feat: export plugin done

* ci: change plugin-export version

* refactor: renders add ctx params

* fix: fix select and multipleSelect export

* fix: array convert string

* refactor: move SchemaInitializerPluginProvider

* fix: build error

* fix: change umijs config

* fix: update SchemaInitializerPluginProvider

* fix: import server

* fix: fix some bug

* fix: fix some bug

* refactor: export plugin refactor

* refactor: create all export fields by default

* fix: fix export plugin bug

* fix(plugin-collection-manager): uiSchema toJSON

* fix: update yarn.lock

* fix: fix init fields bug

* refactor: enum params pass by client

* fix: fix export table header title

* refactor: refactor dataIndex

* fix: fix dataIndex maybe complex object

* fix: add checkboxGroup in export plugin

* fix: add checkbox and i18n

* feat: improve code

Co-authored-by: chenos <chenlinxh@gmail.com>
2022-06-14 15:01:53 +08:00

123 lines
4.4 KiB
TypeScript

import { ArrayItems } from '@formily/antd';
import type { ISchema } from '@formily/react';
import { useField, useFieldSchema } from '@formily/react';
import { GeneralSchemaDesigner, SchemaSettings, useDesignable } from '@nocobase/client';
import React, { useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useShared } from './useShared';
export const ExportDesigner = () => {
const field = useField();
const fieldSchema = useFieldSchema();
const { t } = useTranslation();
const { dn } = useDesignable();
const [schema, setSchema] = useState<ISchema>();
const { schema: pageSchema } = useShared();
useEffect(() => {
setSchema(pageSchema);
}, [field.address, fieldSchema?.['x-action-settings']?.['exportSettings']]);
return (
<GeneralSchemaDesigner disableInitializer>
<SchemaSettings.ModalItem
title={t('Edit button')}
schema={
{
type: 'object',
title: t('Edit button'),
properties: {
title: {
'x-decorator': 'FormItem',
'x-component': 'Input',
title: t('Button title'),
default: fieldSchema.title,
'x-component-props': {},
// description: `原字段标题:${collectionField?.uiSchema?.title}`,
},
icon: {
'x-decorator': 'FormItem',
'x-component': 'IconPicker',
title: t('Button icon'),
default: fieldSchema?.['x-component-props']?.icon,
'x-component-props': {},
// description: `原字段标题:${collectionField?.uiSchema?.title}`,
},
type: {
'x-decorator': 'FormItem',
'x-component': 'Radio.Group',
title: t('Button background color'),
default: fieldSchema?.['x-component-props']?.danger
? 'danger'
: fieldSchema?.['x-component-props']?.type === 'primary'
? 'primary'
: 'default',
enum: [
{ value: 'default', label: '{{t("Default")}}' },
{ value: 'primary', label: '{{t("Highlight")}}' },
{ value: 'danger', label: '{{t("Danger red")}}' },
],
},
},
} as ISchema
}
onSubmit={({ title, icon, type }) => {
if (title) {
fieldSchema.title = title;
field.title = title;
field.componentProps.icon = icon;
field.componentProps.danger = type === 'danger';
field.componentProps.type = type;
fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
fieldSchema['x-component-props'].icon = icon;
fieldSchema['x-component-props'].danger = type === 'danger';
fieldSchema['x-component-props'].type = type;
dn.emit('patch', {
schema: {
['x-uid']: fieldSchema['x-uid'],
title,
'x-component-props': {
...fieldSchema['x-component-props'],
},
},
});
dn.refresh();
}
}}
/>
<SchemaSettings.ActionModalItem
title={t('Exportable fields')}
schema={schema}
initialValues={{ exportSettings: fieldSchema?.['x-action-settings']?.exportSettings }}
components={{ ArrayItems }}
onSubmit={({ exportSettings }) => {
fieldSchema['x-action-settings']['exportSettings'] = exportSettings
?.filter((fieldItem) => fieldItem?.dataIndex?.length)
.map((item) => ({
dataIndex: item.dataIndex.map((di) => di.name ?? di),
title: item.title,
}));
dn.emit('patch', {
schema: {
['x-uid']: fieldSchema['x-uid'],
'x-action-settings': fieldSchema['x-action-settings'],
},
});
dn.refresh();
}}
/>
<SchemaSettings.Divider />
<SchemaSettings.Remove
removeParentsIfNoChildren
breakRemoveOn={(s) => {
return s['x-component'] === 'Space' || s['x-component'].endsWith('ActionBar');
}}
confirm={{
title: t('Delete action'),
}}
/>
</GeneralSchemaDesigner>
);
};