Skip to content

Commit a30e46d

Browse files
committed
refactor: . move QueryLayout to a separate file
1 parent 598f8a5 commit a30e46d

File tree

4 files changed

+40
-37
lines changed

4 files changed

+40
-37
lines changed

src/Layout/QueryLayout.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { generateHiddenClassForTaskList } from './LayoutHelpers';
2+
import { QueryLayoutOptions } from './QueryLayoutOptions';
3+
4+
export class QueryLayout {
5+
protected queryLayoutOptions: QueryLayoutOptions;
6+
7+
constructor(queryLayoutOptions?: QueryLayoutOptions) {
8+
if (queryLayoutOptions) {
9+
this.queryLayoutOptions = queryLayoutOptions;
10+
} else {
11+
this.queryLayoutOptions = new QueryLayoutOptions();
12+
}
13+
}
14+
15+
public applyQueryLayoutOptions() {
16+
const taskListHiddenClasses: string[] = [];
17+
const componentsToGenerateClassesOnly: [boolean, string][] = [
18+
// The following components are handled in QueryRenderer.ts and thus are not part of the same flow that
19+
// hides TaskLayoutComponent items. However, we still want to have 'tasks-layout-hide' items for them
20+
// (see https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1866).
21+
// This can benefit from some refactoring, i.e. render these components in a similar flow rather than
22+
// separately.
23+
[this.queryLayoutOptions.hideUrgency, 'urgency'],
24+
[this.queryLayoutOptions.hideBacklinks, 'backlinks'],
25+
[this.queryLayoutOptions.hideEditButton, 'edit-button'],
26+
[this.queryLayoutOptions.hidePostponeButton, 'postpone-button'],
27+
];
28+
for (const [hide, component] of componentsToGenerateClassesOnly) {
29+
generateHiddenClassForTaskList(taskListHiddenClasses, hide, component);
30+
}
31+
32+
if (this.queryLayoutOptions.shortMode) taskListHiddenClasses.push('tasks-layout-short-mode');
33+
34+
return taskListHiddenClasses;
35+
}
36+
}

src/Layout/TaskLayout.ts

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { generateHiddenClassForTaskList } from './LayoutHelpers';
2-
import { QueryLayoutOptions } from './QueryLayoutOptions';
32
import { TaskLayoutOptions } from './TaskLayoutOptions';
43

54
export type TaskLayoutComponent =
@@ -34,40 +33,6 @@ export const taskLayoutComponents: TaskLayoutComponent[] = [
3433
'blockLink',
3534
];
3635

37-
export class QueryLayout {
38-
protected queryLayoutOptions: QueryLayoutOptions;
39-
40-
constructor(queryLayoutOptions?: QueryLayoutOptions) {
41-
if (queryLayoutOptions) {
42-
this.queryLayoutOptions = queryLayoutOptions;
43-
} else {
44-
this.queryLayoutOptions = new QueryLayoutOptions();
45-
}
46-
}
47-
48-
public applyQueryLayoutOptions() {
49-
const taskListHiddenClasses: string[] = [];
50-
const componentsToGenerateClassesOnly: [boolean, string][] = [
51-
// The following components are handled in QueryRenderer.ts and thus are not part of the same flow that
52-
// hides TaskLayoutComponent items. However, we still want to have 'tasks-layout-hide' items for them
53-
// (see https://github.com/obsidian-tasks-group/obsidian-tasks/issues/1866).
54-
// This can benefit from some refactoring, i.e. render these components in a similar flow rather than
55-
// separately.
56-
[this.queryLayoutOptions.hideUrgency, 'urgency'],
57-
[this.queryLayoutOptions.hideBacklinks, 'backlinks'],
58-
[this.queryLayoutOptions.hideEditButton, 'edit-button'],
59-
[this.queryLayoutOptions.hidePostponeButton, 'postpone-button'],
60-
];
61-
for (const [hide, component] of componentsToGenerateClassesOnly) {
62-
generateHiddenClassForTaskList(taskListHiddenClasses, hide, component);
63-
}
64-
65-
if (this.queryLayoutOptions.shortMode) taskListHiddenClasses.push('tasks-layout-short-mode');
66-
67-
return taskListHiddenClasses;
68-
}
69-
}
70-
7136
/**
7237
* This represents the desired layout of tasks when they are rendered in a given configuration.
7338
* The layout is used when flattening the task to a string and when rendering queries, and can be

src/Renderer/QueryRenderer.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { EventRef, MarkdownPostProcessorContext } from 'obsidian';
22
import { App, Keymap, MarkdownRenderChild, MarkdownRenderer, TFile } from 'obsidian';
33
import { GlobalFilter } from '../Config/GlobalFilter';
44
import { GlobalQuery } from '../Config/GlobalQuery';
5+
import { QueryLayout } from '../Layout/QueryLayout';
56
import { DateFallback } from '../Task/DateFallback';
67

78
import type { IQuery } from '../IQuery';
@@ -11,7 +12,7 @@ import type { QueryResult } from '../Query/QueryResult';
1112
import type { TaskGroups } from '../Query/Group/TaskGroups';
1213
import { postponeButtonTitle, shouldShowPostponeButton } from '../Scripting/Postponer';
1314
import type { Task } from '../Task/Task';
14-
import { QueryLayout, TaskLayout } from '../Layout/TaskLayout';
15+
import { TaskLayout } from '../Layout/TaskLayout';
1516
import { PostponeMenu } from '../ui/Menus/PostponeMenu';
1617
import type TasksPlugin from '../main';
1718
import { TaskModal } from '../Obsidian/TaskModal';

tests/Layout/TaskLayout.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
* @jest-environment jsdom
33
*/
44

5+
import { QueryLayout } from '../../src/Layout/QueryLayout';
56
import { TaskLayoutOptions } from '../../src/Layout/TaskLayoutOptions';
67
import { QueryLayoutOptions } from '../../src/Layout/QueryLayoutOptions';
7-
import { QueryLayout, TaskLayout } from '../../src/Layout/TaskLayout';
8+
import { TaskLayout } from '../../src/Layout/TaskLayout';
89

910
describe('TaskLayout tests', () => {
1011
it('should generate expected CSS classes for default layout', () => {

0 commit comments

Comments
 (0)