Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- You can now sort tasks alphabetically by name using `alphabetical` or `alphabeticalDescending` in the sorting field
- You can now provide 'time' to the show field on a query. This will only render the time of the task (unless the end of the task is on a different day than the start).
- You can now provide 'section' to the show field on a query to display only the section name for tasks in sections.

### 🐛 Bug Fixes

Expand Down
7 changes: 7 additions & 0 deletions docs/docs/query-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,15 @@ The possible values are:
- `deadline`: render the deadline of the task
- `description`: render the description of the task
- `project`: render the project (and section, if applicable) of the task
- `section`: render only the section name of the task (if the task has a section)
- `labels`: render the labels of the task

:::note

If both `project` and `section` are specified, only `project` will be shown to avoid redundancy. The `project` option already includes section information when available.

:::

For example:

````
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/translation-status.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
{
"name": "English",
"code": "en",
"completed": 206,
"completed": 207,
"missing": 0,
"percent": 100
},
{
"name": "Nederlands",
"code": "nl",
"completed": 146,
"missing": 60,
"missing": 61,
"percent": 71
}
]
2 changes: 2 additions & 0 deletions plugin/src/i18n/langs/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ export const en: Translations = {
unknownKey: (key: string) => `Found unexpected query key '${key}'. Is this a typo?`,
dueAndTime:
"Both 'due' and 'time' show options are set. The 'time' option will be ignored when 'due' is present.",
projectAndSection:
"Both 'project' and 'section' show options are set. The 'section' option will be ignored when 'project' is present.",
},
groupedHeaders: {
noDueDate: "No due date",
Expand Down
1 change: 1 addition & 0 deletions plugin/src/i18n/translation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export type Translations = {
jsonQuery: string;
unknownKey: (key: string) => string;
dueAndTime: string;
projectAndSection: string;
};
groupedHeaders: {
noDueDate: string;
Expand Down
10 changes: 5 additions & 5 deletions plugin/src/query/__snapshots__/parser.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ exports[`parseQuery - error message snapshots > show array must contain strings
[Error: Field 'show' has the following issues:
Invalid input: expected "none"
Field 'show' elements have the following issues:
Item 'show[0]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"
Item 'show[1]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"
Item 'show[2]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"]
Item 'show[0]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"
Item 'show[1]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"
Item 'show[2]': Invalid option: expected one of "due"|"date"|"description"|"labels"|"project"|"deadline"|"time"|"section"]
`;

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

exports[`parseQuery - error message snapshots > sorting array must contain strings 1`] = `
Expand Down
33 changes: 33 additions & 0 deletions plugin/src/query/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,28 @@ describe("parseQuery", () => {
show: new Set([ShowMetadataVariant.Due, ShowMetadataVariant.Time]),
}),
},
{
description: "with show including section",
input: {
filter: "bar",
show: ["section"],
},
expectedOutput: makeQuery({
filter: "bar",
show: new Set([ShowMetadataVariant.Section]),
}),
},
{
description: "with show including section and project",
input: {
filter: "bar",
show: ["section", "project"],
},
expectedOutput: makeQuery({
filter: "bar",
show: new Set([ShowMetadataVariant.Section, ShowMetadataVariant.Project]),
}),
},
];

for (const tc of testcases) {
Expand Down Expand Up @@ -319,6 +341,17 @@ describe("parseQuery - warnings", () => {
"Both 'due' and 'time' show options are set. The 'time' option will be ignored when 'due' is present.",
],
},
{
description: "Both project and section in show options",
input: {
filter: "bar",
show: ["project", "section"],
},
expectedWarnings: [
"This query is written using JSON. This is deprecated and will be removed in a future version. Please use YAML instead.",
"Both 'project' and 'section' show options are set. The 'section' option will be ignored when 'project' is present.",
],
},
];

for (const tc of testcases) {
Expand Down
5 changes: 5 additions & 0 deletions plugin/src/query/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ const showSchema = lookupToEnum({
project: ShowMetadataVariant.Project,
deadline: ShowMetadataVariant.Deadline,
time: ShowMetadataVariant.Time,
section: ShowMetadataVariant.Section,
});

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

if (show.has(ShowMetadataVariant.Project) && show.has(ShowMetadataVariant.Section)) {
warnings.push(t().query.warning.projectAndSection);
}

return [
{
name: out.data.name,
Expand Down
1 change: 1 addition & 0 deletions plugin/src/query/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum ShowMetadataVariant {
Description = 3,
Deadline = 4,
Time = 5,
Section = 6,
}

export enum GroupVariant {
Expand Down
22 changes: 22 additions & 0 deletions plugin/src/ui/query/task/TaskMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,27 @@ const projectMeta: MetadataDefinition = {
side: "right",
};

const sectionMeta: MetadataDefinition = {
name: "section",
isShown: (query, task) =>
query.show.has(ShowMetadataVariant.Section) &&
!query.show.has(ShowMetadataVariant.Project) &&
task.section !== undefined,
content: (task) => [
{
// biome-ignore lint/style/noNonNullAssertion: We enforce this above in 'isShown'.
content: task.section!.name,
},
],
icons: {
after: {
id: "gallery-vertical",
shouldRender: (settings) => settings.renderProjectIcon,
},
},
side: "right",
};

const dueDateMeta: MetadataDefinition = {
name: "due",
isShown: (query, task) => query.show.has(ShowMetadataVariant.Due) && task.due !== undefined,
Expand Down Expand Up @@ -128,6 +149,7 @@ const timeOnlyMeta: MetadataDefinition = {

const metadata: MetadataDefinition[] = [
projectMeta,
sectionMeta,
dueDateMeta,
deadlineMeta,
labelsMeta,
Expand Down