File tree Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Expand file tree Collapse file tree 3 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 1
1
import type { Task } from '../Task/Task' ;
2
- import { type QueryContext , makeQueryContext } from '../Scripting/QueryContext' ;
2
+ import { type QueryContext , makeQueryContextWithTasks } from '../Scripting/QueryContext' ;
3
3
4
4
/**
5
5
* SearchInfo contains selected data passed in from the {@link Query} being executed.
@@ -30,6 +30,6 @@ export class SearchInfo {
30
30
* @return A QueryContext, or undefined if the path to the query file is unknown.
31
31
*/
32
32
public queryContext ( ) : QueryContext | undefined {
33
- return this . queryPath ? makeQueryContext ( this . queryPath ) : undefined ;
33
+ return this . queryPath ? makeQueryContextWithTasks ( this . queryPath , this . allTasks ) : undefined ;
34
34
}
35
35
}
Original file line number Diff line number Diff line change
1
+ import type { Task } from '../Task/Task' ;
1
2
import { TasksFile } from './TasksFile' ;
2
3
3
4
/**
@@ -18,6 +19,7 @@ import { TasksFile } from './TasksFile';
18
19
export interface QueryContext {
19
20
query : {
20
21
file : TasksFile ;
22
+ allTasks : Readonly < Task [ ] > ;
21
23
} ;
22
24
}
23
25
@@ -32,6 +34,17 @@ export function makeQueryContext(path: string): QueryContext {
32
34
return {
33
35
query : {
34
36
file : tasksFile ,
37
+ allTasks : [ ] ,
38
+ } ,
39
+ } ;
40
+ }
41
+
42
+ export function makeQueryContextWithTasks ( path : string , allTasks : Readonly < Task [ ] > ) : QueryContext {
43
+ const tasksFile = new TasksFile ( path ) ;
44
+ return {
45
+ query : {
46
+ file : tasksFile ,
47
+ allTasks : allTasks ,
35
48
} ,
36
49
} ;
37
50
}
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ import { FolderField } from '../../src/Query/Filter/FolderField';
4
4
import { PathField } from '../../src/Query/Filter/PathField' ;
5
5
import { RootField } from '../../src/Query/Filter/RootField' ;
6
6
import { makeQueryContext } from '../../src/Scripting/QueryContext' ;
7
+ import { FunctionField } from '../../src/Query/Filter/FunctionField' ;
8
+ import { SearchInfo } from '../../src/Query/SearchInfo' ;
7
9
8
10
describe ( 'QueryContext' , ( ) => {
9
11
describe ( 'values should all match their corresponding filters' , ( ) => {
@@ -34,5 +36,20 @@ describe('QueryContext', () => {
34
36
const filter = new FilenameField ( ) . createFilterOrErrorMessage ( instruction ) ;
35
37
expect ( filter ) . toMatchTask ( task ) ;
36
38
} ) ;
39
+
40
+ it ( 'allTasks' , ( ) => {
41
+ // Arrange
42
+ // An artificial example, just to demonstrate that query.allTasks is accessible via scripting
43
+ const instruction = 'group by function query.allTasks.length' ;
44
+ const grouper = new FunctionField ( ) . createGrouperFromLine ( instruction ) ;
45
+ expect ( grouper ) . not . toBeNull ( ) ;
46
+ const searchInfo = new SearchInfo ( path , [ task ] ) ;
47
+
48
+ // Act
49
+ const group : string [ ] = grouper ! . grouper ( task , searchInfo ) ;
50
+
51
+ // Assert
52
+ expect ( group ) . toEqual ( [ '1' ] ) ;
53
+ } ) ;
37
54
} ) ;
38
55
} ) ;
You can’t perform that action at this time.
0 commit comments