diff --git a/packages/app-desktop/gui/NoteEditor/utils/index.ts b/packages/app-desktop/gui/NoteEditor/utils/index.ts index 3b3189c2c..3de653439 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/index.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/index.ts @@ -2,6 +2,7 @@ import { FormNote } from './types'; import HtmlToMd from '@joplin/lib/HtmlToMd'; import Note from '@joplin/lib/models/Note'; +import { NoteEntity } from '@joplin/lib/services/database/types'; const { MarkupToHtml } = require('@joplin/renderer'); export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss: string): Promise { @@ -23,8 +24,7 @@ export async function htmlToMarkdown(markupLanguage: number, html: string, origi return newBody; } -// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied -export async function formNoteToNote(formNote: FormNote): Promise { +export async function formNoteToNote(formNote: FormNote): Promise { return { id: formNote.id, // Should also include parent_id and deleted_time so that the reducer @@ -32,6 +32,7 @@ export async function formNoteToNote(formNote: FormNote): Promise { // https://discourse.joplinapp.org/t/experimental-wysiwyg-editor-in-joplin/6915/57?u=laurent parent_id: formNote.parent_id, deleted_time: formNote.deleted_time, + is_conflict: formNote.is_conflict, title: formNote.title, body: formNote.body, }; diff --git a/packages/app-desktop/gui/NoteEditor/utils/types.ts b/packages/app-desktop/gui/NoteEditor/utils/types.ts index 1dcbcd834..1f261661a 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/types.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/types.ts @@ -148,6 +148,7 @@ export interface FormNote { body: string; parent_id: string; is_todo: number; + is_conflict?: number; // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied bodyEditorContent?: any; markup_language: number; diff --git a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.test.ts b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.test.ts index e8299b574..08d742ac1 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.test.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.test.ts @@ -5,6 +5,7 @@ import useFormNote, { HookDependencies } from './useFormNote'; import shim from '@joplin/lib/shim'; import Resource from '@joplin/lib/models/Resource'; import { join } from 'path'; +import { formNoteToNote } from '.'; const defaultFormNoteProps: HookDependencies = { syncStarted: false, @@ -82,6 +83,39 @@ describe('useFormNote', () => { formNote.unmount(); }); + + // Lacking is_conflict has previously caused UI issues. See https://github.com/laurent22/joplin/pull/10913 + // for details. + it('should preserve value of is_conflict on save', async () => { + const testNote = await Note.save({ title: 'Test Note!', is_conflict: 1 }); + + const makeFormNoteProps = (): HookDependencies => { + return { + ...defaultFormNoteProps, + noteId: testNote.id, + }; + }; + + const formNote = renderHook(props => useFormNote(props), { + initialProps: makeFormNoteProps(), + }); + await formNote.waitFor(() => { + expect(formNote.result.current.formNote).toMatchObject({ + is_conflict: 1, + title: testNote.title, + }); + }); + + // Should preserve is_conflict after save. + expect(await formNoteToNote(formNote.result.current.formNote)).toMatchObject({ + is_conflict: 1, + deleted_time: 0, + title: testNote.title, + }); + + formNote.unmount(); + }); + // It seems this test is crashing the worker on CI (out of memory), so disabling it for now. // it('should reload the note when it is changed outside of the editor', async () => { diff --git a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts index 86251e4f9..47c0355d9 100644 --- a/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts +++ b/packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts @@ -101,6 +101,7 @@ export default function useFormNote(dependencies: HookDependencies) { is_todo: n.is_todo, parent_id: n.parent_id, deleted_time: n.deleted_time, + is_conflict: n.is_conflict, bodyWillChangeId: 0, bodyChangeId: 0, markup_language: n.markup_language,