-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
edited notes: decouple from ribbon and recognize TODAY keyword #7704
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
Closed
contributor
wants to merge
23
commits into
TriliumNext:main
from
contributor:edited-notes-recognize-keywords
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
6134722
edited notes: move edited-notes related code to own module
contributor fda2fb9
edited notes: recognize dateNote label value TODAY, MONTH, YEAR
contributor f5ad2ca
edited notes: handle timezone differences between client and server
contributor 9563bdc
edited notes: force tests to run in UTC timezone
contributor d7f7ced
edited notes: better docstring for resolveDateParams
contributor cce2bc7
lint format
contributor 152c7ae
edited notes: extract sqlquery var for eslint to recognize indentation
contributor bcb8f29
edited notes: move formatMap on module level
contributor 9892298
edited notes: extendable EditedNotesResponse
contributor dd9f791
edited notes: return limit in response
contributor 452b838
edited notes: add happy path tests
contributor e18fc4c
edited notes: more descriptive name dateNoteLabelKeywordToDateFilter
contributor 366a8bd
edited notes: better names in tests
contributor e1170b2
edited notes: recognize not valid dates/keywords, return 0 limit to c…
contributor 0ee7a4e
edited notes: add positive delta test
contributor 00770dc
edited notes: more restrictive check
contributor d3c0e8b
edited notes: do not shadow variable
contributor f083908
edited notes: use parameterized limit
contributor 2a65b85
edited notes: allow spaces between keyword and delta in #dateNote
contributor 0cec3c7
make EditedNotes standalone component independent from ribbon
contributor 4006743
rename conflicting type name
contributor 01f571e
edited notes: handle promise rejection
contributor fb2dd0b
edited notes: better reuse of EditedNotes component with showNotePath…
contributor 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { useEffect, useState } from "preact/hooks"; | ||
| import { EditedNotesResponse, EditedNote } from "@triliumnext/commons"; | ||
| import server from "../services/server"; | ||
| import { t } from "../services/i18n"; | ||
| import froca from "../services/froca"; | ||
| import NoteLink from "./react/NoteLink"; | ||
| import { joinElements } from "./react/react_utils"; | ||
|
|
||
| interface EditedNotesProps { | ||
| noteId?: string, | ||
| dateFilter: string, | ||
| showNotePath?: boolean, | ||
| } | ||
|
|
||
| export default function EditedNotes({ noteId, dateFilter, showNotePath = true } : EditedNotesProps) { | ||
| const [ editedNotes, setEditedNotes ] = useState<EditedNote[]>(); | ||
|
|
||
| useEffect(() => { | ||
| if (!noteId || !dateFilter) return; | ||
| server.get<EditedNotesResponse>(`edited-notes/${dateFilter}`) | ||
| .then(async response => { | ||
| const filteredNotes = response.notes.filter((n) => n.noteId !== noteId); | ||
| const noteIds = filteredNotes.flatMap((n) => n.noteId); | ||
| await froca.getNotes(noteIds, true); // preload all at once | ||
| setEditedNotes(filteredNotes); | ||
| }) | ||
| .catch(err => { | ||
| console.error("Failed to fetch edited notes:", err); | ||
| setEditedNotes([]); | ||
| }); | ||
| }, [noteId, dateFilter]); | ||
|
|
||
| return ( | ||
| <> | ||
| {editedNotes?.length ? ( | ||
| <div className="edited-notes-list use-tn-links"> | ||
| {joinElements(editedNotes.map(editedNote => { | ||
| return ( | ||
| <span className="edited-note-line"> | ||
| {editedNote.isDeleted ? ( | ||
| <i>{`${editedNote.title} ${t("edited_notes.deleted")}`}</i> | ||
| ) : ( | ||
| <> | ||
| {editedNote.notePath ? <NoteLink notePath={editedNote.notePath} showNotePath={showNotePath} /> : <span>{editedNote.title}</span>} | ||
| </> | ||
| )} | ||
| </span> | ||
| ) | ||
| }), " ")} | ||
| </div> | ||
| ) : ( | ||
| <div className="no-edited-notes-found">{t("edited_notes.no_edited_notes_found")}</div> | ||
| )} | ||
| </> | ||
| ) | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| import cls from '../../services/cls.js'; | ||
| import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest'; | ||
| import { dateNoteLabelKeywordToDateFilter } from "./edited-notes.js"; | ||
|
|
||
| // test date setup | ||
| // client: UTC+1 | ||
| // server: UTC | ||
| // day/month/year is changed when server converts a client date to to UTC | ||
| const clientDate = "2025-01-01 00:11:11.000+0100"; | ||
| const serverDate = "2024-12-31 23:11:11.000Z"; | ||
|
|
||
| // expected values - from client's point of view | ||
| const expectedToday = "2025-01-01"; | ||
| const expectedTodayMinus1 = "2024-12-31"; | ||
| const expectedTodayPlus1 = "2025-01-02"; | ||
| const expectedMonth = "2025-01"; | ||
| const expectedMonthMinus2 = "2024-11"; | ||
| const expectedYear = "2025"; | ||
| const expectedYearMinus1 = "2024"; | ||
|
|
||
| function keywordResolvesToDate(dateStrOrKeyword: string, expectedDate: string) { | ||
| cls.init(() => { | ||
| cls.set("localNowDateTime", clientDate); | ||
| const dateFilter = dateNoteLabelKeywordToDateFilter(dateStrOrKeyword); | ||
| expect(dateFilter.date).toBe(expectedDate); | ||
| }); | ||
| } | ||
|
|
||
| function keywordDoesNotResolve(dateStrOrKeyword: string) { | ||
| cls.init(() => { | ||
| cls.set("localNowDateTime", clientDate); | ||
| const dateFilter = dateNoteLabelKeywordToDateFilter(dateStrOrKeyword); | ||
| expect(dateFilter.date).toBe(null); | ||
| }); | ||
| } | ||
|
|
||
| describe("edited-notes::dateNoteLabelKeywordToDateFilter", () => { | ||
| beforeEach(() => { | ||
| vi.stubEnv("TZ", "UTC"); | ||
| vi.useFakeTimers(); | ||
| vi.setSystemTime(new Date(serverDate)); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.unstubAllEnvs(); | ||
| // Restore real timers after each test | ||
| vi.useRealTimers(); | ||
| }); | ||
|
|
||
| it("resolves 'TODAY' to today's date", () => { | ||
| keywordResolvesToDate("TODAY", expectedToday); | ||
| }); | ||
|
|
||
| it("resolves 'TODAY+1' to tomorrow's date", () => { | ||
| keywordResolvesToDate("TODAY+1", expectedTodayPlus1); | ||
| }); | ||
|
|
||
| it("resolves 'MONTH' to current month", () => { | ||
| keywordResolvesToDate("MONTH", expectedMonth); | ||
| }); | ||
|
|
||
| it("resolves 'YEAR' to current year", () => { | ||
| keywordResolvesToDate("YEAR", expectedYear); | ||
| }); | ||
|
|
||
| it("resolves 'TODAY-1' to yesterday's date", () => { | ||
| keywordResolvesToDate("TODAY-1", expectedTodayMinus1); | ||
| }); | ||
|
|
||
| it("resolves 'TODAY - 1' (with spaces) to yesterday's date", () => { | ||
| keywordResolvesToDate("TODAY - 1", expectedTodayMinus1); | ||
| keywordResolvesToDate("TODAY- 1", expectedTodayMinus1); | ||
| keywordResolvesToDate("TODAY -1", expectedTodayMinus1); | ||
| }); | ||
|
|
||
| it("resolves 'MONTH-2' to 2 months ago", () => { | ||
| keywordResolvesToDate("MONTH-2", expectedMonthMinus2); | ||
| }); | ||
|
|
||
| it("resolves 'YEAR-1' to last year", () => { | ||
| keywordResolvesToDate("YEAR-1", expectedYearMinus1); | ||
| }); | ||
|
|
||
| it("returns original string for day", () => { | ||
| keywordResolvesToDate("2020-12-31", "2020-12-31"); | ||
| }); | ||
|
|
||
| it("returns original string for month", () => { | ||
| keywordResolvesToDate("2020-12", "2020-12"); | ||
| }); | ||
|
|
||
| it("returns original string for partial month", () => { | ||
| keywordResolvesToDate("2020-1", "2020-1"); | ||
| }); | ||
|
|
||
| it("returns original string for partial month with trailing dash", () => { | ||
| keywordResolvesToDate("2020-", "2020-"); | ||
| }); | ||
|
|
||
| it("returns original string for year", () => { | ||
| keywordResolvesToDate("2020", "2020"); | ||
| }); | ||
|
|
||
| it("returns original string for potentially partial day", () => { | ||
| keywordResolvesToDate("2020-12-1", "2020-12-1"); | ||
| }); | ||
|
|
||
| it("returns null for partial year", () => { | ||
| keywordDoesNotResolve("202"); | ||
| }); | ||
|
|
||
| it("returns null for arbitrary string", () => { | ||
| keywordDoesNotResolve("FOO"); | ||
| }); | ||
|
|
||
| it("returns null for missing delta", () => { | ||
| keywordDoesNotResolve("TODAY-"); | ||
| }); | ||
|
|
||
| it("resolves 'today' (lowercase) to today's date", () => { | ||
| keywordResolvesToDate("today", expectedToday); | ||
| }); | ||
|
|
||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.