diff --git a/packages/core/client/src/block-provider/hooks/index.ts b/packages/core/client/src/block-provider/hooks/index.ts index d669f9700e..7be987aa21 100644 --- a/packages/core/client/src/block-provider/hooks/index.ts +++ b/packages/core/client/src/block-provider/hooks/index.ts @@ -929,6 +929,34 @@ export const useRemoveActionProps = (associationName) => { }; }; +export const useDisassociateActionProps = () => { + const filterByTk = useFilterByTk(); + const { resource, service, block, __parent } = useBlockRequestContext(); + const { setVisible } = useActionContext(); + return { + async onClick() { + await resource.remove({ + values: [filterByTk], + }); + + const { count = 0, page = 0, pageSize = 0 } = service?.data?.meta || {}; + if (count % pageSize === 1 && page !== 1) { + service.run({ + ...service?.params?.[0], + page: page - 1, + }); + } else { + service?.refresh?.(); + } + + if (block && block !== 'TableField') { + __parent?.service?.refresh?.(); + setVisible?.(false); + } + }, + }; +}; + export const useDetailPrintActionProps = () => { const { formBlockRef } = useFormBlockContext(); diff --git a/packages/core/client/src/locale/en_US.json b/packages/core/client/src/locale/en_US.json index fc5780851f..9d62938cd6 100644 --- a/packages/core/client/src/locale/en_US.json +++ b/packages/core/client/src/locale/en_US.json @@ -53,6 +53,9 @@ "Insert right": "Insert right", "Insert inner": "Insert inner", "Delete": "Delete", + "Disassociate": "Disassociate", + "Disassociate record": "Disassociate record", + "Are you sure you want to disassociate it?": "Are you sure you want to disassociate it?", "UI editor": "UI editor", "Collection": "Collection", "Collection selector": "Collection selector", diff --git a/packages/core/client/src/locale/es_ES.json b/packages/core/client/src/locale/es_ES.json index 5a768525ed..0b07980888 100644 --- a/packages/core/client/src/locale/es_ES.json +++ b/packages/core/client/src/locale/es_ES.json @@ -52,6 +52,9 @@ "Insert right": "Insertar a la derecha", "Insert inner": "Insertar al interior", "Delete": "Borrar", + "Disassociate": "Desasociar", + "Disassociate record": "Desasociar registro", + "Are you sure you want to disassociate it?": "¿Seguro que quieres desasociarlo?", "UI editor": "IU editor", "Collection": "Colección", "Collections & Fields": "Colección & Campos", diff --git a/packages/core/client/src/locale/fr_FR.json b/packages/core/client/src/locale/fr_FR.json index 7c7e87d735..3630bf1696 100644 --- a/packages/core/client/src/locale/fr_FR.json +++ b/packages/core/client/src/locale/fr_FR.json @@ -52,6 +52,9 @@ "Insert right": "Insérer à droite", "Insert inner": "Insérer à l'intérieur", "Delete": "Supprimer", + "Disassociate": "Dissocier", + "Disassociate record": "Dissocier l'enregistrement", + "Are you sure you want to disassociate it?": "Êtes-vous sûr de vouloir le dissocier ?", "UI editor": "Éditeur d'interface utilisateur", "Collection": "Collection", "Collections & Fields": "Collections et champs", diff --git a/packages/core/client/src/locale/ja_JP.json b/packages/core/client/src/locale/ja_JP.json index 21a2087ed0..55e36c3122 100644 --- a/packages/core/client/src/locale/ja_JP.json +++ b/packages/core/client/src/locale/ja_JP.json @@ -52,6 +52,9 @@ "Insert right": "右に挿入", "Insert inner": "中に挿入", "Delete": "削除", + "Disassociate": "関連付けを解除", + "Disassociate record": "レコードの関連付けを解除", + "Are you sure you want to disassociate it?": "本当に関連付けを解除しますか?", "UI editor": "UI エディタ", "Collection": "コレクション", "Enable child collections": "启用子表", diff --git a/packages/core/client/src/locale/ko_KR.json b/packages/core/client/src/locale/ko_KR.json index cee480711b..662530d4db 100644 --- a/packages/core/client/src/locale/ko_KR.json +++ b/packages/core/client/src/locale/ko_KR.json @@ -60,6 +60,9 @@ "Insert right": "오른쪽에 삽입", "Insert inner": "내부에 삽입", "Delete": "삭제", + "Disassociate": "연결 해제", + "Disassociate record": "레코드 연결 해제", + "Are you sure you want to disassociate it?": "정말로 연결을 해제하시겠습니까?", "UI editor": "UI 편집기", "Collection": "컬렉션", "Collection selector": "컬렉션 선택기", diff --git a/packages/core/client/src/locale/pt_BR.json b/packages/core/client/src/locale/pt_BR.json index 1187469a71..b901a558e5 100644 --- a/packages/core/client/src/locale/pt_BR.json +++ b/packages/core/client/src/locale/pt_BR.json @@ -32,6 +32,9 @@ "Insert right": "Inserir à direita", "Insert inner": "Inserir interno", "Delete": "Excluir", + "Disassociate": "Desassociar", + "Disassociate record": "Desassociar registro", + "Are you sure you want to disassociate it?": "Tem certeza de que deseja desassociá-lo?", "UI editor": "Editor de UI", "Collection": "Coleção", "Collections & Fields": "Coleções e campos", diff --git a/packages/core/client/src/locale/ru_RU.json b/packages/core/client/src/locale/ru_RU.json index f7d6ccc032..9254a98e14 100644 --- a/packages/core/client/src/locale/ru_RU.json +++ b/packages/core/client/src/locale/ru_RU.json @@ -52,6 +52,9 @@ "Insert right": "Вставить справа", "Insert inner": "Вставить внутрь", "Delete": "Удалить", + "Disassociate": "Разъединить", + "Disassociate record": "Разъединить запись", + "Are you sure you want to disassociate it?": "Вы уверены, что хотите разъединить это?", "UI editor": "UI редактор", "Collection": "Коллекция", "Collections & Fields": "Коллекции & Поля", diff --git a/packages/core/client/src/locale/tr_TR.json b/packages/core/client/src/locale/tr_TR.json index 45c6fc2779..820943a907 100644 --- a/packages/core/client/src/locale/tr_TR.json +++ b/packages/core/client/src/locale/tr_TR.json @@ -52,6 +52,9 @@ "Insert right": "Sağa yerleştir", "Insert inner": "İçine yerleştir", "Delete": "Sil", + "Disassociate": "Bağlantıyı kes", + "Disassociate record": "Kaydı bağlantıyı kes", + "Are you sure you want to disassociate it?": "Bağlantıyı kesmek istediğinizden emin misiniz?", "UI editor": "UI editor", "Collection": "Koleksiyonlar", "Collections & Fields": "Koleksiyonlar & Alanlar", diff --git a/packages/core/client/src/locale/uk_UA.json b/packages/core/client/src/locale/uk_UA.json index 5c6cdc1925..9e87c8e29b 100644 --- a/packages/core/client/src/locale/uk_UA.json +++ b/packages/core/client/src/locale/uk_UA.json @@ -52,6 +52,9 @@ "Insert right": "Вставити справа", "Insert inner": "Вставити всередину", "Delete": "Видалити", + "Disassociate": "Роз'єднати", + "Disassociate record": "Роз'єднати запис", + "Are you sure you want to disassociate it?": "Ви впевнені, що хочете роз'єднати це?", "UI editor": "Редактор UI", "Collection": "Колекція", "Collections & Fields": "Колекції та поля", diff --git a/packages/core/client/src/locale/zh-CN.json b/packages/core/client/src/locale/zh-CN.json index 09c8965af5..9674546afc 100644 --- a/packages/core/client/src/locale/zh-CN.json +++ b/packages/core/client/src/locale/zh-CN.json @@ -60,6 +60,9 @@ "Insert right": "在右边插入", "Insert inner": "在里面插入", "Delete": "删除", + "Disassociate": "解除关联", + "Disassociate record": "解除关联记录", + "Are you sure you want to disassociate it?": "你确定要解除关联吗?", "UI editor": "界面配置", "Collection": "数据表", "Collection selector": "数据表选择器", diff --git a/packages/core/client/src/locale/zh-TW.json b/packages/core/client/src/locale/zh-TW.json index 256fad0f27..5f792317cd 100644 --- a/packages/core/client/src/locale/zh-TW.json +++ b/packages/core/client/src/locale/zh-TW.json @@ -60,6 +60,9 @@ "Insert right": "從右邊插入", "Insert inner": "從裡面插入", "Delete": "刪除", + "Disassociate": "解除關聯", + "Disassociate record": "解除關聯記錄", + "Are you sure you want to disassociate it?": "你確定要解除關聯嗎?", "UI editor": "介面編輯", "Collection": "資料表", "Collection selector": "資料表選擇器", diff --git a/packages/core/client/src/modules/actions/disassociate/DisassociateActionInitializer.tsx b/packages/core/client/src/modules/actions/disassociate/DisassociateActionInitializer.tsx new file mode 100644 index 0000000000..5f4145a67d --- /dev/null +++ b/packages/core/client/src/modules/actions/disassociate/DisassociateActionInitializer.tsx @@ -0,0 +1,25 @@ +import React from 'react'; + +import { ActionInitializer } from '../../../schema-initializer/items/ActionInitializer'; + +export const DisassociateActionInitializer = (props) => { + const schema = { + title: '{{ t("Disassociate") }}', + 'x-action': 'disassociate', + 'x-component': 'Action', + 'x-toolbar': 'ActionSchemaToolbar', + 'x-designer': 'Action.Designer', + 'x-component-props': { + icon: 'DeleteOutlined', + confirm: { + title: "{{t('Disassociate record')}}", + content: "{{t('Are you sure you want to disassociate it?')}}", + }, + useProps: '{{ useDisassociateActionProps }}', + }, + 'x-action-settings': { + triggerWorkflows: [], + }, + }; + return ; +}; diff --git a/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx index c235712825..1c0a4716b1 100644 --- a/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/TableActionColumnInitializers.tsx @@ -9,6 +9,7 @@ import { SchemaInitializer } from '../../application/schema-initializer/SchemaIn import { useCollection } from '../../collection-manager'; import { createDesignable, useDesignable } from '../../schema-component'; import { useGetAriaLabelOfDesigner } from '../../schema-settings/hooks/useGetAriaLabelOfDesigner'; +import { useBlockRequestContext } from '../../block-provider/BlockProvider'; export const Resizable = () => { const { t } = useTranslation(); @@ -151,6 +152,27 @@ export const tableActionColumnInitializers = new SchemaInitializer({ return (collection.template !== 'view' || collection?.writableView) && collection.template !== 'sql'; }, }, + { + type: 'item', + title: '{{t("Disassociate")}}', + name: 'disassociate', + Component: 'DisassociateActionInitializer', + schema: { + 'x-component': 'Action.Link', + 'x-action': 'disassociate', + 'x-acl-action': 'destroy', + 'x-decorator': 'ACLActionProvider', + }, + useVisible() { + const { props } = useBlockRequestContext(); + const collection = useCollection(); + return ( + !!props?.association && + (collection.template !== 'view' || collection?.writableView) && + collection.template !== 'sql' + ); + }, + }, { type: 'item', title: '{{t("Add child")}}', diff --git a/packages/core/client/src/schema-initializer/index.ts b/packages/core/client/src/schema-initializer/index.ts index e49b592b35..6055309247 100644 --- a/packages/core/client/src/schema-initializer/index.ts +++ b/packages/core/client/src/schema-initializer/index.ts @@ -1,4 +1,5 @@ import { Plugin } from '../application/Plugin'; +import { DisassociateActionInitializer } from '../modules/actions/disassociate/DisassociateActionInitializer'; import { blockInitializers, createFormActionInitializers, @@ -56,6 +57,7 @@ export class SchemaInitializerPlugin extends Plugin { this.app.addComponents({ ...initializerComponents, ...items, + DisassociateActionInitializer, } as any); this.app.schemaInitializerManager.add(blockInitializers); diff --git a/packages/core/server/src/acl/available-action.ts b/packages/core/server/src/acl/available-action.ts index 2afa4de2ae..3f6780708f 100644 --- a/packages/core/server/src/acl/available-action.ts +++ b/packages/core/server/src/acl/available-action.ts @@ -33,6 +33,7 @@ const availableActions: { }, destroy: { displayName: '{{t("Delete")}}', + aliases: ['destroy', 'remove'], type: 'old-data', }, };