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

Commit 42d4fe9

Browse files
committed
task filters
1 parent e4db116 commit 42d4fe9

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

src/components/DefaultHeader.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
6060
const [labelState, setLabelState] = useState(label);
6161

6262
let propertyIcon: JSX.Element;
63-
let columnSearch: JSX.Element = null;
63+
let columnSearch = <TextFilter {...headerProps} />;
6464
switch (input) {
6565
case InputType.NUMBER:
6666
propertyIcon = <HashIcon />;
@@ -98,6 +98,7 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
9898
break;
9999
case InputType.TASK:
100100
propertyIcon = <TaskIcon />;
101+
columnSearch = <BaseFilter {...headerProps} />;
101102
break;
102103
case InputType.CHECKBOX:
103104
propertyIcon = <TaskIcon />;
@@ -114,10 +115,7 @@ export default function DefaultHeader(headerProps: DatabaseHeaderProps) {
114115
propertyIcon = <RollupIcon />;
115116
break;
116117
default:
117-
break;
118-
}
119-
if (!columnSearch) {
120-
columnSearch = <TextFilter {...headerProps} />;
118+
// Do nothing
121119
}
122120

123121
function handlerAddColumnToLeft() {

src/components/reducers/TableFilterFlavours.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { FilterFn, FilterFns, Row } from "@tanstack/react-table"
22
import { RowDataType } from "cdm/FolderModel"
33
import { LocalSettings } from "cdm/SettingsModel";
44
import { InputType } from "helpers/Constants";
5-
import { Link, Literal } from "obsidian-dataview";
5+
import { Link, Literal, STask } from "obsidian-dataview";
66
import { DataviewService } from "services/DataviewService";
77
import { LOGGER } from "services/Logger";
88
import { ParseService } from "services/ParseService";
@@ -114,11 +114,28 @@ const BooleanGroupFilterFn: FilterFn<RowDataType> = (row: Row<RowDataType>, colu
114114
return Boolean(value) === Boolean(selectedOption);
115115

116116
}
117+
118+
const TaskGroupFilterFn: FilterFn<RowDataType> = (row: Row<RowDataType>, columnId: string, selectedOption: string) => {
119+
const value = row.getValue<Literal>(columnId) as STask[];
120+
if (selectedOption === undefined || selectedOption === null) {
121+
return true;
122+
}
123+
const sanitizedSelectedOption = selectedOption.toLowerCase();
124+
return value.some((task) => {
125+
// Sanitize the value to obtain the file name
126+
const sanitized = task.text.toLowerCase();
127+
return sanitized.includes(sanitizedSelectedOption) || searchRegex(sanitized, sanitizedSelectedOption);
128+
});
129+
130+
131+
}
132+
117133
const customSortingfns: FilterFns = {
118134
markdown: MarkdownFilterFn,
119135
linksGroup: LinksGroupFilterFn,
120136
calendar: CalendarGroupFilterFn,
121137
boolean: BooleanGroupFilterFn,
138+
task: TaskGroupFilterFn
122139
};
123140

124141
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.TASK:
115+
filterKey = 'task';
116+
break;
114117
default:
115118
filterKey = 'auto';
116119
}

0 commit comments

Comments
 (0)