mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-01 18:52:20 +08:00
refactor: set sorting rule
This commit is contained in:
parent
40ee889135
commit
1ef49c8717
@ -49,6 +49,6 @@ export const dataScope = defineAction({
|
||||
return;
|
||||
}
|
||||
resource.addFilterGroup(ctx.model.uid, params.filter);
|
||||
resource.refresh();
|
||||
// resource.refresh();
|
||||
},
|
||||
});
|
||||
|
@ -12,4 +12,5 @@ export * from './dataScope';
|
||||
export * from './openView';
|
||||
export * from './titleField';
|
||||
export * from './dateTimeFormat';
|
||||
export * from './sortingRules';
|
||||
//
|
||||
|
112
packages/core/client/src/flow/actions/sortingRules.tsx
Normal file
112
packages/core/client/src/flow/actions/sortingRules.tsx
Normal file
@ -0,0 +1,112 @@
|
||||
/**
|
||||
* 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 { defineAction, MultiRecordResource, useStepSettingContext } from '@nocobase/flow-engine';
|
||||
import React from 'react';
|
||||
import { Select } from 'antd';
|
||||
import { tval } from '@nocobase/utils/client';
|
||||
import { useCompile } from '../../schema-component';
|
||||
import { useSortFields } from '../../';
|
||||
|
||||
const SelectOptions = (props) => {
|
||||
const {
|
||||
model: { resource },
|
||||
app,
|
||||
} = useStepSettingContext();
|
||||
const compile = useCompile();
|
||||
const sortFields = useSortFields(resource?.resourceName);
|
||||
console.log(sortFields);
|
||||
return <Select {...props} options={sortFields} />;
|
||||
};
|
||||
const isArrayEqualIgnoreOrder = (a: string[], b: string[]) =>
|
||||
a.length === b.length && [...a].sort().every((v, i) => v === [...b].sort()[i]);
|
||||
export const sortingRule = defineAction({
|
||||
name: 'sortingRule',
|
||||
title: tval('Set default sorting rules'),
|
||||
uiSchema: {
|
||||
sort: {
|
||||
type: 'array',
|
||||
'x-component': 'ArrayItems',
|
||||
'x-decorator': 'FormItem',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
space: {
|
||||
type: 'void',
|
||||
'x-component': 'Space',
|
||||
properties: {
|
||||
sort: {
|
||||
type: 'void',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'ArrayItems.SortHandle',
|
||||
},
|
||||
field: {
|
||||
type: 'string',
|
||||
required: true,
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': SelectOptions,
|
||||
'x-component-props': {
|
||||
style: {
|
||||
width: 260,
|
||||
},
|
||||
},
|
||||
},
|
||||
direction: {
|
||||
type: 'string',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'Radio.Group',
|
||||
'x-component-props': {
|
||||
optionType: 'button',
|
||||
},
|
||||
enum: [
|
||||
{
|
||||
label: tval('ASC'),
|
||||
value: 'asc',
|
||||
},
|
||||
{
|
||||
label: tval('DESC'),
|
||||
value: 'desc',
|
||||
},
|
||||
],
|
||||
},
|
||||
remove: {
|
||||
type: 'void',
|
||||
'x-decorator': 'FormItem',
|
||||
'x-component': 'ArrayItems.Remove',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
properties: {
|
||||
add: {
|
||||
type: 'void',
|
||||
title: tval('Add sort field'),
|
||||
'x-component': 'ArrayItems.Addition',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
defaultParams(ctx) {
|
||||
return {
|
||||
sort: [],
|
||||
};
|
||||
},
|
||||
async handler(ctx, params) {
|
||||
const sortArr = params.sort.map((item) => {
|
||||
return item.direction === 'desc' ? `-${item.field}` : item.field;
|
||||
});
|
||||
// @ts-ignore
|
||||
const resource = ctx.model?.resource as MultiRecordResource;
|
||||
if (!resource) {
|
||||
return;
|
||||
}
|
||||
resource.setSort(sortArr);
|
||||
},
|
||||
});
|
@ -502,6 +502,10 @@ TableModel.registerFlow({
|
||||
use: 'dataScope',
|
||||
title: tval('Set data scope'),
|
||||
},
|
||||
sortingRule: {
|
||||
use: 'sortingRule',
|
||||
title: tval('Set default sorting rules'),
|
||||
},
|
||||
enabledIndexColumn: {
|
||||
title: tval('Enable index column'),
|
||||
uiSchema: {
|
||||
|
Loading…
x
Reference in New Issue
Block a user