Skip to content

Commit

Permalink
fix: use combine operator & and |` (#2938)
Browse files Browse the repository at this point in the history
Resolves #2939

**Changes:**
Updates the filter combination logic in BAIPropertyFilter to:
- Return `undefined` instead of empty string when merging empty filter values
- Change operator types from 'and'/'or' to '&'/'|' to match backend expectations
- Standardize filter combination to use '&' operator consistently
  • Loading branch information
yomybaby committed Dec 11, 2024
1 parent 937ceac commit 8252a10
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions react/src/components/BAIPropertyFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,11 @@ export function mergeFilterValues(
filterStrings: Array<string | undefined>,
operator: string = '&',
) {
return _.join(
const mergedFilter = _.join(
_.map(filterEmptyItem(filterStrings), (str) => `(${str})`),
operator,
);
return !!mergedFilter ? mergedFilter : undefined;
}

/**
Expand Down Expand Up @@ -129,7 +130,7 @@ export function parseFilterValue(filter: string) {
* @param operator - The logical operator to use ('and' or 'or').
* @returns The combined filter string.
*/
function combineFilters(filters: string[], operator: 'and' | 'or'): string {
function combineFilters(filters: string[], operator: '&' | '|'): string {
return filters.join(` ${operator} `);
}

Expand Down Expand Up @@ -194,7 +195,7 @@ const BAIPropertyFilter: React.FC<BAIPropertyFilterProps> = ({
item.type === 'string' ? `"${item.value}"` : item.value;
return `${item.property} ${item.operator} ${valueStringInResult}`;
});
setValue(combineFilters(filterStrings, 'and')); // Change 'and' to 'or' if needed
setValue(combineFilters(filterStrings, '&'));
}
}, [list, setValue]);

Expand Down

0 comments on commit 8252a10

Please sign in to comment.