Skip to content

Commit 09311a2

Browse files
authored
Fix custom expression filter cannot show (opensearch-project#178)
* Fix custom expression filter cannot show This PR fixes that a new detector with custom filter created using API cannot show. Testing done: 1. Created a detector with a custom filter and verified the change fixed the issue. Signed-off-by: Kaituo Li <kaituo@amazon.com>
1 parent 20727b1 commit 09311a2

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

public/pages/ReviewAndCreate/components/FilterDisplayList/FilterDisplayList.tsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ export const FilterDisplayList = (props: FilterDisplayListProps) => {
2626
const [filterIndex, setFilterIndex] = useState<number>(-1);
2727
let filters = get(props, 'uiMetadata.filters', []);
2828
const oldFilterType = get(props, 'uiMetadata.filterType', undefined);
29-
const isOldDetector = !isEmpty(oldFilterType);
3029

31-
// Old detectors with custom filters will have no filter list, but
32-
// will have a populated filter query
33-
if (isEmpty(filters) && isOldDetector && !isEmpty(props.filterQuery)) {
30+
// We want to show the custom filter if filters is empty and
31+
// props.filterQuery isn't empty.
32+
// Two possible situations for the if branch:
33+
// First, old detectors with custom filters will have no filter list, but
34+
// will have a populated filter query.
35+
// Second, the detector has been created from API (no uiMetadata.* fields).
36+
if (isEmpty(filters) && !isEmpty(props.filterQuery)) {
3437
return (
3538
<div>
3639
<EuiText>

public/pages/ReviewAndCreate/containers/__tests__/__snapshots__/ReviewAndCreate.test.tsx.snap

+17-7
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,24 @@ exports[`<ReviewAndCreate /> spec renders the component 1`] = `
202202
<div
203203
class="euiFormRow__fieldWrapper"
204204
>
205-
<div
206-
class="euiText euiText--medium"
207-
>
208-
<p
209-
class="enabled"
205+
<div>
206+
<div
207+
class="euiText euiText--medium"
210208
>
211-
-
212-
</p>
209+
<p
210+
class="enabled"
211+
>
212+
Custom expression:
213+
214+
<button
215+
class="euiLink euiLink--primary"
216+
data-test-subj="viewFilter"
217+
type="button"
218+
>
219+
View code
220+
</button>
221+
</p>
222+
</div>
213223
</div>
214224
</div>
215225
</div>

0 commit comments

Comments
 (0)