fix empty rule state in query builder (#18481)

This commit is contained in:
Karan Hotchandani 2024-10-31 09:01:26 +05:30 committed by GitHub
parent 854c3d6cca
commit 5c3ad966a1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 9 deletions

View File

@ -103,7 +103,7 @@ const QueryBuilderWidget: FC<WidgetProps> = ({
onTreeUpdate(nTree, nConfig);
if (outputType === QueryBuilderOutputType.ELASTICSEARCH) {
const data = elasticSearchFormat(nTree, config) ?? {};
const data = elasticSearchFormat(nTree, config) ?? '';
const qFilter = {
query: data,
};
@ -111,7 +111,7 @@ const QueryBuilderWidget: FC<WidgetProps> = ({
debouncedFetchEntityCount(qFilter);
}
onChange(JSON.stringify(qFilter));
onChange(!isEmpty(data) ? JSON.stringify(qFilter) : '');
} else {
const data = QbUtils.jsonLogicFormat(nTree, config);
onChange(JSON.stringify(data.logic ?? '{}'));
@ -125,13 +125,14 @@ const QueryBuilderWidget: FC<WidgetProps> = ({
useEffect(() => {
if (!isEmpty(value)) {
if (outputType === QueryBuilderOutputType.ELASTICSEARCH) {
const tree = QbUtils.checkTree(
QbUtils.loadTree(
getJsonTreeFromQueryFilter(JSON.parse(value || '')) as JsonTree
),
config
);
onTreeUpdate(tree, config);
const parsedTree = getJsonTreeFromQueryFilter(
JSON.parse(value || '')
) as JsonTree;
if (Object.keys(parsedTree).length > 0) {
const tree = QbUtils.checkTree(QbUtils.loadTree(parsedTree), config);
onTreeUpdate(tree, config);
}
} else {
const tree = QbUtils.loadFromJsonLogic(JSON.parse(value || ''), config);
if (tree) {

View File

@ -176,4 +176,8 @@
}
}
}
.rule-container:first-child .action--DELETE {
display: none;
}
}