Skip to content

Commit 9dcc0e5

Browse files
authored
Merge pull request #3426 from ilandikov/refactor-prepare-includes
refactor: prepare includes
2 parents 672421a + b7d15ce commit 9dcc0e5

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

src/Config/Settings.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ export const TASK_FORMATS = {
6161
export type TASK_FORMATS = typeof TASK_FORMATS; // For convenience to make some typing easier
6262

6363
export interface Settings {
64+
includes: Record<string, string>;
6465
globalQuery: string;
6566
globalFilter: string;
6667
removeGlobalFilter: boolean;
@@ -96,6 +97,7 @@ export interface Settings {
9697
}
9798

9899
const defaultSettings: Settings = {
100+
includes: {},
99101
globalQuery: '',
100102
globalFilter: '',
101103
removeGlobalFilter: false,

src/Scripting/QueryContext.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getSettings } from '../Config/Settings';
12
import type { Task } from '../Task/Task';
23
import type { TasksFile } from './TasksFile';
34

@@ -24,6 +25,7 @@ export interface QueryContext {
2425
allTasks: Readonly<Task[]>;
2526
searchCache: Record<string, any>; // Added caching capability
2627
};
28+
includes: Record<string, string>;
2729
}
2830

2931
/**
@@ -57,5 +59,6 @@ export function makeQueryContextWithTasks(tasksFile: TasksFile, allTasks: Readon
5759
allTasks: allTasks,
5860
searchCache: {}, // Added for caching
5961
},
62+
includes: { ...getSettings().includes },
6063
};
6164
}

tests/Scripting/Includes.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { getSettings, resetSettings, updateSettings } from '../../src/Config/Settings';
2+
import { Query } from '../../src/Query/Query';
3+
import { TasksFile } from '../../src/Scripting/TasksFile';
4+
5+
afterEach(() => {
6+
resetSettings();
7+
});
8+
9+
describe('include tests', () => {
10+
it('should accept whole-line include placeholder', () => {
11+
updateSettings({ includes: { not_done: 'not done' } });
12+
13+
const source = '{{includes.not_done}}';
14+
const query = new Query(source, new TasksFile('stuff.md'));
15+
16+
expect(query.error).toBeUndefined();
17+
expect(query.filters.length).toEqual(1);
18+
expect(query.filters[0].statement.anyPlaceholdersExpanded).toEqual('not done');
19+
});
20+
});
21+
22+
describe('include settings tests', () => {
23+
it('should have an empty include field', () => {
24+
const settings = getSettings();
25+
26+
expect(settings.includes).toEqual({});
27+
});
28+
});

0 commit comments

Comments
 (0)