fix(Data-template): fix bug when deleting fields (#1907)
* chore: add translation * fix(Data-template): fix bug when deleting fields --------- Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
d35f67d2e1
commit
110b00bc01
@ -708,4 +708,6 @@ export default {
|
|||||||
"Render Failed": "Render Failed",
|
"Render Failed": "Render Failed",
|
||||||
"Feedback": "Feedback",
|
"Feedback": "Feedback",
|
||||||
"Try again": "Try again",
|
"Try again": "Try again",
|
||||||
|
"Data template": "Data template",
|
||||||
|
"Template fields have been removed and need to be reconfigured": "Template fields have been removed and need to be reconfigured",
|
||||||
};
|
};
|
||||||
|
@ -686,5 +686,7 @@ export default {
|
|||||||
"UpdatedAt": "Registro del último usuario actualizado de una fila",
|
"UpdatedAt": "Registro del último usuario actualizado de una fila",
|
||||||
"Column width": "Ancho de columna",
|
"Column width": "Ancho de columna",
|
||||||
"Sortable": "Clasificable",
|
"Sortable": "Clasificable",
|
||||||
"Enable link": "Activar enlace"
|
"Enable link": "Activar enlace",
|
||||||
};
|
"Data template": "Plantilla de datos",
|
||||||
|
"Template fields have been removed and need to be reconfigured": "Los campos de la plantilla se han eliminado y deben reconfigurarse",
|
||||||
|
};
|
||||||
|
@ -617,4 +617,6 @@ export default {
|
|||||||
'Add template': 'テンプレートを追加',
|
'Add template': 'テンプレートを追加',
|
||||||
'Display data template selector': 'データテンプレートセレクターを表示',
|
'Display data template selector': 'データテンプレートセレクターを表示',
|
||||||
'Form data templates': 'フォームデータテンプレート',
|
'Form data templates': 'フォームデータテンプレート',
|
||||||
|
"Data template": "データテンプレート",
|
||||||
|
"Template fields have been removed and need to be reconfigured": "テンプレートフィールドが削除されました。再設定する必要があります",
|
||||||
}
|
}
|
||||||
|
@ -667,4 +667,6 @@ export default {
|
|||||||
'Add template': 'Adicionar modelo',
|
'Add template': 'Adicionar modelo',
|
||||||
'Display data template selector': 'Exibir seletor de modelo de dados',
|
'Display data template selector': 'Exibir seletor de modelo de dados',
|
||||||
'Form data templates': 'Modelos de dados do formulário',
|
'Form data templates': 'Modelos de dados do formulário',
|
||||||
|
"Data template": "Modelo de dados",
|
||||||
|
"Template fields have been removed and need to be reconfigured": "Os campos do modelo foram removidos e precisam ser reconfigurados",
|
||||||
};
|
};
|
||||||
|
@ -521,4 +521,6 @@ export default {
|
|||||||
'Add template': "Добавить шаблон",
|
'Add template': "Добавить шаблон",
|
||||||
'Display data template selector': "Отображать селектор шаблона данных",
|
'Display data template selector': "Отображать селектор шаблона данных",
|
||||||
'Form data templates': "Шаблоны данных формы",
|
'Form data templates': "Шаблоны данных формы",
|
||||||
|
"Data template": "Шаблон данных",
|
||||||
|
"Template fields have been removed and need to be reconfigured": "Поля шаблона были удалены и требуют повторной настройки",
|
||||||
}
|
}
|
||||||
|
@ -520,4 +520,6 @@ export default {
|
|||||||
'Add template': 'Şablon ekle',
|
'Add template': 'Şablon ekle',
|
||||||
'Display data template selector': 'Veri şablonu seçicisini görüntüle',
|
'Display data template selector': 'Veri şablonu seçicisini görüntüle',
|
||||||
'Form data templates': 'Form veri şablonları',
|
'Form data templates': 'Form veri şablonları',
|
||||||
|
"Data template": "Veri şablonu",
|
||||||
|
"Template fields have been removed and need to be reconfigured": "Şablon alanları kaldırıldı ve yeniden yapılandırılması gerekiyor",
|
||||||
}
|
}
|
||||||
|
@ -777,6 +777,7 @@ export default {
|
|||||||
'Add template': '添加模板',
|
'Add template': '添加模板',
|
||||||
'Display data template selector': '显示数据模板选择框',
|
'Display data template selector': '显示数据模板选择框',
|
||||||
'Form data templates': '表单数据模板',
|
'Form data templates': '表单数据模板',
|
||||||
|
'Data template': '数据模板',
|
||||||
|
|
||||||
'Reload Application': '重载应用',
|
'Reload Application': '重载应用',
|
||||||
'The application is reloading, please do not close the page.': '应用正在重新加载,请勿关闭页面。',
|
'The application is reloading, please do not close the page.': '应用正在重新加载,请勿关闭页面。',
|
||||||
@ -785,5 +786,6 @@ export default {
|
|||||||
"Allows to clear cache, reboot application": "允许清除缓存,重启应用",
|
"Allows to clear cache, reboot application": "允许清除缓存,重启应用",
|
||||||
'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?': '重启将会中断当前服务,这个过程可能需要一点时间,确定要继续吗?',
|
'The will interrupt service, it may take a few seconds to restart. Are you sure to continue?': '重启将会中断当前服务,这个过程可能需要一点时间,确定要继续吗?',
|
||||||
'Reboot': '重启',
|
'Reboot': '重启',
|
||||||
|
"Template fields have been removed and need to be reconfigured": "模板字段已被删除,需要重新配置",
|
||||||
'Clear cache': '清除缓存',
|
'Clear cache': '清除缓存',
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { useFieldSchema } from '@formily/react';
|
import { useFieldSchema } from '@formily/react';
|
||||||
import { forEach } from '@nocobase/utils/client';
|
import { forEach, showToast } from '@nocobase/utils/client';
|
||||||
import { Select } from 'antd';
|
import { Select } from 'antd';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import React, { useCallback, useEffect } from 'react';
|
import React, { useCallback, useEffect } from 'react';
|
||||||
@ -25,12 +25,28 @@ const useDataTemplates = () => {
|
|||||||
const fieldSchema = useFieldSchema();
|
const fieldSchema = useFieldSchema();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { items = [], display = true } = findDataTemplates(fieldSchema);
|
const { items = [], display = true } = findDataTemplates(fieldSchema);
|
||||||
|
const { getCollectionJoinField } = useCollectionManager();
|
||||||
|
|
||||||
|
// 过滤掉已经被删除的字段
|
||||||
|
items.forEach((item) => {
|
||||||
|
item.fields = item.fields
|
||||||
|
.map((field) => {
|
||||||
|
const joinField = getCollectionJoinField(`${item.collection}.${field}`);
|
||||||
|
if (joinField) {
|
||||||
|
return field;
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
})
|
||||||
|
.filter(Boolean);
|
||||||
|
});
|
||||||
|
|
||||||
const templates: any = [
|
const templates: any = [
|
||||||
{
|
{
|
||||||
key: 'none',
|
key: 'none',
|
||||||
title: t('None'),
|
title: t('None'),
|
||||||
},
|
},
|
||||||
].concat(items.map<any>((t, i) => ({ key: i, ...t })));
|
].concat(items.map<any>((t, i) => ({ key: i, ...t })));
|
||||||
|
|
||||||
const defaultTemplate = items.find((item) => item.default);
|
const defaultTemplate = items.find((item) => item.default);
|
||||||
return {
|
return {
|
||||||
templates,
|
templates,
|
||||||
@ -42,14 +58,13 @@ const useDataTemplates = () => {
|
|||||||
|
|
||||||
export const Templates = ({ style = {}, form }) => {
|
export const Templates = ({ style = {}, form }) => {
|
||||||
const { templates, display, enabled, defaultTemplate } = useDataTemplates();
|
const { templates, display, enabled, defaultTemplate } = useDataTemplates();
|
||||||
const { getCollectionField } = useCollectionManager();
|
|
||||||
const [value, setValue] = React.useState(defaultTemplate?.key || 'none');
|
const [value, setValue] = React.useState(defaultTemplate?.key || 'none');
|
||||||
const api = useAPIClient();
|
const api = useAPIClient();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (defaultTemplate) {
|
if (defaultTemplate) {
|
||||||
fetchTemplateData(api, defaultTemplate)
|
fetchTemplateData(api, defaultTemplate, t)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (form) {
|
if (form) {
|
||||||
forEach(data, (value, key) => {
|
forEach(data, (value, key) => {
|
||||||
@ -58,6 +73,7 @@ export const Templates = ({ style = {}, form }) => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
return data;
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
@ -68,15 +84,20 @@ export const Templates = ({ style = {}, form }) => {
|
|||||||
const handleChange = useCallback(async (value, option) => {
|
const handleChange = useCallback(async (value, option) => {
|
||||||
setValue(value);
|
setValue(value);
|
||||||
if (option.key !== 'none') {
|
if (option.key !== 'none') {
|
||||||
fetchTemplateData(api, option).then((data) => {
|
fetchTemplateData(api, option, t)
|
||||||
if (form) {
|
.then((data) => {
|
||||||
forEach(data, (value, key) => {
|
if (form) {
|
||||||
if (value) {
|
forEach(data, (value, key) => {
|
||||||
form.values[key] = value;
|
if (value) {
|
||||||
}
|
form.values[key] = value;
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
});
|
}
|
||||||
|
return data;
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error(err);
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
form?.reset();
|
form?.reset();
|
||||||
}
|
}
|
||||||
@ -110,7 +131,10 @@ function findDataTemplates(fieldSchema): ITemplate {
|
|||||||
return {} as ITemplate;
|
return {} as ITemplate;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchTemplateData(api, template: { collection: string; dataId: number; fields: string[] }) {
|
async function fetchTemplateData(api, template: { collection: string; dataId: number; fields: string[] }, t) {
|
||||||
|
if (template.fields.length === 0) {
|
||||||
|
return showToast(t('Template fields have been removed and need to be reconfigured'));
|
||||||
|
}
|
||||||
return api
|
return api
|
||||||
.resource(template.collection)
|
.resource(template.collection)
|
||||||
.get({
|
.get({
|
||||||
|
@ -3,10 +3,12 @@ export * from './common';
|
|||||||
export * from './date';
|
export * from './date';
|
||||||
export * from './forEach';
|
export * from './forEach';
|
||||||
export * from './getValuesByPath';
|
export * from './getValuesByPath';
|
||||||
|
export * from './json-templates';
|
||||||
export * from './merge';
|
export * from './merge';
|
||||||
|
export * from './notification';
|
||||||
export * from './number';
|
export * from './number';
|
||||||
export * from './parse-filter';
|
export * from './parse-filter';
|
||||||
export * from './registry';
|
export * from './registry';
|
||||||
// export * from './toposort';
|
// export * from './toposort';
|
||||||
export * from './uid';
|
export * from './uid';
|
||||||
export * from './json-templates';
|
|
||||||
|
8
packages/core/utils/src/notification.ts
Normal file
8
packages/core/utils/src/notification.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { notification } from 'antd';
|
||||||
|
|
||||||
|
export const showToast = (message, type = 'info', duration = 5000) => {
|
||||||
|
notification[type]({
|
||||||
|
message,
|
||||||
|
duration,
|
||||||
|
});
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user