Skip to content

Commit 1c269db

Browse files
committed
Issue: [BUG] Filtering on field with multiple values does not work as expected #895
1 parent 1ed5131 commit 1c269db

File tree

4 files changed

+31
-4
lines changed

4 files changed

+31
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
### 🐞 Fixes
1414

15+
- [#895](https://github.com/estruyf/vscode-front-matter/issues/895): Fix issue with array values in filters
16+
1517
## [10.6.0] - 2024-11-06 - [Release notes](https://beta.frontmatter.codes/updates/v10.6.0)
1618

1719
### 🎨 Enhancements

src/dashboardWebView/components/Header/Filters.tsx

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,35 @@ export const Filters: React.FunctionComponent<IFiltersProps> = () => {
2424
return otherFilters?.map((filter) => {
2525
const filterName = typeof filter === "string" ? filter : filter.name;
2626
const filterTitle = typeof filter === "string" ? firstToUpper(filter) : filter.title;
27-
const values = filterValues?.[filterName];
27+
let values = filterValues?.[filterName];
2828
if (!values || values.length === 0) {
2929
return null;
3030
}
3131

32+
// Get all the unique values
33+
const individualValues = new Set<string>();
34+
values.forEach((value) => {
35+
if (value.length === 0) {
36+
return;
37+
}
38+
39+
if (Array.isArray(value)) {
40+
value.forEach((v) => individualValues.add(v));
41+
}
42+
43+
if (typeof value === "string") {
44+
individualValues.add(value);
45+
}
46+
});
47+
48+
values = Array.from(individualValues);
49+
3250
return (
3351
<Filter
3452
key={filterName}
3553
label={filterTitle}
3654
activeItem={crntFilters[filterName]}
37-
items={values}
55+
items={values as string[]}
3856
onClick={(value) => setCrntFilters((prev) => {
3957
const clone = Object.assign({}, prev);
4058
if (!clone[filterName] && value) {

src/dashboardWebView/hooks/usePages.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,14 @@ export default function usePages(pages: Page[]) {
107107
for (const filter of filterNames) {
108108
const filterValue = filters[filter];
109109
if (filterValue) {
110-
pagesSorted = pagesSorted.filter((page) => page[filter] === filterValue);
110+
pagesSorted = pagesSorted.filter((page) => {
111+
const value = page[filter];
112+
if (Array.isArray(value)) {
113+
return value.includes(filterValue);
114+
} else {
115+
return value === filterValue;
116+
}
117+
});
111118
}
112119
}
113120
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { atom } from 'recoil';
22

3-
export const FilterValuesAtom = atom<{ [filter: string]: string[] }>({
3+
export const FilterValuesAtom = atom<{ [filter: string]: string[] | string[][] }>({
44
key: 'FilterValuesAtom',
55
default: {}
66
});

0 commit comments

Comments
 (0)