fix: action log filtering of a record

This commit is contained in:
chenos 2021-08-23 23:30:48 +08:00
parent 44633db5ff
commit 73c52b7ea4
3 changed files with 31 additions and 7 deletions

View File

@ -156,13 +156,13 @@ export class Resource {
static make(options: null | string | Resource | ResourceOptions): Resource | null { static make(options: null | string | Resource | ResourceOptions): Resource | null {
if (typeof options === 'string') { if (typeof options === 'string') {
return new Resource({ resourceName: options }); return new this({ resourceName: options });
} }
if (options instanceof Resource) { if (options instanceof Resource) {
return options; return options;
} }
if (typeof options === 'object' && options.resourceName) { if (typeof options === 'object' && options.resourceName) {
return new Resource(options); return new this(options);
} }
console.warn('resource 初始化参数错误'); console.warn('resource 初始化参数错误');
return null; return null;

View File

@ -697,7 +697,7 @@ function generateCardItemSchema(component) {
}, },
column3: { column3: {
type: 'void', type: 'void',
title: '选择数据源', title: '数据表',
'x-component': 'Table.Column', 'x-component': 'Table.Column',
properties: { properties: {
'collection.title': { 'collection.title': {
@ -782,7 +782,7 @@ function generateCardItemSchema(component) {
}, },
'collection.title': { 'collection.title': {
type: 'string', type: 'string',
title: '选择数据源', title: '数据表',
'x-decorator': 'FormItem', 'x-decorator': 'FormItem',
'x-component': 'Input', 'x-component': 'Input',
'x-read-pretty': true, 'x-read-pretty': true,

View File

@ -44,7 +44,7 @@ import { interfaces, options } from '../database-field/interfaces';
import { DraggableBlockContext } from '../../components/drag-and-drop'; import { DraggableBlockContext } from '../../components/drag-and-drop';
import AddNew from '../add-new'; import AddNew from '../add-new';
import { isGridRowOrCol } from '../grid'; import { isGridRowOrCol } from '../grid';
import { Resource } from '../../resource'; import { ListOptions, Resource } from '../../resource';
import { import {
CollectionProvider, CollectionProvider,
DisplayedMapProvider, DisplayedMapProvider,
@ -432,7 +432,7 @@ function AddColumn() {
const { appendChild, remove } = useDesignable(); const { appendChild, remove } = useDesignable();
const { collection, fields, refresh } = useCollectionContext(); const { collection, fields, refresh } = useCollectionContext();
const displayed = useDisplayedMapContext(); const displayed = useDisplayedMapContext();
// const { service } = useTable();
return ( return (
<Dropdown <Dropdown
trigger={['click']} trigger={['click']}
@ -463,6 +463,7 @@ function AddColumn() {
await removeSchema(removed); await removeSchema(removed);
displayed.remove(field.name); displayed.remove(field.name);
} }
// service.refresh();
}} }}
/> />
))} ))}
@ -2317,7 +2318,30 @@ Table.useActionLogDetailsResource = ({ onSuccess }) => {
}; };
const useActionLogsResource = (options: any = {}) => { const useActionLogsResource = (options: any = {}) => {
const resource = Resource.make('action_logs'); const { props } = useTable();
const ctx = useContext(TableRowContext);
class ActionLogoResource extends Resource {
list(options?: ListOptions) {
console.log({ options });
let defaultFilter = options?.defaultFilter;
if (ctx?.record) {
const extra = {
index: ctx?.record?.id,
collection_name: props.collectionName,
};
if (defaultFilter) {
defaultFilter = { and: [defaultFilter, extra] };
} else {
defaultFilter = extra;
}
}
return super.list({ ...options, defaultFilter });
}
}
const resource = ActionLogoResource.make('action_logs');
return { return {
resource, resource,
}; };