feat: kanban support enable drag and drop (#5468)

This commit is contained in:
Katherine 2024-10-23 10:44:16 +08:00 committed by GitHub
parent b36586f324
commit 37bae6ab34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 35 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import {
useFormBlockContext,
schemaSettingsLabelLayout,
} from '@nocobase/client';
import { useTranslation } from 'react-i18next';
import { useKanbanBlockContext } from './KanbanBlockProvider';
export const kanbanSettings = new SchemaSettings({
name: 'blockSettings:kanban',
@ -78,6 +79,32 @@ export const kanbanSettings = new SchemaSettings({
},
},
schemaSettingsLabelLayout,
{
name: 'allowDragAndDrop',
type: 'switch',
useComponentProps: () => {
const field = useField();
const fieldSchema = useFieldSchema();
const { t } = useTranslation();
const { dn } = useDesignable();
return {
title: t('Enable drag and drop sorting'),
checked: field.componentProps?.dragSort !== false,
onChange: async (dragSort) => {
field.componentProps = field.componentProps || {};
field.componentProps.dragSort = dragSort;
fieldSchema['x-component-props'] = fieldSchema['x-component-props'] || {};
fieldSchema['x-component-props'].dragSort = dragSort;
dn.emit('patch', {
schema: {
['x-uid']: fieldSchema['x-uid'],
'x-component-props': fieldSchema['x-component-props'],
},
});
},
};
},
},
{
name: 'divider',
type: 'divider',

View File

@ -8,7 +8,7 @@
*/
import { ArrayField } from '@formily/core';
import { useField } from '@formily/react';
import { useField, useFieldSchema } from '@formily/react';
import { Spin } from 'antd';
import React, { createContext, useCallback, useContext, useEffect, useState } from 'react';
import {
@ -82,8 +82,13 @@ export const useKanbanBlockContext = () => {
};
const useDisableCardDrag = () => {
const fieldSchema = useFieldSchema();
const { dragSort } = fieldSchema?.parent?.['x-component-props'] || {};
const ctx = useKanbanBlockContext();
const { allowAll, allowConfigure, parseAction } = useACLRoleContext();
if (dragSort === false) {
return true;
}
if (allowAll || allowConfigure) {
return false;
}

View File

@ -4,5 +4,6 @@
"Create sort field": "创建排序字段",
"Convert the following integer fields to sorting fields": "将以下整数字段转为排序字段",
"Sorting field":"排序字段",
"Grouped sorting based on":"基于分组字段"
"Grouped sorting based on":"基于分组字段",
"Enable drag and drop sorting":"启用拖拽排序"
}