ChengLei Shao 61e7a89067
refactor: export action (#5665)
* chore: export xlsx command

* chore: container service

* chore: report export progress

* chore: export

* chore: performInsert

* chore: export command

* chore: base exporter

* chore: limit option

* chore: export

* chore: export

* chore: types

* chore: ws socket with auth

* refactor: refactor exporter, change addRows method to handleRow method to support row-by-row processing

* chore: xlsx exporter

* chore: base exporter

* chore: export limit

* chore: import action

* chore: load websocket

* chore: import action

* chore: object to cli args

* chore: import options

* chore: import action

* chore: import runner

* chore: import action

* chore: import options

* chore: import options

* chore: plugin load event

* chore: test

* chore: i18n

* chore: i18n

* chore: i18n

* fix: ws auth status

* chore: cache in data source

* chore: load datasource

* chore: import with field alias

* fix: build

* fix: test

* fix: build

* fix: import schema settings

* fix: import action

* fix: import progress

* chore: template creator

* fix: import error message

* fix: import error message

* chore: test

* chore: workflow dispatch event

* chore: export alias

* fix: typo

* chore: error render

* fix: event error

* chore: send message to tags

* fix: test

* fix: import action setting
2024-12-31 20:16:03 +08:00

156 lines
4.8 KiB
TypeScript

/**
* This file is part of the NocoBase (R) project.
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
* Authors: NocoBase Team.
*
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
* For more information, please refer to: https://www.nocobase.com/agreement.
*/
import type { VoidField } from '@formily/core';
import { Cascader, css, useCollection_deprecated } from '@nocobase/client';
import { useTranslation } from 'react-i18next';
import { NAMESPACE } from './constants';
import { useFields } from './useFields';
const INCLUDE_FILE_TYPE = [
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
'application/vnd.ms-excel',
'application/wps-office.xlsx',
];
export const useShared = () => {
const { t } = useTranslation(NAMESPACE);
const { name } = useCollection_deprecated();
const fields = useFields(name);
return {
importSettingsSchema: {
type: 'void',
'x-component': 'Grid',
properties: {
explain: {
type: 'string',
title: `{{ t("Import explain", {ns: "${NAMESPACE}"}) }}`,
'x-decorator': 'FormItem',
'x-component': 'Input.TextArea',
},
importColumns: {
type: 'array',
'x-component': 'ArrayItems',
'x-decorator': 'FormItem',
items: {
type: 'object',
properties: {
space: {
type: 'void',
'x-component': 'Space',
'x-component-props': {
className: css`
width: 100%;
& .ant-space-item:nth-child(2) {
flex: 1;
}
`,
},
properties: {
sort: {
type: 'void',
'x-decorator': 'FormItem',
'x-component': 'ArrayItems.SortHandle',
},
dataIndex: {
type: 'array',
'x-decorator': 'FormItem',
'x-component': Cascader,
required: true,
enum: fields,
'x-component-props': {
fieldNames: {
label: 'title',
value: 'name',
children: 'children',
},
changeOnSelect: false,
},
},
title: {
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-component-props': {
placeholder: '{{ t("Custom column title") }}',
},
},
description: {
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Input',
'x-component-props': {
placeholder: `{{ t("Field description placeholder", {ns: "${NAMESPACE}"}) }}`,
},
},
remove: {
type: 'void',
'x-decorator': 'FormItem',
'x-component': 'ArrayItems.Remove',
},
},
},
},
},
properties: {
add: {
type: 'void',
title: `{{ t("Add importable field", {ns: "${NAMESPACE}"}) }}`,
'x-component': 'ArrayItems.Addition',
'x-component-props': {
className: css`
border-color: var(--colorSettings);
color: var(--colorSettings);
&.ant-btn-dashed:hover {
border-color: var(--colorSettings);
color: var(--colorSettings);
}
`,
},
},
},
},
},
},
beforeUploadHandler() {
return false;
},
uploadValidator(value, rule) {
if (value.length > 1) {
return {
type: 'error',
message: t('Only one file is allowed to be uploaded'),
};
}
const file = value[0] ?? {};
if (file.size > 10 * 1024 * 1024) {
return {
type: 'error',
message: t('File size cannot exceed 10M'),
};
}
if (!INCLUDE_FILE_TYPE.includes(file.type)) {
return {
type: 'error',
message: t('Please upload the file of Excel'),
};
}
return '';
},
validateUpload(form, submitField: VoidField, deps) {
const [upload] = deps;
submitField.disabled = upload?.length === 0;
submitField.componentProps = {
...submitField.componentProps,
disabled: upload?.length === 0 || form.errors?.length > 0,
};
},
};
};