Skip to content

Commit bf27fe1

Browse files
committed
support filters
1 parent 028929c commit bf27fe1

File tree

4 files changed

+20
-15
lines changed

4 files changed

+20
-15
lines changed

packages/components/package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/components/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@labkey/components",
3-
"version": "7.13.0-fb-mvtc.6",
3+
"version": "7.13.0-fb-mvtc.11",
44
"description": "Components, models, actions, and utility functions for LabKey applications and pages",
55
"sideEffects": false,
66
"files": [
@@ -50,7 +50,7 @@
5050
"homepage": "https://github.com/LabKey/labkey-ui-components#readme",
5151
"dependencies": {
5252
"@hello-pangea/dnd": "18.0.1",
53-
"@labkey/api": "1.45.0-fb-mvtc.2",
53+
"@labkey/api": "1.45.0-fb-mvtc.4",
5454
"@testing-library/dom": "~10.4.1",
5555
"@testing-library/jest-dom": "~6.9.1",
5656
"@testing-library/react": "~16.3.0",

packages/components/src/internal/components/search/FilterFacetedSelector.tsx

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,12 @@ export const FilterFacetedSelector: FC<Props> = memo(props => {
215215
fieldKey,
216216
value,
217217
checked,
218-
fieldFilters?.[0], // choose values applies only to the first filter
218+
fieldFilters?.[0] ?? (multiChoices ? Filter.create(fieldKey, [], Filter.Types.ARRAY_CONTAINS_ALL) : null), // choose values applies only to the first filter
219219
uncheckOthers
220220
);
221221
onFieldFilterUpdate([newFilter], 0);
222222
},
223-
[disabled, allShown, fieldDistinctValues, fieldKey, fieldFilters, onFieldFilterUpdate]
223+
[disabled, allShown, fieldDistinctValues, fieldKey, fieldFilters, onFieldFilterUpdate, multiChoices]
224224
);
225225

226226
const filteredFieldDistinctValues = useMemo(() => {
@@ -250,12 +250,15 @@ export const FilterFacetedSelector: FC<Props> = memo(props => {
250250
if (!newActiveFilterType) return newFilters;
251251

252252
const filterType = resolveFilterType(newActiveFilterType?.value, field);
253+
let updatedFilterValues = fieldFilters[0]?.getValue();
254+
if (updatedFilterValues && multiChoices && !filterType.isMultiValued())
255+
updatedFilterValues = null;
253256

254-
newFilters = [Filter.create(fieldKey, fieldFilters[0]?.getValue(), filterType), null];
257+
newFilters = [Filter.create(fieldKey, updatedFilterValues, filterType), null];
255258

256259
onFieldFilterUpdate(newFilters, 0);
257260
},
258-
[onFieldFilterUpdate, filterOptions, field, fieldFilters, fieldKey]
261+
[onFieldFilterUpdate, filterOptions, field, fieldFilters, fieldKey, multiChoices]
259262
);
260263

261264
if (!fieldDistinctValues || allShown === undefined) return <LoadingSpinner />;
@@ -275,7 +278,7 @@ export const FilterFacetedSelector: FC<Props> = memo(props => {
275278
options={filterOptions}
276279
placeholder="Select a filter type..."
277280
required={true}
278-
value={fieldFilters?.[0]?.getFilterType()?.getURLSuffix() || ''}
281+
value={fieldFilters?.[0]?.getFilterType()?.getURLSuffix() || 'arraycontainsall'}
279282
/>
280283
}
281284
{(fieldDistinctValues?.length > showSearchLength || searchStr) && (

packages/components/src/internal/components/search/utils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,12 @@ export function getUpdateFilterExpressionFilter(
294294

295295
// this util is only for string field type
296296
export function getCheckedFilterValues(filter: Filter.IFilter, allValues: string[], multiChoices?: string[]): string[] {
297-
if (!filter && !allValues) return [];
297+
if (!filter && (!allValues || multiChoices?.length > 0)) return [];
298298

299299
if (filter?.getFilterType().getURLSuffix().indexOf('array') === 0) {
300-
return filter.getValue() ?? [];
300+
const checked = filter.getValue() ?? [];
301+
if (checked.length === multiChoices?.length) return allValues;
302+
return checked;
301303
}
302304

303305
const filterUrlSuffix = filter?.getFilterType()?.getURLSuffix();

0 commit comments

Comments
 (0)