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
2 changes: 1 addition & 1 deletion docs/javascript-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const operators = api.catalog.filterOperators();
## Tasks

All paths are vault-relative Markdown file paths. New tasks created or converted by TaskNotes v5
receive a UUID in the standard `id` frontmatter field. That ID remains unchanged when a task file
receive a UUID in the `id` frontmatter field (or the property key configured for **Task ID**). That ID remains unchanged when a task file
moves or is renamed, while `path` continues to identify the task's current location. Existing tasks
without an ID remain valid and are not migrated automatically.

Expand Down
2 changes: 1 addition & 1 deletion docs/migration-v4-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Values saved for these settings stay in `data.json`, so devices still on 4.x kee

## Stable task IDs

New and converted tasks receive a UUID in the `id` frontmatter property. The ID stays the same when a task file is renamed or moved, so integrations can refer to a task without depending on its path.
New and converted tasks receive a UUID in the `id` frontmatter property. The property key can be changed under **Settings → TaskNotes → Properties → Metadata & integration properties → Task ID**. The ID stays the same when a task file is renamed or moved, so integrations can refer to a task without depending on its path.

Existing tasks without an `id` remain valid and are not changed. Path-based integrations continue to work. The JavaScript API adds `getByPath()` and `getById()`; see [JavaScript API](javascript-api.md).

Expand Down
2 changes: 2 additions & 0 deletions docs/releases/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ When a change has user-facing documentation, include a canonical tasknotes.dev l

- (#2615) Added **Hide top-level subtasks** to the Calendar view's list (Agenda) layout and the month view's selected day panel, as in Task List and Kanban. When on, a subtask whose parent task is listed on the same day shows only under the parent's expanded subtasks instead of also as its own row. A subtask whose parent isn't listed that day keeps its own row. See [Agenda View](https://tasknotes.dev/views/agenda-view/#customization).
- Thanks to @tistieom for the request
- (#2574) The task ID property can now be remapped like other task properties, under **Settings → TaskNotes → Properties → Metadata & integration properties → Task ID**. It defaults to `id`, so existing vaults are unchanged. When a collection's task type maps the ID to another property, TaskNotes uses that property. See [Task Properties](https://tasknotes.dev/settings/task-properties/#metadata-properties).
- Thanks to @minchinweb for the request

## Changed

Expand Down
1 change: 1 addition & 0 deletions docs/settings/task-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ Each default reminder can be:

These properties are system-managed and typically only require property key configuration:

- **Task ID**: The task's stable ID (default: `id`). Change it if your notes already use `id` for something else, for example `tasknote_id`. Existing notes keep their IDs under the old key until you rename it in them.
- **Date Created**: When the task was created
- **Date Modified**: When the task was last modified
- **Completed Date**: When the task was completed
Expand Down
75 changes: 75 additions & 0 deletions e2e/issues/issue-2574-remappable-id.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/**
* Issue #2574: the stable task ID property can be remapped like other fields.
*
* Remaps `id` to `tasknote_id`, then checks the settings page, a newly
* created task and ID lookup. (The e2e vault has no mdbase collection; the
* generated task type is covered by unit tests.) The mapping is restored and
* the created task deleted afterwards.
*
* @see https://github.com/callumalpass/tasknotes/issues/2574
*/

import { test, expect } from '@playwright/test';
import { launchObsidian, closeObsidian, ObsidianApp, openTaskNotesSettings } from '../obsidian';

let app: ObsidianApp;

test.describe('Issue #2574: remappable task ID', () => {
test.beforeAll(async () => {
app = await launchObsidian();
});

test.afterAll(async () => {
if (app) {
await app.page.evaluate(async () => {
const plugin = (window as any).app.plugins.plugins.tasknotes;
if (plugin.settings.fieldMapping.id !== 'id') {
plugin.settings.fieldMapping.id = 'id';
await plugin.saveSettings();
}
});
await closeObsidian(app);
}
});

test('writes and reads the ID under the mapped property', async () => {
const page = app.page;

expect(
await page.evaluate(() => (window as any).app.plugins.plugins.tasknotes.settings.fieldMapping.id)
).toBe('id');

await page.evaluate(async () => {
const plugin = (window as any).app.plugins.plugins.tasknotes;
plugin.settings.fieldMapping.id = 'tasknote_id';
await plugin.saveSettings();
});

const result = await page.evaluate(async () => {
const obsidian = (window as any).app;
const plugin = obsidian.plugins.plugins.tasknotes;
const { file, taskInfo } = await plugin.taskService.createTask(
{ title: 'Issue 2574 remapped id' },
{ applyDefaults: false }
);
const content: string = await obsidian.vault.read(file);
let byId: string[] = [];
for (let attempt = 0; attempt < 20 && byId.length === 0; attempt++) {
byId = (await plugin.cacheManager.getTasksById(taskInfo.id)).map((task: any) => task.path);
if (byId.length === 0) await new Promise((resolve) => setTimeout(resolve, 100));
}
await obsidian.vault.delete(file);
return { id: taskInfo.id as string, path: file.path as string, content, byId };
});

expect(result.id).toMatch(/^[0-9a-f-]{36}$/);
expect(result.content).toContain(`tasknote_id: ${result.id}`);
expect(result.content).not.toMatch(/^id:/m);
expect(result.byId).toEqual([result.path]);

const settings = await openTaskNotesSettings(page, 'Properties/Metadata & integration properties');
await expect(
settings.locator('.vertical-tab-content:visible').getByText('Task ID', { exact: true })
).toBeVisible();
});
});
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
"@modelcontextprotocol/sdk": "1.32.1",
"@tasknotes/calendar": "0.1.12",
"@tasknotes/calendar-service-client": "0.1.2",
"@tasknotes/model": "0.3.0-rc.22",
"@tasknotes/model": "0.3.1",
"ajv": "8.20.0",
"ajv-formats": "3.0.1",
"chrono-node": "^2.7.5",
Expand Down
10 changes: 7 additions & 3 deletions src/api/TaskNotesAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
FILTER_PROPERTIES,
} from "../types";
import type { TaskNotesSettings } from "../types/settings";
import { DEFAULT_FIELD_MAPPING } from "../core/defaultFieldMapping";
import { toUserField } from "../core/fieldMapping";
import { ensureFolderExists } from "../utils/helpers";
import { parseLinkToPath } from "../utils/linkUtils";
import { computeTaskTimeData, computeTimeSummary } from "../utils/timeTrackingUtils";
Expand Down Expand Up @@ -353,6 +355,7 @@ const CORE_FIELD_DEFINITIONS: ReadonlyArray<
const FIELD_MAPPING_KEY_BY_FIELD_ID: Partial<
Record<string, keyof TaskNotesSettings["fieldMapping"]>
> = {
id: "id",
title: "title",
status: "status",
priority: "priority",
Expand Down Expand Up @@ -1062,14 +1065,15 @@ export class TaskNotesAPI implements TaskNotesRuntimeApiV1 {
}

private getFieldDefinitions(): TaskNotesRuntimeFieldDefinition[] {
const mapping = this.plugin.settings.fieldMapping ?? {};
const mapping = this.plugin.settings.fieldMapping ?? DEFAULT_FIELD_MAPPING;
const coreFields = CORE_FIELD_DEFINITIONS.map((field) => {
const mappingKey = FIELD_MAPPING_KEY_BY_FIELD_ID[field.id];
const queryField = runtimeFilterPropertyForInternal(field.id);
return {
...field,
frontmatterKey:
field.id === "id" ? "id" : mappingKey ? mapping[mappingKey] : undefined,
frontmatterKey: mappingKey
? toUserField(mapping, mappingKey)
: undefined,
queryable: !!queryField,
sortable: queryField?.sortable ?? false,
groupable: queryField?.groupable ?? false,
Expand Down
4 changes: 4 additions & 0 deletions src/core/defaultFieldMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import type { FieldMapping } from "../types";
/** Default frontmatter property for a pending moved recurring occurrence's original rule date. */
export const DEFAULT_RECURRENCE_ORIGINAL_DATE_PROPERTY = "recurrence_original_date";

/** Default frontmatter property for a task's stable identity. */
export const DEFAULT_ID_PROPERTY = "id";

export const DEFAULT_FIELD_MAPPING: FieldMapping = {
...MODEL_DEFAULT_FIELD_MAPPING,
id: DEFAULT_ID_PROPERTY,
recurrenceOriginalDate: DEFAULT_RECURRENCE_ORIGINAL_DATE_PROPERTY,
};
20 changes: 13 additions & 7 deletions src/core/fieldMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import type {
TaskInfo,
} from "../types";
import type { UserMappedField } from "../types/settings";
import { DEFAULT_RECURRENCE_ORIGINAL_DATE_PROPERTY } from "./defaultFieldMapping";
import { DEFAULT_ID_PROPERTY, DEFAULT_RECURRENCE_ORIGINAL_DATE_PROPERTY } from "./defaultFieldMapping";
import { normalizeStringArrayValue } from "./nullableListNormalization";

export {
Expand All @@ -47,17 +47,23 @@ export {
VALID_DEPENDENCY_RELTYPES,
};

// The shared model mapping does not know about `recurrenceOriginalDate`, and settings saved
// before the field existed do not contain it. These wrappers resolve the property name
// (falling back to the default) and handle the field around the model functions.
// Settings saved before `id` and `recurrenceOriginalDate` were mappable do not contain
// them. These wrappers resolve both property names (falling back to the defaults) and
// handle `recurrenceOriginalDate` around the model functions.

type ResolvedFieldMapping = FieldMapping & { recurrenceOriginalDate: string };
type ResolvedFieldMapping = FieldMapping & { id: string; recurrenceOriginalDate: string };

function withResolvedMapping(mapping: FieldMapping): ResolvedFieldMapping {
if (typeof mapping.recurrenceOriginalDate === "string") {
const hasId = typeof mapping.id === "string" && mapping.id.trim().length > 0;
if (hasId && typeof mapping.recurrenceOriginalDate === "string") {
return mapping as ResolvedFieldMapping;
}
return { ...mapping, recurrenceOriginalDate: DEFAULT_RECURRENCE_ORIGINAL_DATE_PROPERTY };
return {
...mapping,
id: hasId ? (mapping.id as string) : DEFAULT_ID_PROPERTY,
recurrenceOriginalDate:
mapping.recurrenceOriginalDate ?? DEFAULT_RECURRENCE_ORIGINAL_DATE_PROPERTY,
};
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/de/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11307,6 +11307,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "Die Aufgabe hat weder ein Planungs- noch ein Fälligkeitsdatum für die Synchronisierung"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "Aufgaben-ID"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/en/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11309,6 +11309,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "Task has no scheduled or due date to sync"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "Task ID"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/es/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11309,6 +11309,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "La tarea no tiene fecha programada o de vencimiento para sincronizar"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "ID de la tarea"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/fr/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11309,6 +11309,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "La tâche n''a pas de date planifiée ou d''échéance à synchroniser"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "ID de la tâche"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/it/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11309,6 +11309,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "L'attività non ha una data pianificata o una data di scadenza per la sincronizzazione"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "ID attività"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/ja/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11308,6 +11308,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "タスクに同期する予定日または期限がありません"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "タスクID"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/ko/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11308,6 +11308,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "동기화할 예정일 또는 마감일이 없습니다"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "작업 ID"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/pt/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11310,6 +11310,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "Tarefa não tem data agendada ou de vencimento para sincronizar"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "ID da tarefa"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/ru/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11309,6 +11309,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "У задачи нет запланированной даты или срока для синхронизации"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "ID задачи"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
5 changes: 5 additions & 0 deletions src/i18n/locales/zh/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -11306,6 +11306,11 @@ msgctxt "settings.integrations.googleCalendarExport.notices.noDateToSync"
msgid "Task has no scheduled or due date to sync"
msgstr "任务没有可同步的计划日期或截止日期"

#: src/settings/native/properties.ts
msgctxt "settings.taskProperties.properties.id.name"
msgid "Task ID"
msgstr "任务 ID"

#: src/settings/native/general.ts
msgctxt "settings.general.taskIdentification.header"
msgid "Task identification"
Expand Down
Loading
Loading