Skip to content

Commit cef0dfd

Browse files
committed
refactor: Add the 'group by' field name to GroupDisplayHeading
See #1867. This should enable styling to be done, depending on the type of group in each group heading. I called it 'property' for consistency with the same information elsewhere in the grouping code, even though this is a hangover from an earlier implementation, and 'fieldName' is probably a more accurate name.
1 parent 50fc40b commit cef0dfd

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

src/Query/GroupDisplayHeading.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,22 @@ export class GroupDisplayHeading {
2121
*/
2222
public readonly displayName: string;
2323

24+
/**
25+
* The property, or field name, in the 'group by' line that generated this heading.
26+
* For example, 'starts', 'status.type', or 'priority'.
27+
*/
28+
public readonly property: string;
29+
2430
/**
2531
* Construct a {@link GroupDisplayHeading} object
2632
* @param {number} nestingLevel - See {@link nestingLevel} for details
2733
* @param {string} displayName - The text to be displayed for the group
34+
* @param {string} property - The name, usually field name, in the 'group by' instruction,
35+
* for example 'due' or 'priority'. This may be useful in styling the group headings.
2836
*/
29-
constructor(nestingLevel: number, displayName: string) {
37+
constructor(nestingLevel: number, displayName: string, property: string) {
3038
this.nestingLevel = nestingLevel;
3139
this.displayName = displayName;
40+
this.property = property;
3241
}
3342
}

src/Query/GroupDisplayHeadingSelector.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { GroupDisplayHeading } from './GroupDisplayHeading';
22
import type { TaskGroupingTreeStorage } from './TaskGroupingTree';
3+
import type { Grouper } from './Grouper';
34

45
/*
56
* This file contains implementation details of Group.ts
@@ -84,8 +85,10 @@ import type { TaskGroupingTreeStorage } from './TaskGroupingTree';
8485
*/
8586
export class GroupDisplayHeadingSelector {
8687
private lastHeadingAtLevel = new Array<string>();
88+
private groupers: Grouper[];
8789

88-
constructor(taskGroupingTreeStorage: TaskGroupingTreeStorage) {
90+
constructor(taskGroupingTreeStorage: TaskGroupingTreeStorage, groupers: Grouper[]) {
91+
this.groupers = groupers;
8992
const firstGroup = taskGroupingTreeStorage.keys().next().value;
9093
const groupCount = firstGroup.length;
9194
for (let i = 0; i < groupCount; i++) {
@@ -106,7 +109,7 @@ export class GroupDisplayHeadingSelector {
106109
for (let level = 0; level < groupNames.length; level++) {
107110
const group = groupNames[level];
108111
if (group != this.lastHeadingAtLevel[level]) {
109-
headingsForGroup.push(new GroupDisplayHeading(level, group));
112+
headingsForGroup.push(new GroupDisplayHeading(level, group, this.groupers[level].property));
110113
// Reset all the lower heading levels to un-seen
111114
for (let j = level; j < groupNames.length; j++) {
112115
this.lastHeadingAtLevel[j] = '';

src/Query/TaskGroup.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export class TaskGroup {
9696
// These headings mimic the behaviour of QueryRenderer,
9797
// which uses 'h4', 'h5' and 'h6' for nested groups.
9898
const headingPrefix = '#'.repeat(4 + heading.nestingLevel);
99-
output += `${headingPrefix} ${heading.displayName}\n`;
99+
output += `${headingPrefix} [${heading.property}] ${heading.displayName}\n`;
100100
}
101101

102102
output += this.tasksAsStringOfLines();

src/Query/TaskGroups.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export class TaskGroups {
9595
this.sortTaskGroups();
9696

9797
// Get the headings, now that the groups have been sorted.
98-
const displayHeadingSelector = new GroupDisplayHeadingSelector(taskGroupingTree.groups);
98+
const displayHeadingSelector = new GroupDisplayHeadingSelector(taskGroupingTree.groups, this._groupers);
9999
for (const group of this._groups) {
100100
group.setGroupHeadings(displayHeadingSelector.getHeadingsForTaskGroup(group.groups));
101101
}

tests/Query/Filter/TagsField.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,13 @@ describe('grouping by tag', () => {
663663
- tags reverse
664664
665665
Group names: [#tag2]
666-
#### #tag2
666+
#### [tags] #tag2
667667
- [ ] b #tag2
668668
669669
---
670670
671671
Group names: [#tag1]
672-
#### #tag1
672+
#### [tags] #tag1
673673
- [ ] a #tag1
674674
675675
---

tests/TaskGroups.test.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ describe('Grouping tasks', () => {
3535
- path
3636
3737
Group names: [file1]
38-
#### file1
38+
#### [path] file1
3939
- [ ] b
4040
- [ ] c
4141
4242
---
4343
4444
Group names: [file2]
45-
#### file2
45+
#### [path] file2
4646
- [ ] a
4747
4848
---
@@ -116,19 +116,19 @@ describe('Grouping tasks', () => {
116116
- path
117117
118118
Group names: [a/b/c]
119-
#### a/b/c
119+
#### [path] a/b/c
120120
- [ ] first file path, alphabetically
121121
122122
---
123123
124124
Group names: [b/c/d]
125-
#### b/c/d
125+
#### [path] b/c/d
126126
- [ ] second file path
127127
128128
---
129129
130130
Group names: [d/e/f]
131-
#### d/e/f
131+
#### [path] d/e/f
132132
- [ ] third file path
133133
134134
---
@@ -156,13 +156,13 @@ describe('Grouping tasks', () => {
156156
- filename
157157
158158
Group names: [[[9 something]]]
159-
#### [[9 something]]
159+
#### [filename] [[9 something]]
160160
- [ ] first, as 9 is less then 10
161161
162162
---
163163
164164
Group names: [[[10 something]]]
165-
#### [[10 something]]
165+
#### [filename] [[10 something]]
166166
- [ ] second, as 10 is more than 9
167167
168168
---
@@ -189,13 +189,13 @@ describe('Grouping tasks', () => {
189189
- due reverse
190190
191191
Group names: [2023-07-08 Saturday]
192-
#### 2023-07-08 Saturday
192+
#### [due] 2023-07-08 Saturday
193193
- [ ] b 📅 2023-07-08
194194
195195
---
196196
197197
Group names: [2023-04-05 Wednesday]
198-
#### 2023-04-05 Wednesday
198+
#### [due] 2023-04-05 Wednesday
199199
- [ ] a 📅 2023-04-05
200200
201201
---
@@ -224,14 +224,14 @@ describe('Grouping tasks', () => {
224224
- tags
225225
226226
Group names: [#group1]
227-
#### #group1
227+
#### [tags] #group1
228228
- [ ] Task 1 #group1
229229
- [ ] Task 2 #group2 #group1
230230
231231
---
232232
233233
Group names: [#group2]
234-
#### #group2
234+
#### [tags] #group2
235235
- [ ] Task 2 #group2 #group1
236236
- [ ] Task 3 #group2
237237
@@ -273,21 +273,21 @@ describe('Grouping tasks', () => {
273273
- filename
274274
275275
Group names: [folder\\_b/folder\\_c/,[[file_c]]]
276-
#### folder\\_b/folder\\_c/
277-
##### [[file_c]]
276+
#### [folder] folder\\_b/folder\\_c/
277+
##### [filename] [[file_c]]
278278
- [ ] Task 1 - but path is 2nd, alphabetically
279279
280280
---
281281
282282
Group names: [folder\\_b/folder\\_c/,[[file_d]]]
283-
##### [[file_d]]
283+
##### [filename] [[file_d]]
284284
- [ ] Task 2 - but path is 2nd, alphabetically
285285
286286
---
287287
288288
Group names: [folder\\_a/folder\\_b/,[[file_c]]]
289-
#### folder\\_a/folder\\_b/
290-
##### [[file_c]]
289+
#### [folder] folder\\_a/folder\\_b/
290+
##### [filename] [[file_c]]
291291
- [ ] Task 3 - but path is 1st, alphabetically
292292
293293
---
@@ -322,20 +322,20 @@ describe('Grouping tasks', () => {
322322
- happens
323323
324324
Group names: [2 TODO,2022-09-19 Monday]
325-
#### 2 TODO
326-
##### 2022-09-19 Monday
325+
#### [status.type] 2 TODO
326+
##### [happens] 2022-09-19 Monday
327327
- [ ] Task a - early date 📅 2022-09-19
328328
329329
---
330330
331331
Group names: [2 TODO,2022-10-06 Thursday]
332-
##### 2022-10-06 Thursday
332+
##### [happens] 2022-10-06 Thursday
333333
- [ ] Task c - intermediate date ⏳ 2022-10-06
334334
335335
---
336336
337337
Group names: [2 TODO,2022-12-06 Tuesday]
338-
##### 2022-12-06 Tuesday
338+
##### [happens] 2022-12-06 Tuesday
339339
- [ ] Task b - later date ⏳ 2022-12-06
340340
341341
---

0 commit comments

Comments
 (0)