Skip to content

Commit

Permalink
Make title parameter optional (#279)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
jamiebrynes7 authored Feb 1, 2024
1 parent 91aeb03 commit 4b4ff22
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<sup>[1](#footnote-1)</sup> | 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[] | [] |
Expand Down Expand Up @@ -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.

Expand All @@ -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).

---

<a name="footnote-1">1</a>: There are some exceptions in the Todoist API. Checkout [this issue](https://github.com/jamiebrynes7/obsidian-todoist-plugin/issues/34) for details.
27 changes: 11 additions & 16 deletions src/query/parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ describe("parseQuery - rejections", () => {
};

const testcases: Testcase[] = [
{
description: "name is required",
input: {
filter: "foo",
}
},
{
description: "name must be a string",
input: {
Expand Down Expand Up @@ -129,64 +123,65 @@ 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",
},
expectedOutput: makeQuery({
name: "foo",
filter: "bar",
}),
})
},
{
description: "with autorefresh",
input: {
name: "foo",
filter: "bar",
autorefresh: 120,
},
expectedOutput: makeQuery({
name: "foo",
filter: "bar",
autorefresh: 120,
}),
},
{
description: "with group",
input: {
name: "foo",
filter: "bar",
group: true,
},
expectedOutput: makeQuery({
name: "foo",
filter: "bar",
group: true,
}),
},
{
description: "with sorting",
input: {
name: "foo",
filter: "bar",
sorting: ["date"]
},
expectedOutput: makeQuery({
name: "foo",
filter: "bar",
sorting: [SortingVariant.Date],
}),
},
{
description: "with show",
input: {
name: "foo",
filter: "bar",
show: ["due", "project"]
},
expectedOutput: makeQuery({
name: "foo",
filter: "bar",
show: new Set([ShowMetadataVariant.Due, ShowMetadataVariant.Project]),
})
Expand Down
2 changes: 1 addition & 1 deletion src/query/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/ui/TodoistQuery.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@
}
</script>

<h4 class="todoist-query-title">{title}</h4>
{#if title.length != 0}
<h4 class="todoist-query-title">{title}</h4>
{/if}
<div
class={fetching
? "edit-block-button todoist-refresh-button todoist-refresh-disabled"
Expand Down

0 comments on commit 4b4ff22

Please sign in to comment.