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

Commit b9062bb

Browse files
committed
Merge branch '536-fr-add-filtersort-options-for-the-tasks-query-results'
2 parents 91f0808 + cdcacb1 commit b9062bb

File tree

7 files changed

+45
-40
lines changed

7 files changed

+45
-40
lines changed

src/components/cellTypes/TaskCell.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { CellComponentProps } from "cdm/ComponentsModel";
22
import { Grouping } from "obsidian-dataview/lib/data-model/value";
3-
import { SListItem } from "obsidian-dataview/lib/data-model/serialized/markdown";
3+
import {
4+
SListItem,
5+
STask,
6+
} from "obsidian-dataview/lib/data-model/serialized/markdown";
47
import { DataviewService } from "services/DataviewService";
58
import React, { useEffect, useRef } from "react";
69
import { TableColumn } from "cdm/FolderModel";
@@ -14,13 +17,14 @@ const TaskCell = (taskProps: CellComponentProps) => {
1417
useEffect(() => {
1518
let taskValue = cell.getValue();
1619
// Check if there are tasks in the cell
17-
if (taskValue !== "") {
20+
if (taskValue) {
1821
taskRef.current.innerHTML = "";
22+
1923
if (
2024
(column.columnDef as TableColumn).config.task_hide_completed &&
21-
typeof (taskValue as any).where === "function"
25+
DataviewService.getDataviewAPI().isDataArray(taskValue)
2226
) {
23-
taskValue = (taskValue as any).where((t: any) => !t.completed);
27+
taskValue = taskValue.where((t: STask) => !t.completed);
2428
}
2529
const taskComponent = new MarkdownRenderChild(taskRef.current);
2630
DataviewService.getDataviewAPI().taskList(

src/components/headerActions/handlers/buttons/SortHandlerAction.tsx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import CrossIcon from "components/img/CrossIcon";
44
import ArrowUpIcon from "components/img/ArrowUp";
55
import ArrowDownIcon from "components/img/ArrowDown";
66
import React from "react";
7-
import { InputType } from "helpers/Constants";
87
import { TableColumn } from "cdm/FolderModel";
98
import headerButtonComponent from "components/headerActions/HeaderButtonComponent";
109
import { t } from "lang/helpers";
@@ -13,17 +12,8 @@ export default class SortHandlerAction extends AbstractHeaderAction {
1312
globalHeaderActionResponse: HeaderActionResponse;
1413
handle(headerActionResponse: HeaderActionResponse): HeaderActionResponse {
1514
this.globalHeaderActionResponse = headerActionResponse;
16-
const column = this.globalHeaderActionResponse.headerMenuProps.headerProps
17-
.column.columnDef as TableColumn;
18-
switch (column.input) {
19-
case InputType.TASK:
20-
case InputType.INLINKS:
21-
case InputType.OUTLINKS:
22-
// DO NOTHING
23-
break;
24-
default:
25-
this.addSortButtons();
26-
}
15+
this.addSortButtons();
16+
2717
return this.goNext(this.globalHeaderActionResponse);
2818
}
2919

src/services/DataviewService.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Notice } from "obsidian";
2-
import { DataviewApi, getAPI, isPluginEnabled } from "obsidian-dataview";
2+
import { DataviewApi, getAPI, isPluginEnabled, STask } from "obsidian-dataview";
33
import { Literal, WrappedLiteral } from "obsidian-dataview/lib/data-model/value";
44
class DataviewProxy {
55

@@ -30,6 +30,15 @@ class DataviewProxy {
3030
return isPluginEnabled(app);
3131
}
3232

33+
34+
isStasks(value: Literal): value is STask {
35+
return (value as STask).task;
36+
}
37+
38+
isSTaskArray(value: Literal): value is STask[] {
39+
return (value as STask[]).every(v => this.isStasks(v));
40+
}
41+
3342
/**
3443
* Singleton instance
3544
* @returns {VaultManager}

src/services/parseServiceHelpers/SelectParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SelectParser extends TypeParser<string> {
5252
.parse(DataviewService.wrapLiteral(curr))
5353
.toString()
5454
);
55-
});
55+
}, "");
5656
return `[${stringArray}]`;
5757
}
5858
}

src/services/parseServiceHelpers/SortingParser.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,46 +27,51 @@ class SortingParser extends TypeParser<Literal> {
2727
}
2828

2929
private parseToPlainText(wrapped: WrappedLiteral) {
30-
let plainText: string;
3130
switch (wrapped.type) {
3231
case 'boolean':
3332
case 'number':
34-
plainText = wrapped.value.toString();
35-
break;
33+
return wrapped.value.toString();
3634
case 'array':
37-
plainText = wrapped.value
35+
if (DataviewService.isSTaskArray(wrapped.value)) {
36+
return wrapped.value.reduce((acc, curr) => {
37+
if (!curr.completed) {
38+
acc += 1;
39+
}
40+
return acc
41+
}, 0);
42+
}
43+
return wrapped.value
3844
.map(
3945
v => this.parse(
4046
DataviewService.wrapLiteral(v),
4147
)
4248
).join(', ');
43-
break;
4449
case 'link':
45-
plainText = wrapped.value.markdown();
46-
break;
50+
return wrapped.value.markdown();
4751
case 'date':
4852
if (wrapped.value.hour === 0 && wrapped.value.minute === 0 && wrapped.value.second === 0) {
4953
// Parse date
50-
51-
plainText = parseLuxonDatetimeToString(wrapped.value, this.config.date_format);
54+
return parseLuxonDatetimeToString(wrapped.value, this.config.date_format);
5255
} else {
5356
// Parse datetime
54-
plainText = parseLuxonDateToString(wrapped.value, this.config.datetime_format);
57+
return parseLuxonDateToString(wrapped.value, this.config.datetime_format);
5558
}
56-
break;
5759
case 'object':
5860
if (DateTime.isDateTime(wrapped.value)) {
59-
plainText = this.parse({ type: 'date', value: wrapped.value });
60-
} else {
61-
plainText = JSON.stringify(wrapped.value);
61+
return this.parse({ type: 'date', value: wrapped.value });
6262
}
63-
break;
63+
64+
if (DataviewService.isStasks(wrapped.value)) {
65+
return wrapped.value.completed ? '0' : '1';
66+
}
67+
68+
return JSON.stringify(wrapped.value);
6469
default:
65-
plainText = wrapped.value?.toString().trim();
70+
return wrapped.value?.toString().trim();
6671
}
67-
68-
return plainText;
6972
}
73+
74+
7075
}
7176

7277
export default SortingParser;

src/services/parseServiceHelpers/StringifyReplacer.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import { LocalSettings } from "cdm/SettingsModel";
2-
import { InputType } from "helpers/Constants";
31
import { Literal } from "obsidian-dataview";
42
import { DataviewService } from "services/DataviewService";
5-
import { ParseService } from "services/ParseService";
63

74
/**
85
* Custom replacer for JSON.stringify to handle DB Folder types

src/services/parseServiceHelpers/TextParser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class TextParser extends TypeParser<string | DataObject> {
5454
.parse(DataviewService.wrapLiteral(curr))
5555
.toString()
5656
);
57-
});
57+
}, "");
5858
return `[${stringArray}]`;
5959
}
6060
}

0 commit comments

Comments
 (0)