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

Desktop: Fix importing completed tasks (#10528)

This commit is contained in:
Henry Heino 2024-06-04 01:52:34 -07:00 committed by GitHub
parent e049698012
commit 0938dc9d52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 2 deletions

View File

@ -0,0 +1,5 @@
---
title: Not a task
---
This is a note.

View File

@ -0,0 +1,6 @@
---
title: Task
completed?: yes
---
This is a test. This task should import as completed.

View File

@ -184,4 +184,24 @@ describe('InteropService_Importer_Md_frontmatter: importMetadata', () => {
const tags = (await Tag.tagsByNoteId(note.id)).map(tag => tag.title).sort();
expect(tags).toMatchObject(['tag1', 'tag2']);
});
it('should import completed tasks', async () => {
const note = await importTestFile('task_completed.md');
expect(note.title).toBe('Task');
expect(note.body).toBe('This is a test. This task should import as completed.\n');
expect(note.is_todo).toBe(1);
expect(note.todo_completed).toBeGreaterThan(0);
});
it('should import notes that are not tasks', async () => {
const note = await importTestFile('not_a_task.md');
expect(note).toMatchObject({
title: 'Not a task',
body: 'This is a note.',
is_todo: 0,
todo_completed: 0,
});
});
});

View File

@ -101,7 +101,7 @@ export const serialize = async (modNote: NoteEntity, tagTitles: string[]) => {
};
function isTruthy(str: string): boolean {
return str.toLowerCase() in ['true', 'yes'];
return ['true', 'yes'].includes(str.toLowerCase());
}
// Enforces exactly 2 spaces in front of list items
@ -227,7 +227,7 @@ export const parse = (note: string): ParsedMeta => {
if (metadata.is_todo) {
if (isTruthy(md['completed?'])) {
// Completed time isn't preserved, so we use a sane choice here
metadata['todo_completed'] = metadata['user_updated_time'];
metadata['todo_completed'] = metadata['user_updated_time'] ?? Date.now();
}
if ('due' in md) {
const due_date = time.anythingToMs(md['due'], null);