Skip to content
This repository was archived by the owner on Jul 28, 2025. It is now read-only.

Commit f8982cf

Browse files
committed
tags filter
1 parent 04ca0d0 commit f8982cf

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

docs/docs/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Number range filter
88
- Text filter with unique values suggestions
99
- Tasks filter
10+
1011
## 2.8.4
1112
### Shiny new things
1213
- New rollup. All task count [ISSUE#602](https://github.com/RafaelGB/obsidian-db-folder/issues/602)

src/components/DefaultHeader.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
8787
break;
8888
case InputType.TAGS:
8989
propertyIcon = <TagsIcon />;
90+
columnSearch = <BaseFilter {...headerProps} />;
9091
break;
9192
case InputType.INLINKS:
9293
propertyIcon = <IncomingLinkIcon />;

src/components/reducers/TableFilterFlavours.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ const BooleanGroupFilterFn: FilterFn<RowDataType> = (row: Row<RowDataType>, colu
115115

116116
}
117117

118+
const TagsGroupFilterFn: FilterFn<RowDataType> = (row: Row<RowDataType>, columnId: string, filterValue: string) => {
119+
const value = row.getValue<Literal>(columnId);
120+
const wrapLiteral = DataviewService.wrapLiteral(value);
121+
if (filterValue === undefined || filterValue === null) {
122+
return true;
123+
}
124+
125+
if (value === undefined || value === null) {
126+
return false;
127+
}
128+
const sanitizedFilterValue = filterValue.toLowerCase();
129+
if (wrapLiteral.type === "array") {
130+
return wrapLiteral.value.some((tag) => {
131+
const sanitizedTag = tag.toString().toLowerCase();
132+
return sanitizedTag.includes(sanitizedFilterValue) || searchRegex(sanitizedTag, sanitizedFilterValue);
133+
});
134+
} else {
135+
const sanitizedTag = wrapLiteral.value.toString().toLowerCase();
136+
return sanitizedTag.includes(sanitizedFilterValue) || searchRegex(sanitizedTag, sanitizedFilterValue);
137+
}
138+
}
139+
118140
const TaskGroupFilterFn: FilterFn<RowDataType> = (row: Row<RowDataType>, columnId: string, selectedOption: string) => {
119141
const value = row.getValue<Literal>(columnId) as STask[];
120142
if (selectedOption === undefined || selectedOption === null) {
@@ -126,16 +148,15 @@ const TaskGroupFilterFn: FilterFn<RowDataType> = (row: Row<RowDataType>, columnI
126148
const sanitized = task.text.toLowerCase();
127149
return sanitized.includes(sanitizedSelectedOption) || searchRegex(sanitized, sanitizedSelectedOption);
128150
});
129-
130-
131151
}
132152

133153
const customSortingfns: FilterFns = {
134154
markdown: MarkdownFilterFn,
135155
linksGroup: LinksGroupFilterFn,
136156
calendar: CalendarGroupFilterFn,
137157
boolean: BooleanGroupFilterFn,
138-
task: TaskGroupFilterFn
158+
task: TaskGroupFilterFn,
159+
tags: TagsGroupFilterFn,
139160
};
140161

141162
export default customSortingfns;

src/helpers/TableFiltersHelper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export function getFilterKeyInFunctionOfInputType(inputType: string): string {
111111
case InputType.CHECKBOX:
112112
filterKey = 'boolean';
113113
break;
114+
case InputType.TAGS:
115+
filterKey = 'tags';
116+
break;
114117
case InputType.TASK:
115118
filterKey = 'task';
116119
break;

0 commit comments

Comments
 (0)