Skip to content

Commit

Permalink
fix: 修复crud2搜索关闭时搜索面板依旧存在问题
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangtao07 committed Jan 24, 2024
1 parent 07aa055 commit cbed0e4
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {
CRUDScaffoldConfig
} from '../../builder';
import type {EditorNodeType} from 'amis-editor-core';
import type {FormControlProps} from 'amis';
import type {FormControlProps, PlainObject} from 'amis';

interface Option {
label: string;
Expand Down Expand Up @@ -235,6 +235,12 @@ export class CRUDFiltersControl extends React.Component<
this.setState({loading: false});
}

setFilterVisible(schema: PlainObject) {
if (!('visibleOn' in schema) && schema.type) {
schema.visible = schema.body?.length > 0;
}
}

async updateSimpleQuery(enable: boolean) {
const {manager, nodeId, builder} = this.props;
const store = manager.store;
Expand Down Expand Up @@ -269,7 +275,7 @@ export class CRUDFiltersControl extends React.Component<
}
})) ?? [];

const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
Expand All @@ -292,14 +298,15 @@ export class CRUDFiltersControl extends React.Component<
return [key, value];
}
);
this.setFilterVisible(newFilterSchema);

const targetNode = manager.store.getNodeById(filterSchema.$$id);

if (targetNode) {
targetNode.updateSchema(newFilterSchema);
}
} else {
const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
Expand Down Expand Up @@ -330,6 +337,7 @@ export class CRUDFiltersControl extends React.Component<
}
);

this.setFilterVisible(newFilterSchema);
const targetNode = manager.store.getNodeById(filterSchema.$$id);

if (targetNode) {
Expand Down Expand Up @@ -402,7 +410,7 @@ export class CRUDFiltersControl extends React.Component<
}
});

const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
Expand All @@ -425,14 +433,15 @@ export class CRUDFiltersControl extends React.Component<
return [key, value];
}
);
this.setFilterVisible(newFilterSchema);

const targetNode = manager.store.getNodeById(filterSchema.$$id);

if (targetNode) {
targetNode.updateSchema(newFilterSchema);
}
} else {
const newFilterSchema = traverseSchemaDeep(
let newFilterSchema = traverseSchemaDeep(
filterSchema,
(key: string, value: any, host: any) => {
/** 更新标识符 */
Expand Down Expand Up @@ -464,6 +473,7 @@ export class CRUDFiltersControl extends React.Component<
return [key, value];
}
);
this.setFilterVisible(newFilterSchema);

const targetNode = manager.store.getNodeById(filterSchema.$$id);

Expand Down

0 comments on commit cbed0e4

Please sign in to comment.