Skip to content

Commit f871f44

Browse files
authored
Merge pull request #2613 from ilandikov/refactor-taskLayout-queryLayout-renames
refactor: `TaskLayout`& `QueryLayout` renames
2 parents be6994a + 022c55e commit f871f44

File tree

5 files changed

+26
-24
lines changed

5 files changed

+26
-24
lines changed

src/Layout/LayoutHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export function generateHiddenClassForTaskList(taskListHiddenClasses: string[], hide: boolean, component: string) {
1+
export function generateHiddenClassForTaskList(hiddenClasses: string[], hide: boolean, component: string) {
22
if (hide) {
3-
taskListHiddenClasses.push(hiddenComponentClassName(component));
3+
hiddenClasses.push(hiddenComponentClassName(component));
44
}
55
}
66

src/Layout/QueryLayout.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { generateHiddenClassForTaskList } from './LayoutHelpers';
22
import { QueryLayoutOptions } from './QueryLayoutOptions';
33

4+
/**
5+
* This class generates a list of hidden query components' classes.
6+
* The output depends on {@link QueryLayoutOptions} objects.
7+
*/
48
export class QueryLayout {
59
protected queryLayoutOptions: QueryLayoutOptions;
610

@@ -12,8 +16,8 @@ export class QueryLayout {
1216
}
1317
}
1418

15-
public applyQueryLayoutOptions() {
16-
const taskListHiddenClasses: string[] = [];
19+
public getHiddenClasses() {
20+
const hiddenClasses: string[] = [];
1721
const componentsToGenerateClassesOnly: [boolean, string][] = [
1822
// The following components are handled in QueryRenderer.ts and thus are not part of the same flow that
1923
// hides TaskLayoutComponent items. However, we still want to have 'tasks-layout-hide' items for them
@@ -26,11 +30,11 @@ export class QueryLayout {
2630
[this.queryLayoutOptions.hidePostponeButton, 'postpone-button'],
2731
];
2832
for (const [hide, component] of componentsToGenerateClassesOnly) {
29-
generateHiddenClassForTaskList(taskListHiddenClasses, hide, component);
33+
generateHiddenClassForTaskList(hiddenClasses, hide, component);
3034
}
3135

32-
if (this.queryLayoutOptions.shortMode) taskListHiddenClasses.push('tasks-layout-short-mode');
36+
if (this.queryLayoutOptions.shortMode) hiddenClasses.push('tasks-layout-short-mode');
3337

34-
return taskListHiddenClasses;
38+
return hiddenClasses;
3539
}
3640
}

src/Layout/TaskLayout.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ import { generateHiddenClassForTaskList } from './LayoutHelpers';
22
import { TaskLayoutOptions } from './TaskLayoutOptions';
33

44
/**
5-
* This represents the desired layout of tasks when they are rendered in a given configuration.
6-
* The layout is used when flattening the task to a string and when rendering queries, and can be
7-
* modified by applying {@link TaskLayoutOptions} objects.
5+
* This class generates a list of hidden task components' classes.
6+
* The output depends on {@link TaskLayoutOptions} objects.
87
*/
98
export class TaskLayout {
109
private taskLayoutOptions: TaskLayoutOptions;
@@ -16,19 +15,15 @@ export class TaskLayout {
1615
this.taskLayoutOptions = new TaskLayoutOptions();
1716
}
1817
}
19-
public applyTaskLayoutOptions() {
20-
const taskListHiddenClasses: string[] = [];
18+
public generateHiddenClasses() {
19+
const hiddenClasses: string[] = [];
2120
this.taskLayoutOptions.toggleableComponents.forEach((component) => {
22-
generateHiddenClassForTaskList(
23-
taskListHiddenClasses,
24-
!this.taskLayoutOptions.isShown(component),
25-
component,
26-
);
21+
generateHiddenClassForTaskList(hiddenClasses, !this.taskLayoutOptions.isShown(component), component);
2722
});
2823

2924
// Tags are hidden, rather than removed. See tasks-layout-hide-tags in styles.css.
30-
generateHiddenClassForTaskList(taskListHiddenClasses, !this.taskLayoutOptions.areTagsShown(), 'tags');
25+
generateHiddenClassForTaskList(hiddenClasses, !this.taskLayoutOptions.areTagsShown(), 'tags');
3126

32-
return taskListHiddenClasses;
27+
return hiddenClasses;
3328
}
3429
}

src/Renderer/QueryRenderer.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,14 @@ class QueryRenderChild extends MarkdownRenderChild {
222222
}
223223

224224
private async createTaskList(tasks: Task[], content: HTMLDivElement): Promise<void> {
225-
const layout = new TaskLayout(this.query.taskLayoutOptions);
226-
const queryLayout = new QueryLayout(this.query.queryLayoutOptions);
227225
const taskList = content.createEl('ul');
226+
228227
taskList.addClasses(['contains-task-list', 'plugin-tasks-query-result']);
229-
taskList.addClasses([...layout.applyTaskLayoutOptions(), ...queryLayout.applyQueryLayoutOptions()]);
228+
const taskLayout = new TaskLayout(this.query.taskLayoutOptions);
229+
taskList.addClasses(taskLayout.generateHiddenClasses());
230+
const queryLayout = new QueryLayout(this.query.queryLayoutOptions);
231+
taskList.addClasses(queryLayout.getHiddenClasses());
232+
230233
const groupingAttribute = this.getGroupingAttribute();
231234
if (groupingAttribute && groupingAttribute.length > 0) taskList.dataset.taskGroupBy = groupingAttribute;
232235

tests/Layout/TaskLayout.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ describe('TaskLayout tests', () => {
1212
const taskLayout = new TaskLayout();
1313
const queryLayout = new QueryLayout();
1414

15-
const hiddenClasses = [...taskLayout.applyTaskLayoutOptions(), ...queryLayout.applyQueryLayoutOptions()];
15+
const hiddenClasses = [...taskLayout.generateHiddenClasses(), ...queryLayout.getHiddenClasses()];
1616
expect(hiddenClasses.join('\n')).toMatchInlineSnapshot('"tasks-layout-hide-urgency"');
1717
});
1818

@@ -30,7 +30,7 @@ describe('TaskLayout tests', () => {
3030
const taskLayout = new TaskLayout(taskLayoutOptions);
3131
const queryLayout = new QueryLayout(queryLayoutOptions);
3232

33-
const hiddenClasses = [...taskLayout.applyTaskLayoutOptions(), ...queryLayout.applyQueryLayoutOptions()];
33+
const hiddenClasses = [...taskLayout.generateHiddenClasses(), ...queryLayout.getHiddenClasses()];
3434
expect(hiddenClasses.join('\n')).toMatchInlineSnapshot(`
3535
"tasks-layout-hide-id
3636
tasks-layout-hide-blockedBy

0 commit comments

Comments
 (0)