mirror of
https://github.com/nocobase/nocobase
synced 2024-11-15 10:06:22 +00:00
Revert "fix: the edit drawer's audit logs block can only get records by this … (#1917)"
This reverts commit 42ad77da68
.
# Conflicts:
# packages/core/client/src/block-provider/TableBlockProvider.tsx
# packages/core/client/src/schema-component/antd/filter/useValues.ts
This commit is contained in:
parent
5e4682be72
commit
a1872fa75b
@ -1,7 +1,7 @@
|
||||
import { ArrayField, createForm } from '@formily/core';
|
||||
import { FormContext, useField, useFieldSchema } from '@formily/react';
|
||||
import React, { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||
import { useCollection, useCollectionManager } from '../collection-manager';
|
||||
import { useCollectionManager } from '../collection-manager';
|
||||
import { useFilterBlock } from '../filter-provider/FilterProvider';
|
||||
import { useRecord } from '../record-provider';
|
||||
import { FixedBlockWrapper, SchemaComponentOptions, removeNullCondition } from '../schema-component';
|
||||
@ -102,13 +102,8 @@ export const TableBlockProvider = (props) => {
|
||||
const record = useRecord();
|
||||
const fieldSchema = useFieldSchema();
|
||||
const { getCollection, getCollectionField } = useCollectionManager();
|
||||
const parent = useCollection();
|
||||
const filter = generateFilterParams(record, parent.name, parent.filterTargetKey, {});
|
||||
const collection = getCollection(props.collection);
|
||||
const { treeTable } = fieldSchema?.['x-decorator-props'] || {};
|
||||
if (filter) {
|
||||
params.filter = filter;
|
||||
}
|
||||
if (props.dragSort) {
|
||||
params['sort'] = ['sort'];
|
||||
}
|
||||
@ -255,28 +250,3 @@ export const useTableBlockProps = () => {
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const generateFilterParams = (record, parentName, filterTargetKey, defaultFilter) => {
|
||||
let filter = defaultFilter;
|
||||
|
||||
if (parentName) {
|
||||
const filterByTk = `${record?.[filterTargetKey || 'id']}`;
|
||||
if (filter) {
|
||||
filter = {
|
||||
$and: [
|
||||
filter,
|
||||
{
|
||||
collectionName: parentName,
|
||||
recordId: filterByTk,
|
||||
},
|
||||
],
|
||||
};
|
||||
} else {
|
||||
filter = {
|
||||
collectionName: parentName,
|
||||
recordId: filterByTk,
|
||||
};
|
||||
}
|
||||
}
|
||||
return filter;
|
||||
};
|
||||
|
@ -13,8 +13,6 @@ import { useCompile, useDesignable } from '../../hooks';
|
||||
import { removeNullCondition } from '../filter';
|
||||
import { FixedBlockDesignerItem } from '../page';
|
||||
import { FilterDynamicComponent } from './FilterDynamicComponent';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import isEmpty from 'lodash/isEmpty';
|
||||
|
||||
export const TableBlockDesigner = () => {
|
||||
const { name, title, sortable } = useCollection();
|
||||
@ -27,9 +25,7 @@ export const TableBlockDesigner = () => {
|
||||
const { t } = useTranslation();
|
||||
const { dn } = useDesignable();
|
||||
const compile = useCompile();
|
||||
const defaultFilter = removeNullCondition(fieldSchema?.['x-decorator-props']?.params?.filter || {});
|
||||
// 当前filter 不需要在 "设置数据范围" 表单里初始化,只需要在查询的时候合并到查询条件 filter中
|
||||
const crypticFilter = fieldSchema?.['x-decorator-props']?.params?.crypticFilter;
|
||||
const defaultFilter = fieldSchema?.['x-decorator-props']?.params?.filter || {};
|
||||
const defaultSort = fieldSchema?.['x-decorator-props']?.params?.sort || [];
|
||||
const defaultResource = fieldSchema?.['x-decorator-props']?.resource;
|
||||
const supportTemplate = !fieldSchema?.['x-decorator-props']?.disableTemplate;
|
||||
@ -71,16 +67,12 @@ export const TableBlockDesigner = () => {
|
||||
({ filter }) => {
|
||||
filter = removeNullCondition(filter);
|
||||
const params = field.decoratorProps.params || {};
|
||||
let tempFilter = !isEmpty(crypticFilter) ? crypticFilter : filter;
|
||||
if (!isEmpty(filter)) {
|
||||
tempFilter = !isEmpty(crypticFilter) ? mergeFilter([filter, tempFilter]) : cloneDeep(filter);
|
||||
}
|
||||
params.filter = filter;
|
||||
field.decoratorProps.params = params;
|
||||
fieldSchema['x-decorator-props']['params'] = params;
|
||||
const filters = service.params?.[1]?.filters || {};
|
||||
service.run(
|
||||
{ ...service.params?.[0], filter: mergeFilter([...Object.values(filters), tempFilter]), page: 1 },
|
||||
{ ...service.params?.[0], filter: mergeFilter([...Object.values(filters), filter]), page: 1 },
|
||||
{ filters },
|
||||
);
|
||||
dn.emit('patch', {
|
||||
@ -90,7 +82,7 @@ export const TableBlockDesigner = () => {
|
||||
},
|
||||
});
|
||||
},
|
||||
[field, crypticFilter],
|
||||
[field],
|
||||
);
|
||||
|
||||
return (
|
||||
|
@ -1323,8 +1323,6 @@ export const createTableBlockSchema = (options) => {
|
||||
TableBlockDesigner,
|
||||
blockType,
|
||||
pageSize = 20,
|
||||
// 当前filter 不需要在 "设置数据范围" 表单里初始化,只需要在查询的时候合并到查询条件 filter中
|
||||
crypticFilter = {},
|
||||
...others
|
||||
} = options;
|
||||
const schema: ISchema = {
|
||||
@ -1337,7 +1335,6 @@ export const createTableBlockSchema = (options) => {
|
||||
action: 'list',
|
||||
params: {
|
||||
pageSize,
|
||||
crypticFilter,
|
||||
},
|
||||
rowKey,
|
||||
showIndex: true,
|
||||
|
@ -1,30 +1,13 @@
|
||||
import { TableOutlined } from '@ant-design/icons';
|
||||
import { ISchema, useFieldSchema } from '@formily/react';
|
||||
import {
|
||||
createTableBlockSchema,
|
||||
generateFilterParams,
|
||||
SchemaInitializer,
|
||||
useCollection,
|
||||
useRecord,
|
||||
} from '@nocobase/client';
|
||||
import { ISchema } from '@formily/react';
|
||||
import { createTableBlockSchema, SchemaInitializer } from '@nocobase/client';
|
||||
import React from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { getResourceOfBlockDesigner } from './utils';
|
||||
|
||||
export const AuditLogsBlockInitializer = (props) => {
|
||||
const { filterTargetKey } = useCollection();
|
||||
|
||||
const { insert } = props;
|
||||
const { t } = useTranslation();
|
||||
const record = useRecord();
|
||||
const fieldSchema = useFieldSchema();
|
||||
|
||||
const crypticFilterFromAuditLogs = generateFilterParams(
|
||||
record,
|
||||
getResourceOfBlockDesigner(fieldSchema),
|
||||
filterTargetKey,
|
||||
{},
|
||||
);
|
||||
const schema = createTableBlockSchema({
|
||||
collection: 'auditLogs',
|
||||
rowKey: 'id',
|
||||
@ -33,8 +16,6 @@ export const AuditLogsBlockInitializer = (props) => {
|
||||
tableActionColumnInitializers: 'AuditLogsTableActionColumnInitializers',
|
||||
tableBlockProvider: 'AuditLogsBlockProvider',
|
||||
disableTemplate: true,
|
||||
// 当前filter 不需要在 "设置数据范围" 表单里初始化,只需要在查询的时候合并到查询条件 filter中
|
||||
crypticFilter: crypticFilterFromAuditLogs,
|
||||
});
|
||||
|
||||
return (
|
||||
|
@ -4,7 +4,6 @@ import {
|
||||
CollectionManagerContext,
|
||||
CollectionManagerProvider,
|
||||
FormProvider,
|
||||
generateFilterParams,
|
||||
SchemaComponent,
|
||||
TableBlockProvider,
|
||||
useCollection,
|
||||
@ -459,35 +458,55 @@ export const AuditLogs: any = () => {
|
||||
);
|
||||
};
|
||||
|
||||
AuditLogs.Decorator = observer((props: any) => {
|
||||
const parent = useCollection();
|
||||
const record = useRecord();
|
||||
const { interfaces } = useContext(CollectionManagerContext);
|
||||
const filter = generateFilterParams(record, parent.name, parent.filterTargetKey, props?.params?.filter) || {};
|
||||
const defaults = {
|
||||
collection: 'auditLogs',
|
||||
resource: 'auditLogs',
|
||||
action: 'list',
|
||||
params: {
|
||||
pageSize: 20,
|
||||
appends: ['collection', 'user'],
|
||||
...props.params,
|
||||
filter,
|
||||
sort: '-createdAt',
|
||||
},
|
||||
rowKey: 'id',
|
||||
showIndex: true,
|
||||
dragSort: false,
|
||||
};
|
||||
return (
|
||||
<IsAssociationBlock.Provider value={!!parent.name}>
|
||||
<CollectionManagerProvider collections={[collection]} interfaces={interfaces}>
|
||||
<TableBlockProvider {...defaults}>{props.children}</TableBlockProvider>
|
||||
</CollectionManagerProvider>
|
||||
</IsAssociationBlock.Provider>
|
||||
);
|
||||
}, {
|
||||
displayName: 'AuditLogs.Decorator'
|
||||
});
|
||||
AuditLogs.Decorator = observer(
|
||||
(props: any) => {
|
||||
const parent = useCollection();
|
||||
const record = useRecord();
|
||||
const { interfaces } = useContext(CollectionManagerContext);
|
||||
let filter = props?.params?.filter;
|
||||
if (parent.name) {
|
||||
const filterByTk = record?.[parent.filterTargetKey || 'id'];
|
||||
if (filter) {
|
||||
filter = {
|
||||
$and: [
|
||||
filter,
|
||||
{
|
||||
collectionName: parent.name,
|
||||
recordId: `${filterByTk}`,
|
||||
},
|
||||
],
|
||||
};
|
||||
} else {
|
||||
filter = {
|
||||
collectionName: parent.name,
|
||||
recordId: `${filterByTk}`,
|
||||
};
|
||||
}
|
||||
}
|
||||
const defaults = {
|
||||
collection: 'auditLogs',
|
||||
resource: 'auditLogs',
|
||||
action: 'list',
|
||||
params: {
|
||||
pageSize: 20,
|
||||
appends: ['collection', 'user'],
|
||||
...props.params,
|
||||
filter,
|
||||
sort: '-createdAt',
|
||||
},
|
||||
rowKey: 'id',
|
||||
showIndex: true,
|
||||
dragSort: false,
|
||||
};
|
||||
return (
|
||||
<IsAssociationBlock.Provider value={!!parent.name}>
|
||||
<CollectionManagerProvider collections={[collection]} interfaces={interfaces}>
|
||||
<TableBlockProvider {...defaults}>{props.children}</TableBlockProvider>
|
||||
</CollectionManagerProvider>
|
||||
</IsAssociationBlock.Provider>
|
||||
);
|
||||
},
|
||||
{ displayName: 'AuditLogs.Decorator' },
|
||||
);
|
||||
|
||||
AuditLogs.Designer = AuditLogsDesigner;
|
||||
|
@ -1,6 +1,4 @@
|
||||
import { uid } from '@formily/shared';
|
||||
import { Schema } from '@formily/react';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
export const createSchema = () => {
|
||||
const filterSchema = {
|
||||
@ -303,18 +301,3 @@ export const createSchema = () => {
|
||||
};
|
||||
return schema;
|
||||
};
|
||||
|
||||
/**
|
||||
* 获取 TableBlockDesigner 或 DetailsDesigner 的 resource
|
||||
*/
|
||||
export function getResourceOfBlockDesigner(schema: Schema) {
|
||||
let tempSchema = cloneDeep(schema);
|
||||
while (
|
||||
tempSchema &&
|
||||
((tempSchema?.['x-designer'] !== 'TableBlockDesigner' && tempSchema?.['x-designer'] !== 'DetailsDesigner') ||
|
||||
tempSchema?.['x-decorator-props']?.['resource'] === 'auditLogs')
|
||||
) {
|
||||
tempSchema = tempSchema.parent;
|
||||
}
|
||||
return tempSchema?.['x-decorator-props']?.['resource'];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user