Merge pull request 'fix: 上游跟进,(fix: sort params missing when switch page numbers #3906) 分页时拖拽排序的问题' (#617) from fix/upstream-sort into dev

Reviewed-on: daoyoucloud/tachycode#617
This commit is contained in:
sealday 2024-04-07 20:14:12 +08:00
commit 511f282b8c

View File

@ -1,6 +1,6 @@
import { ArrayField } from '@nocobase/schema'; import { ArrayField } from '@nocobase/schema';
import { useField, useFieldSchema } from '@nocobase/schema'; import { useField, useFieldSchema } from '@nocobase/schema';
import { useEffect } from 'react'; import { useCallback, useEffect, useMemo } from 'react';
import { useFilterBlock } from '../../../../../filter-provider/FilterProvider'; import { useFilterBlock } from '../../../../../filter-provider/FilterProvider';
import { mergeFilter } from '../../../../../filter-provider/utils'; import { mergeFilter } from '../../../../../filter-provider/utils';
import { removeNullCondition } from '../../../../../schema-component'; import { removeNullCondition } from '../../../../../schema-component';
@ -13,6 +13,7 @@ export const useTableBlockProps = () => {
const ctx = useTableBlockContext(); const ctx = useTableBlockContext();
const globalSort = fieldSchema.parent?.['x-decorator-props']?.['params']?.['sort']; const globalSort = fieldSchema.parent?.['x-decorator-props']?.['params']?.['sort'];
const { getDataBlocks } = useFilterBlock(); const { getDataBlocks } = useFilterBlock();
const params = ctx?.service?.params;
useEffect(() => { useEffect(() => {
if (!ctx?.service?.loading) { if (!ctx?.service?.loading) {
@ -53,10 +54,20 @@ export const useTableBlockProps = () => {
}); });
ctx.service.refresh(); ctx.service.refresh();
}, },
onChange({ current, pageSize }, filters, sorter) { onChange: useCallback(
const sort = sorter.order ? (sorter.order === `ascend` ? [sorter.field] : [`-${sorter.field}`]) : globalSort; ({ current, pageSize }, filters, sorter) => {
ctx.service.run({ ...ctx.service.params?.[0], page: current, pageSize, sort }); const sort = !ctx.dragSort
}, ? sorter.order
? sorter.order === `ascend`
? [sorter.field]
: [`-${sorter.field}`]
: globalSort || ctx.dragSortBy
: ctx.dragSortBy;
ctx.service.run({ ...params?.[0], page: current, pageSize, sort });
},
[globalSort, params],
),
onClickRow(record, setSelectedRow, selectedRow) { onClickRow(record, setSelectedRow, selectedRow) {
const { targets, uid } = findFilterTargets(fieldSchema); const { targets, uid } = findFilterTargets(fieldSchema);
const dataBlocks = getDataBlocks(); const dataBlocks = getDataBlocks();