From 4b4ff22d473a982e1df204ffaaa3452b5e67c0e0 Mon Sep 17 00:00:00 2001 From: Jamie Brynes Date: Thu, 1 Feb 2024 19:48:15 +0000 Subject: [PATCH] Make title parameter optional (#279) * make title filter parameter optional * conditionally render the title block Only render the h4 block if the title is non-zero length * update readme & changelog --- CHANGELOG.md | 1 + README.md | 8 +++----- src/query/parser.test.ts | 27 +++++++++++---------------- src/query/parser.ts | 2 +- src/ui/TodoistQuery.svelte | 4 +++- 5 files changed, 19 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d4e939..a3fd6cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fix intent level to match standard markdown levels in order to have consistent style. - Aligned the grouping behaviour with Todoist's when grouping by project. This will be expanded on in a future release. - Changed all icons to be part of the Lucide set to align with Obsidian. +- The `title` part of the query is now optional. ## [1.11.1] - 2023-04-09 diff --git a/README.md b/README.md index 6e2e8e8..282847c 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ The query is defined in YAML and accepts the following keys: | Name | Required | Description | Type | Default | | ------------- | :------: | ----------------------------------------------------------------------------------------------------------------------------------------------------- | -------- | ------------ | -| `name` | ✓ | The title for the materialized query. You can use the `{task_count}` template which will be replaced by the number of tasks returned by the query. | string | | +| `name` | | The title for the materialized query. You can use the `{task_count}` template which will be replaced by the number of tasks returned by the query. | string | "" | | `filter` | ✓ | A valid [Todoist filter](https://get.todoist.help/hc/en-us/articles/205248842-Filters)[1](#footnote-1) | string | | | `autorefresh` | | The number of seconds between auto-refreshing. If omitted, the query use the default global settings. | number | null | | `sorting` | | Describes how to order the tasks in the query. Can be any of 'priority', 'dateAscending' (aliased as 'date'), 'dateDescending', or multiple of these. | string[] | [] | @@ -75,7 +75,7 @@ show: There are also a few commands bundled in with the plugin: -1. 'Refresh Metadata' +1. 'Sync with Todoist' This command refreshes all the metadata (projects, sections, and labels) for Todoist tasks. This is done at startup. @@ -85,14 +85,12 @@ There are also a few commands bundled in with the plugin: 3. 'Add Todoist task with the current page' - Similiar to the previous command, this one also appends a link to the current active page to the task input. + Similar to the previous command, this one also appends a link to the current active page to the task input. ## CSS This plugin comes with default CSS intended for use with the default Obsidian themes. -I also maintain an Obsidian theme which has support out of the box for this plugin, for a complete example of CSS for this plugin, check out [the source](https://github.com/jamiebrynes7/moonlight-obsidian-theme/blob/master/src/modules/extensions/todoist.scss). - --- 1: There are some exceptions in the Todoist API. Checkout [this issue](https://github.com/jamiebrynes7/obsidian-todoist-plugin/issues/34) for details. diff --git a/src/query/parser.test.ts b/src/query/parser.test.ts index 94422b0..6527034 100644 --- a/src/query/parser.test.ts +++ b/src/query/parser.test.ts @@ -10,12 +10,6 @@ describe("parseQuery - rejections", () => { }; const testcases: Testcase[] = [ - { - description: "name is required", - input: { - filter: "foo", - } - }, { description: "name must be a string", input: { @@ -129,7 +123,16 @@ describe("parseQuery", () => { const testcases: Testcase[] = [ { - description: "only name & filter", + description: "only filter", + input: { + filter: "bar", + }, + expectedOutput: makeQuery({ + filter: "bar", + }), + }, + { + description: "with name", input: { name: "foo", filter: "bar", @@ -137,17 +140,15 @@ describe("parseQuery", () => { expectedOutput: makeQuery({ name: "foo", filter: "bar", - }), + }) }, { description: "with autorefresh", input: { - name: "foo", filter: "bar", autorefresh: 120, }, expectedOutput: makeQuery({ - name: "foo", filter: "bar", autorefresh: 120, }), @@ -155,12 +156,10 @@ describe("parseQuery", () => { { description: "with group", input: { - name: "foo", filter: "bar", group: true, }, expectedOutput: makeQuery({ - name: "foo", filter: "bar", group: true, }), @@ -168,12 +167,10 @@ describe("parseQuery", () => { { description: "with sorting", input: { - name: "foo", filter: "bar", sorting: ["date"] }, expectedOutput: makeQuery({ - name: "foo", filter: "bar", sorting: [SortingVariant.Date], }), @@ -181,12 +178,10 @@ describe("parseQuery", () => { { description: "with show", input: { - name: "foo", filter: "bar", show: ["due", "project"] }, expectedOutput: makeQuery({ - name: "foo", filter: "bar", show: new Set([ShowMetadataVariant.Due, ShowMetadataVariant.Project]), }) diff --git a/src/query/parser.ts b/src/query/parser.ts index c788538..9f389e1 100644 --- a/src/query/parser.ts +++ b/src/query/parser.ts @@ -52,7 +52,7 @@ function tryParseAsYaml(raw: string): any { function parseObject(query: any): Query { return { - name: asRequired("name", stringField(query, "name")), + name: stringField(query, "name") ?? "", filter: asRequired("filter", stringField(query, "filter")), group: booleanField(query, "group") ?? false, autorefresh: numberField(query, "autorefresh", { isPositive: true }) ?? 0, diff --git a/src/ui/TodoistQuery.svelte b/src/ui/TodoistQuery.svelte index e6231d5..4b0061e 100644 --- a/src/ui/TodoistQuery.svelte +++ b/src/ui/TodoistQuery.svelte @@ -107,7 +107,9 @@ } -

{title}

+{#if title.length != 0} +

{title}

+{/if}