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

View File

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