-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: add childTitleTemplate attribute and update titleTemplate attri… #8787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
monotok
wants to merge
5
commits into
TriliumNext:main
Choose a base branch
from
monotok:feature/titleTemplate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d97f646
feat: add childTitleTemplate attribute and update titleTemplate attri…
monotok e116643
docs: update the user guide with information on the new label and the…
monotok 2dbf4b0
test: add unit tests for notes title derived from template label
monotok 1bf7148
test: add unit test for childTitleTemplate
monotok 0399746
test: add unit test for childTitleTemplate and titleTemplate attribut…
monotok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 4 additions & 8 deletions
12
apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
64 changes: 47 additions & 17 deletions
64
...rver/src/assets/doc_notes/en/User Guide/User Guide/Advanced Usage/Default Note Title.html
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { beforeAll, describe, expect, it } from "vitest"; | ||
| import sql_init from "./sql_init"; | ||
| import cls from "./cls"; | ||
| import {newEntityId} from "./utils"; | ||
| import notes from "./notes"; | ||
| import becca from "../becca/becca"; | ||
| import {buildNote} from "../test/becca_easy_mocking"; | ||
|
|
||
| describe("Notes Title", () => { | ||
| beforeAll(async () => { | ||
| sql_init.initializeDb(); | ||
| await sql_init.dbReady; | ||
| }); | ||
|
|
||
| describe("setting titleTemplate label should set the notes title when created from template", () => { | ||
| it("uses #titleTemplate from the selected template note when creating a note from template", () => { | ||
| const parentNote = buildNote({ | ||
| title: "randomNote" | ||
| }); | ||
|
|
||
| cls.init(() => { | ||
| const templateNoteId = newEntityId(); | ||
|
|
||
| const templateNote = notes.createNewNote({ | ||
| parentNoteId: parentNote.noteId, | ||
| noteId: templateNoteId, | ||
| title: "Test template", | ||
| type: "text", | ||
| content: "" | ||
| }).note; | ||
|
|
||
| templateNote.setLabel("titleTemplate", "Hello from template"); | ||
| templateNote.setLabel("template"); | ||
| templateNote.invalidateThisCache(); // ensures getLabelValue sees the new label | ||
|
|
||
| const created = notes.createNewNote({ | ||
| parentNoteId: parentNote.noteId, | ||
| templateNoteId: templateNote.noteId, | ||
| title: null as never, // let notes service derive the title from the template label | ||
| type: "text", | ||
| content: "" | ||
| }).note; | ||
|
|
||
| expect(created.title).toBe("Hello from template"); | ||
|
|
||
| // sanity: ensure the template note is actually the one we set up | ||
| expect(becca.getNote(templateNoteId)?.getLabelValue("titleTemplate")).toBe("Hello from template"); | ||
| }); | ||
| }); | ||
|
|
||
| it("uses #childTitleTemplate from the parent note when creating a note under a parent with label set", () => { | ||
| const parentNote = buildNote({ | ||
| title: "randomNote", | ||
| "#childTitleTemplate": "my child title", | ||
| children: [ | ||
| { | ||
| title: "childNote", | ||
| } | ||
| ] | ||
| }); | ||
|
|
||
| cls.init(() => { | ||
|
|
||
| const created = notes.createNewNote({ | ||
| parentNoteId: parentNote.noteId, | ||
| title: null as never, // let notes service derive the title from the template label | ||
| type: "text", | ||
| content: "" | ||
| }).note; | ||
|
|
||
| expect(created.title).toBe("my child title"); | ||
| }); | ||
| }); | ||
|
|
||
| it("uses #titleTemplate from the selected template note even if the parent note has #childTitleTemplate set", () => { | ||
| const templateParentNote = buildNote({ | ||
| title: "randomNote" | ||
| }); | ||
|
|
||
| const parentNote = buildNote({ | ||
| title: "randomNote", | ||
| "#childTitleTemplate": "my child title", | ||
| children: [ | ||
| { | ||
| title: "childNote", | ||
| } | ||
| ] | ||
| }); | ||
|
|
||
| cls.init(() => { | ||
| const templateNoteId = newEntityId(); | ||
|
|
||
| const templateNote = notes.createNewNote({ | ||
| parentNoteId: templateParentNote.noteId, | ||
| noteId: templateNoteId, | ||
| title: "Test template", | ||
| type: "text", | ||
| content: "" | ||
| }).note; | ||
|
|
||
| templateNote.setLabel("titleTemplate", "Hello from template"); | ||
| templateNote.setLabel("template"); | ||
| templateNote.invalidateThisCache(); // ensures getLabelValue sees the new label | ||
|
|
||
| const created = notes.createNewNote({ | ||
| parentNoteId: parentNote.noteId, | ||
| templateNoteId: templateNote.noteId, | ||
| title: null as never, // let notes service derive the title from the template label | ||
| type: "text", | ||
| content: "" | ||
| }).note; | ||
|
|
||
| expect(created.title).toBe("Hello from template"); | ||
|
|
||
| // sanity: ensure the template note is actually the one we set up | ||
| expect(becca.getNote(templateNoteId)?.getLabelValue("titleTemplate")).toBe("Hello from template"); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
resolveTitleTemplatefunction should be improved to handle two important cases:titleTemplateon the parent note. Since this was the previous behavior, removing it without a fallback will break existing user setups. Adding a fallback ensures that existing folders withtitleTemplatecontinue to work until users migrate tochildTitleTemplate.child:templaterelation, it will eventually inherit that template. The title should be resolved from that template'stitleTemplateif no explicitchildTitleTemplateis defined on the parent. The current logic only checksparams.templateNoteId, which is typically only set when a template is explicitly chosen in the UI.