diff --git a/docs/releases/unreleased.md b/docs/releases/unreleased.md index e2e2171d..96632422 100644 --- a/docs/releases/unreleased.md +++ b/docs/releases/unreleased.md @@ -1,5 +1,7 @@ # Unreleased +- Keep each task's ID in the property your collection's task type maps it to, such as `tasknote_id`, instead of always writing `id`. A plain `id` property is then left as your own data. Collections that use `id` are unchanged (tasknotes#2574, requested by @minchinweb). + - Show reminders as ready as soon as notification access is approved in mdbase, instead of still asking for approval until the page is reloaded. - Keep a reminder's generated notification text in step with its time: changing "15 minutes before" to 2 minutes now reads "2 minutes before". Text you wrote yourself is never changed. diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fdc65109..c4e873e2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -10,8 +10,8 @@ catalogs: specifier: 0.1.17 version: 0.1.17 '@tasknotes/model': - specifier: 0.3.0 - version: 0.3.0 + specifier: 0.3.1 + version: 0.3.1 importers: @@ -94,7 +94,7 @@ importers: version: 0.1.10(react@19.2.8) '@tasknotes/model': specifier: 'catalog:' - version: 0.3.0 + version: 0.3.1 codemirror: specifier: ^6.0.2 version: 6.0.2 @@ -254,7 +254,7 @@ importers: version: 0.1.17 '@tasknotes/model': specifier: 'catalog:' - version: 0.3.0 + version: 0.3.1 react: specifier: 19.3.0 version: 19.3.0 @@ -1831,8 +1831,8 @@ packages: react: optional: true - '@tasknotes/model@0.3.0': - resolution: {integrity: sha512-F7JfLCszUgMOfRCFVW+rfV97IP5fmWpc/ZNCZ+GyzwZAnxggGgLVvJIArn+biiwCAdbr8Fk0lXxMIu2/HRarqw==} + '@tasknotes/model@0.3.1': + resolution: {integrity: sha512-LEFpiTO4o37Z83JqzfvsI5GSjgOVYKyjIrIjiJylVk/bcQJgoUp/NgN+EsvOPNlxSqJRJk2QQHjf9gW7/MeNhA==} '@testing-library/dom@10.4.1': resolution: {integrity: sha512-o4PXJQidqJl82ckFaXUeoAW+XysPLauYI43Abki5hABd853iMhitooc6znOnczgbTYmEP6U6/y1ZyKAIsvMKGg==} @@ -6635,7 +6635,7 @@ snapshots: optionalDependencies: react: 19.2.8 - '@tasknotes/model@0.3.0': + '@tasknotes/model@0.3.1': dependencies: rrule: 2.8.1 yaml: 2.9.1 diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index e081b24f..989f0be4 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -3,4 +3,4 @@ packages: catalog: "@mdbase-dev/sdk": 0.1.17 - "@tasknotes/model": 0.3.0 + "@tasknotes/model": 0.3.1 diff --git a/src/domain/tasknotes-model.test.ts b/src/domain/tasknotes-model.test.ts index 6335083a..307c8359 100644 --- a/src/domain/tasknotes-model.test.ts +++ b/src/domain/tasknotes-model.test.ts @@ -1,6 +1,7 @@ import { describe, expect, it, vi } from "vitest"; import { buildCalendarEntries } from "@tasknotes/model/calendar"; +import { DEFAULT_FIELD_MAPPING } from "@tasknotes/model/mapping"; import { calendarOccurrenceChoice } from "./calendar-edit"; import { TaskNotesTaskModel } from "./tasknotes-model"; @@ -1020,3 +1021,30 @@ function priority(value: string, label: string, weight: number) { function canonicalLocal(value: string): string { return new Date(value).toISOString().replace(".000Z", "Z"); } + +// tasknotes#2574: a collection's type can store the stable ID under another +// property, freeing `id` for the user's own data. +describe("a remapped task ID", () => { + const model = new TaskNotesTaskModel({ + fieldMapping: { ...DEFAULT_FIELD_MAPPING, id: "tasknote_id" }, + }); + + it("writes, reads and keeps the ID under the mapped property", () => { + const created = model.create({ title: "Remapped" }, { id: "abc" }); + expect(created.id).toBe("abc"); + expect(created.frontmatter.tasknote_id).toBe("abc"); + expect(created.frontmatter).not.toHaveProperty("id"); + + const task = model.read({ + path: created.path, + frontmatter: { ...created.frontmatter, id: "mine" }, + body: "", + }); + expect(task.id).toBe("abc"); + + const updated = model.update(task, { title: "Renamed" }); + expect(updated.frontmatter.tasknote_id).toBe("abc"); + expect(updated.frontmatter.id).toBe("mine"); + expect(model.summaryFields()).toContain("tasknote_id"); + }); +}); diff --git a/src/domain/tasknotes-model.ts b/src/domain/tasknotes-model.ts index c218e79d..4fec0590 100644 --- a/src/domain/tasknotes-model.ts +++ b/src/domain/tasknotes-model.ts @@ -15,6 +15,7 @@ import { updateToNextScheduledOccurrence } from "@tasknotes/model/recurrence"; import { mapTaskFromFrontmatter, mapTaskToFrontmatter, + toUserField, } from "@tasknotes/model/mapping"; import { applyFrontmatterPatch, @@ -202,7 +203,7 @@ export class TaskNotesTaskModel { summaryFields(): string[] { return [ ...new Set([ - "id", + toUserField(this.config.fieldMapping, "id"), "mobileRevision", "tags", ...Object.values(this.config.fieldMapping), @@ -983,7 +984,7 @@ export class TaskNotesTaskModel { ) ? { [this.config.fieldMapping.skippedInstances]: [] } : {}), - id, + [toUserField(this.config.fieldMapping, "id")]: id, mobileRevision: revision, }; }