1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Desktop: Fixes #10737: Fix Fix editing notes in "Conflicts" causes them to temporarily vanish (#10913)

This commit is contained in:
Henry Heino 2024-08-22 13:53:39 -07:00 committed by GitHub
parent 02bdb7a79c
commit 33599324d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 39 additions and 2 deletions

View File

@ -2,6 +2,7 @@ import { FormNote } from './types';
import HtmlToMd from '@joplin/lib/HtmlToMd'; import HtmlToMd from '@joplin/lib/HtmlToMd';
import Note from '@joplin/lib/models/Note'; import Note from '@joplin/lib/models/Note';
import { NoteEntity } from '@joplin/lib/services/database/types';
const { MarkupToHtml } = require('@joplin/renderer'); const { MarkupToHtml } = require('@joplin/renderer');
export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss: string): Promise<string> { export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss: string): Promise<string> {
@ -23,8 +24,7 @@ export async function htmlToMarkdown(markupLanguage: number, html: string, origi
return newBody; return newBody;
} }
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied export async function formNoteToNote(formNote: FormNote): Promise<NoteEntity> {
export async function formNoteToNote(formNote: FormNote): Promise<any> {
return { return {
id: formNote.id, id: formNote.id,
// Should also include parent_id and deleted_time so that the reducer // Should also include parent_id and deleted_time so that the reducer
@ -32,6 +32,7 @@ export async function formNoteToNote(formNote: FormNote): Promise<any> {
// https://discourse.joplinapp.org/t/experimental-wysiwyg-editor-in-joplin/6915/57?u=laurent // https://discourse.joplinapp.org/t/experimental-wysiwyg-editor-in-joplin/6915/57?u=laurent
parent_id: formNote.parent_id, parent_id: formNote.parent_id,
deleted_time: formNote.deleted_time, deleted_time: formNote.deleted_time,
is_conflict: formNote.is_conflict,
title: formNote.title, title: formNote.title,
body: formNote.body, body: formNote.body,
}; };

View File

@ -148,6 +148,7 @@ export interface FormNote {
body: string; body: string;
parent_id: string; parent_id: string;
is_todo: number; is_todo: number;
is_conflict?: number;
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied
bodyEditorContent?: any; bodyEditorContent?: any;
markup_language: number; markup_language: number;

View File

@ -5,6 +5,7 @@ import useFormNote, { HookDependencies } from './useFormNote';
import shim from '@joplin/lib/shim'; import shim from '@joplin/lib/shim';
import Resource from '@joplin/lib/models/Resource'; import Resource from '@joplin/lib/models/Resource';
import { join } from 'path'; import { join } from 'path';
import { formNoteToNote } from '.';
const defaultFormNoteProps: HookDependencies = { const defaultFormNoteProps: HookDependencies = {
syncStarted: false, syncStarted: false,
@ -82,6 +83,39 @@ describe('useFormNote', () => {
formNote.unmount(); 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 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 () => { // it('should reload the note when it is changed outside of the editor', async () => {

View File

@ -101,6 +101,7 @@ export default function useFormNote(dependencies: HookDependencies) {
is_todo: n.is_todo, is_todo: n.is_todo,
parent_id: n.parent_id, parent_id: n.parent_id,
deleted_time: n.deleted_time, deleted_time: n.deleted_time,
is_conflict: n.is_conflict,
bodyWillChangeId: 0, bodyWillChangeId: 0,
bodyChangeId: 0, bodyChangeId: 0,
markup_language: n.markup_language, markup_language: n.markup_language,