-
Notifications
You must be signed in to change notification settings - Fork 68
NotesFactory and Tasks function #655
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
Open
mlevison
wants to merge
12
commits into
NotePlan:main
Choose a base branch
from
mlevison:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
42130d6
Initial Checkin GenAITaskChecker
mlevison 6b2b551
Merge branch 'NotePlan:main' into main
mlevison a729394
Plugin Initialized and First Test Case working
mlevison 9cf6d95
Add limited version of getAllTasksForCurrentNote
mlevison d12e13d
Merge branch 'NotePlan:main' into main
mlevison 6936237
Delete task code mlevison.plugin
mlevison b627e54
Added NoteFactory and Task Functions
mlevison 3ade7ad
Revert "Delete task code mlevison.plugin"
mlevison d58b4e9
Revert "Add limited version of getAllTasksForCurrentNote"
mlevison 2e92085
Revert "Plugin Initialized and First Test Case working"
mlevison 60a3518
Revert "Initial Checkin GenAITaskChecker"
mlevison cc20cc4
Update tasks.test..js
mlevison 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
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,55 @@ | ||
export const noteWIthOpenAndCancelledTasks = { | ||
paragraphs: [ | ||
{ type: 'title', lineIndex: 0, content: 'Title', headingLevel: 1 }, | ||
{ type: 'empty', lineIndex: 1 }, | ||
{ type: 'title', lineIndex: 2, content: 'Tasks for 3.4.22', headingLevel: 2 }, | ||
{ type: 'open', lineIndex: 3, content: 'task 1' }, | ||
{ type: 'title', lineIndex: 4, content: 'Journal for 3.4.22' }, | ||
{ type: 'list', lineIndex: 5, content: 'first journal entry' }, | ||
{ type: 'list', lineIndex: 6, content: 'second journal entry' }, | ||
{ type: 'empty', lineIndex: 7 }, | ||
{ type: 'title', lineIndex: 8, content: 'Done ...', headingLevel: 2 }, | ||
{ type: 'title', lineIndex: 9, content: 'Cancelled', headingLevel: 2 }, | ||
{ type: 'cancelled', lineIndex: 10, content: 'task cancelled' }, | ||
], | ||
} | ||
|
||
export const noteWIthDoneAndScheduledTasks = { | ||
paragraphs: [ | ||
{ type: 'title', lineIndex: 0, content: 'Title', headingLevel: 1 }, | ||
{ type: 'empty', lineIndex: 1 }, | ||
{ type: 'title', lineIndex: 2, content: 'Tasks for 3.4.22', headingLevel: 2 }, | ||
{ type: 'scheduled', lineIndex: 3, content: 'task 1' }, | ||
{ type: 'title', lineIndex: 4, content: 'Journal for 3.4.22' }, | ||
{ type: 'list', lineIndex: 5, content: 'first journal entry' }, | ||
{ type: 'list', lineIndex: 6, content: 'second journal entry' }, | ||
{ type: 'empty', lineIndex: 7 }, | ||
{ type: 'title', lineIndex: 8, content: 'Done ...', headingLevel: 2 }, | ||
{ type: 'done', lineIndex: 10, content: 'task finished' }, | ||
], | ||
} | ||
|
||
export const noteWithOpenAndDoneTasks = { | ||
paragraphs: [ | ||
{ type: 'title', lineIndex: 0, content: 'Title', headingLevel: 1 }, | ||
{ type: 'empty', lineIndex: 1 }, | ||
{ type: 'open', lineIndex: 2, content: 'Open task 1' }, | ||
{ type: 'open', lineIndex: 3, content: 'Open task 2' }, | ||
{ type: 'done', lineIndex: 4, content: 'Done task' }, | ||
], | ||
} | ||
|
||
export const noteWithOneTaskOfEachType = { | ||
paragraphs: [ | ||
{ type: 'title', lineIndex: 0, content: 'Title', headingLevel: 1 }, | ||
{ type: 'empty', lineIndex: 1 }, | ||
{ type: 'open', lineIndex: 2, content: 'Open task 1' }, | ||
{ type: 'scheduled', lineIndex: 3, content: 'Scheduled task 2' }, | ||
{ type: 'done', lineIndex: 4, content: 'Done task' }, | ||
{ type: 'cancelled', lineIndex: 5, content: 'Cancelled task' }, | ||
{ type: 'checklist', lineIndex: 6, content: 'checklist' }, | ||
{ type: 'checklistDone', lineIndex: 7, content: 'checklistDone' }, | ||
{ type: 'checklistCancelled', lineIndex: 8, content: 'checklistCancelled' }, | ||
{ type: 'checklistScheduled', lineIndex: 9, content: 'checklistScheduled' }, | ||
], | ||
} |
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,78 @@ | ||
/* global jest, describe, test, expect, beforeAll, afterAll, beforeEach, afterEach */ | ||
import { noteWIthOpenAndCancelledTasks, noteWIthDoneAndScheduledTasks, noteWithOpenAndDoneTasks, noteWithOneTaskOfEachType } from '@mocks/factories/noteFactory' | ||
|
||
import { getAllTasksFromCurrentNote } from '../tasks.js' | ||
import * as sorting from '@helpers/sorting' | ||
import { CustomConsole } from '@jest/console' // see note below | ||
import { Calendar, Clipboard, CommandBar, DataStore, Editor, NotePlan, simpleFormatter, Paragraph /* Note, mockWasCalledWithString, Paragraph */ } from '@mocks/index' | ||
|
||
beforeAll(() => { | ||
global.Calendar = Calendar | ||
global.Clipboard = Clipboard | ||
global.CommandBar = CommandBar | ||
global.DataStore = DataStore | ||
global.Editor = Editor | ||
global.NotePlan = NotePlan | ||
global.console = new CustomConsole(process.stdout, process.stderr, simpleFormatter) // minimize log footprint | ||
DataStore.settings['_logLevel'] = 'none' //change this to DEBUG to get more logging (or 'none' for none) | ||
}) | ||
|
||
describe('mlevison.GenAITaskChecker', () => { | ||
describe('test getTasksByType', () => { | ||
test('prove Open and Cancelled Tasks found in sample note', () => { | ||
const foundTasks = sorting.getTasksByType(noteWIthOpenAndCancelledTasks.paragraphs) | ||
|
||
expect(foundTasks.open.length).toBe(1) | ||
expect(foundTasks.done.length).toBe(0) | ||
expect(foundTasks.cancelled.length).toBe(1) | ||
expect(foundTasks.scheduled.length).toBe(0) | ||
expect(foundTasks.checklist.length).toBe(0) | ||
expect(foundTasks.checklistDone.length).toBe(0) | ||
expect(foundTasks.checklistCancelled.length).toBe(0) | ||
expect(foundTasks.checklistScheduled.length).toBe(0) | ||
}) | ||
|
||
test('prove Done Tasks found in sample note', () => { | ||
const foundTasks = sorting.getTasksByType(noteWIthDoneAndScheduledTasks.paragraphs) | ||
|
||
expect(foundTasks.open.length).toBe(0) | ||
expect(foundTasks.done.length).toBe(1) | ||
expect(foundTasks.cancelled.length).toBe(0) | ||
expect(foundTasks.scheduled.length).toBe(1) | ||
expect(foundTasks.checklist.length).toBe(0) | ||
expect(foundTasks.checklistDone.length).toBe(0) | ||
expect(foundTasks.checklistCancelled.length).toBe(0) | ||
expect(foundTasks.checklistScheduled.length).toBe(0) | ||
}) | ||
}) | ||
|
||
describe('getAllTasksFromCurrentNote', () => { | ||
test('returns open and done tasks from current note', () => { | ||
const tasks = getAllTasksFromCurrentNote(noteWithOpenAndDoneTasks) | ||
expect(tasks.length).toBe(3) | ||
expect(tasks[0].content).toBe('Open task 1') | ||
expect(tasks[1].content).toBe('Open task 2') | ||
expect(tasks[2].content).toBe('Done task') | ||
}) | ||
|
||
test('returns open and cancelled tasks from current note', () => { | ||
const tasks = getAllTasksFromCurrentNote(noteWIthOpenAndCancelledTasks) | ||
expect(tasks.length).toBe(2) | ||
expect(tasks[0].content).toBe('task 1') | ||
expect(tasks[1].content).toBe('task cancelled') | ||
}) | ||
|
||
test('returns one of each task types from current note', () => { | ||
const tasks = getAllTasksFromCurrentNote(noteWithOneTaskOfEachType) | ||
expect(tasks.length).toBe(8) | ||
expect(tasks[0].content).toBe('Open task 1') | ||
expect(tasks[1].content).toBe('Scheduled task 2') | ||
expect(tasks[2].content).toBe('Done task') | ||
expect(tasks[3].content).toBe('Cancelled task') | ||
expect(tasks[4].content).toBe('checklist') | ||
expect(tasks[5].content).toBe('checklistScheduled') | ||
expect(tasks[6].content).toBe('checklistDone') | ||
expect(tasks[7].content).toBe('checklistCancelled') | ||
}) | ||
}) | ||
}) |
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,10 @@ | ||
import { getTasksByType } from './sorting' | ||
|
||
export function getAllTasksFromCurrentNote(currentNote) { | ||
// This function will extract all tasks from the current note and return them grouped by type | ||
// It uses the getTasksByType function to categorize the tasks | ||
const groupedTasks = getTasksByType(currentNote.paragraphs) | ||
|
||
return groupedTasks.open.concat(groupedTasks.scheduled, groupedTasks.done, groupedTasks.cancelled, groupedTasks.checklist, groupedTasks.checklistScheduled, | ||
groupedTasks.checklistDone, groupedTasks.checklistCancelled) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mlevison This is a great start. Thanks! A starting observation:
There are a always a lot of ways to deal with these two things. Look forward to hearing your thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And on a different 'note' (ha ha), I would even at this early stage suggest adding a richer set of content. I.e. note links, dates, emojis, URLs, Markdown links, non-Roman characters. Each of these has caused issues in the past.