Skip to content
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

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

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
5 changes: 3 additions & 2 deletions packages/app-desktop/gui/NoteEditor/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> {
Expand All @@ -23,15 +24,15 @@ 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<any> {
export async function formNoteToNote(formNote: FormNote): Promise<NoteEntity> {
return {
id: formNote.id,
// Should also include parent_id and deleted_time so that the reducer
// can know in which folder the note should go when saving.
// 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,
};
Expand Down
1 change: 1 addition & 0 deletions packages/app-desktop/gui/NoteEditor/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
34 changes: 34 additions & 0 deletions packages/app-desktop/gui/NoteEditor/utils/useFormNote.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();
});
Comment on lines +89 to +117
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how useful this automated test is — the bug is related to the interaction of useFormNote with reducer.ts. As such, an integrated/end-to-end test would make more sense. However, creating conflict notes in Playwright end-to-end tests is more complicated than creating conflicts in Jest tests.


// 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 () => {
Expand Down
1 change: 1 addition & 0 deletions packages/app-desktop/gui/NoteEditor/utils/useFormNote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading