Skip to content

Commit 915ae92

Browse files
committed
plugin: add support for 'section' in 'show' query param
1 parent 981ea7d commit 915ae92

File tree

7 files changed

+68
-5
lines changed

7 files changed

+68
-5
lines changed

plugin/src/i18n/langs/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ export const en: Translations = {
253253
unknownKey: (key: string) => `Found unexpected query key '${key}'. Is this a typo?`,
254254
dueAndTime:
255255
"Both 'due' and 'time' show options are set. The 'time' option will be ignored when 'due' is present.",
256+
projectAndSection:
257+
"Both 'project' and 'section' show options are set. The 'section' option will be ignored when 'project' is present.",
256258
},
257259
groupedHeaders: {
258260
noDueDate: "No due date",

plugin/src/i18n/translation.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export type Translations = {
227227
jsonQuery: string;
228228
unknownKey: (key: string) => string;
229229
dueAndTime: string;
230+
projectAndSection: string;
230231
};
231232
groupedHeaders: {
232233
noDueDate: string;

plugin/src/query/__snapshots__/parser.test.ts.snap

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ exports[`parseQuery - error message snapshots > show array must contain strings
6666
[Error: Field 'show' has the following issues:
6767
Invalid input: expected "none"
6868
Field 'show' elements have the following issues:
69-
Item 'show[0]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"
70-
Item 'show[1]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"
71-
Item 'show[2]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"]
69+
Item 'show[0]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"
70+
Item 'show[1]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"
71+
Item 'show[2]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"]
7272
`;
7373

7474
exports[`parseQuery - error message snapshots > show field - invalid literal (not 'none') 1`] = `
@@ -81,8 +81,8 @@ exports[`parseQuery - error message snapshots > show must have valid enum values
8181
[Error: Field 'show' has the following issues:
8282
Invalid input: expected "none"
8383
Field 'show' elements have the following issues:
84-
Item 'show[0]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"
85-
Item 'show[1]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"]
84+
Item 'show[0]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"
85+
Item 'show[1]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"]
8686
`;
8787

8888
exports[`parseQuery - error message snapshots > sorting array must contain strings 1`] = `

plugin/src/query/parser.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,28 @@ describe("parseQuery", () => {
269269
show: new Set([ShowMetadataVariant.Due, ShowMetadataVariant.Time]),
270270
}),
271271
},
272+
{
273+
description: "with show including section",
274+
input: {
275+
filter: "bar",
276+
show: ["section"],
277+
},
278+
expectedOutput: makeQuery({
279+
filter: "bar",
280+
show: new Set([ShowMetadataVariant.Section]),
281+
}),
282+
},
283+
{
284+
description: "with show including section and project",
285+
input: {
286+
filter: "bar",
287+
show: ["section", "project"],
288+
},
289+
expectedOutput: makeQuery({
290+
filter: "bar",
291+
show: new Set([ShowMetadataVariant.Section, ShowMetadataVariant.Project]),
292+
}),
293+
},
272294
];
273295

274296
for (const tc of testcases) {
@@ -319,6 +341,17 @@ describe("parseQuery - warnings", () => {
319341
"Both 'due' and 'time' show options are set. The 'time' option will be ignored when 'due' is present.",
320342
],
321343
},
344+
{
345+
description: "Both project and section in show options",
346+
input: {
347+
filter: "bar",
348+
show: ["project", "section"],
349+
},
350+
expectedWarnings: [
351+
"This query is written using JSON. This is deprecated and will be removed in a future version. Please use YAML instead.",
352+
"Both 'project' and 'section' show options are set. The 'section' option will be ignored when 'project' is present.",
353+
],
354+
},
322355
];
323356

324357
for (const tc of testcases) {

plugin/src/query/parser.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ const showSchema = lookupToEnum({
108108
project: ShowMetadataVariant.Project,
109109
deadline: ShowMetadataVariant.Deadline,
110110
time: ShowMetadataVariant.Time,
111+
section: ShowMetadataVariant.Section,
111112
});
112113

113114
const groupBySchema = lookupToEnum({
@@ -171,6 +172,10 @@ function parseObjectZod(query: Record<string, unknown>): [Query, QueryWarning[]]
171172
warnings.push(t().query.warning.dueAndTime);
172173
}
173174

175+
if (show.has(ShowMetadataVariant.Project) && show.has(ShowMetadataVariant.Section)) {
176+
warnings.push(t().query.warning.projectAndSection);
177+
}
178+
174179
return [
175180
{
176181
name: out.data.name,

plugin/src/query/query.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export enum ShowMetadataVariant {
1717
Description = 3,
1818
Deadline = 4,
1919
Time = 5,
20+
Section = 6,
2021
}
2122

2223
export enum GroupVariant {

plugin/src/ui/query/task/TaskMetadata.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,26 @@ const projectMeta: MetadataDefinition = {
5151
side: "right",
5252
};
5353

54+
const sectionMeta: MetadataDefinition = {
55+
name: "section",
56+
isShown: (query, task) =>
57+
query.show.has(ShowMetadataVariant.Section) &&
58+
!query.show.has(ShowMetadataVariant.Project) &&
59+
task.section !== undefined,
60+
content: (task) => [
61+
{
62+
content: task.section!.name,
63+
},
64+
],
65+
icons: {
66+
after: {
67+
id: "gallery-vertical",
68+
shouldRender: (settings) => settings.renderProjectIcon,
69+
},
70+
},
71+
side: "right",
72+
};
73+
5474
const dueDateMeta: MetadataDefinition = {
5575
name: "due",
5676
isShown: (query, task) => query.show.has(ShowMetadataVariant.Due) && task.due !== undefined,
@@ -128,6 +148,7 @@ const timeOnlyMeta: MetadataDefinition = {
128148

129149
const metadata: MetadataDefinition[] = [
130150
projectMeta,
151+
sectionMeta,
131152
dueDateMeta,
132153
deadlineMeta,
133154
labelsMeta,

0 commit comments

Comments
 (0)