Skip to content

Commit

Permalink
TaskAutomations and Plugin Info updates
Browse files Browse the repository at this point in the history
  • Loading branch information
dwertheimer committed Nov 10, 2023
1 parent 2f33736 commit 5788611
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 23 deletions.
46 changes: 46 additions & 0 deletions dwertheimer.TaskAutomations/__tests__/NPTaskScanAndProcess.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,52 @@ describe(`${PLUGIN_NAME}`, () => {
const result = await f.prepareUserAction(origPara, {}, '__remove__')
expect(result).toEqual({ action: 'set', changed: changedPara })
})
test('should set a p1 to !', async () => {
const origPara = { content: `foo` }
const changedPara = { content: `! foo` }
const result = await f.prepareUserAction(origPara, {}, '__p1__')
expect(result).toEqual({ action: '__p1__', changed: changedPara })
})
})
/*
* updatePriority()
*/
describe('updatePriority()' /* function */, () => {
test('should remove the priority', () => {
const before = { content: `foo ! bar` }
const result = f.updatePriority(before, 'p0')
expect(result.content).toEqual(`foo bar`)
})
test('should update p1 of task with no priority', () => {
const before = { content: `foo bar` }
const result = f.updatePriority(before, 'p1')
expect(result.content).toEqual(`! foo bar`)
})
test('should update p2 of task with no priority', () => {
const before = { content: `foo bar` }
const result = f.updatePriority(before, 'p2')
expect(result.content).toEqual(`!! foo bar`)
})
test('should update p3 of task with no priority', () => {
const before = { content: `foo bar` }
const result = f.updatePriority(before, 'p3')
expect(result.content).toEqual(`!!! foo bar`)
})
test('should update p3 of task with prev prio at beginning', () => {
const before = { content: `!! foo bar` }
const result = f.updatePriority(before, 'p3')
expect(result.content).toEqual(`!!! foo bar`)
})
test('should update priority of task with prev prio in middle', () => {
const before = { content: `foo !! bar` }
const result = f.updatePriority(before, 'p3')
expect(result.content).toEqual(`!!! foo bar`)
})
test('should update priority of task with prev prio at end', () => {
const before = { content: `foo bar !` }
const result = f.updatePriority(before, 'p3')
expect(result.content).toEqual(`!!! foo bar`)
})
})
})
})
4 changes: 2 additions & 2 deletions dwertheimer.TaskAutomations/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

## [2.17.0] @dwertheimer 2023-08-29

- change edit to allow for
- opt-click a date return you to edit
- Overdue processing: change edit to allow you to opt-click a date return you to edit
- Overdue processing: added p1,p2,p3 options. Thx @george!

## [2.16.0] @dwertheimer 2023-08-23

Expand Down
4 changes: 2 additions & 2 deletions dwertheimer.TaskAutomations/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"plugin.name": "✅ Task Automations",
"plugin.description": "Automations for handling Tasks:\n- Overdue/Forgotten task scanning\n- Task sorting within a note\n- Copying #tags/@mentions from one task to another\n- Mark all tasks in note open/completed\n- Automatically opening URLs of task lines",
"plugin.author": "@dwertheimer",
"plugin.version": "2.16.99-notReleasedYet",
"plugin.lastUpdateInfo": "2.16.0 Overdue processing: Add move-to-note as list/checklist option",
"plugin.version": "2.17.0",
"plugin.lastUpdateInfo": "2.17.0: Overdue processing: added p1,p2,p3 options. Thx @george!",
"plugin.dependencies": [],
"plugin.requiredFiles": [
"css.plugin.css",
Expand Down
44 changes: 43 additions & 1 deletion dwertheimer.TaskAutomations/src/NPTaskScanAndProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ type RescheduleUserAction =
| '__mdfuture__'
| '__newTask__'
| '__opentask__'
| '__p0__'
| '__p1__'
| '__p2__'
| '__p3__'
| string /* >dateOptions */
| number /* lineIndex of item to pop open */

Expand Down Expand Up @@ -118,7 +122,7 @@ export function getSharedOptions(origPara?: TParagraph | { note: TNote } | null,
}

/**
* Open a note, highlight the task being looked at and prompt user for a choice of what to do with one specific line
* Open a note, highlight the task being looked at and prompt user for a choice of what to do with one specific line/task
* @param {*} origPara
* @returns {Promise<RescheduleUserAction | false>} the user choice or false
*/
Expand All @@ -137,6 +141,10 @@ async function promptUserToActOnLine(origPara: TParagraph /*, updatedPara: TPara
{ label: `✓⏎ Mark done and add follow-up in same note`, value: '__mdhere__' },
{ label: `✓📆 Mark done and add follow-up in future note`, value: '__mdfuture__' },
{ label: `💡 This reminds me...(create new task then continue)`, value: '__newTask__' },
{ label: `x! Remove priority from task`, value: '__p0__' },
{ label: `! Set priority to p1`, value: '__p1__' },
{ label: `!! Set priority to p2`, value: '__p2__' },
{ label: `!!! Set priority to p3`, value: '__p3__' },
...sharedOpts,
{ label: `␡ Delete this line (be sure!)`, value: '__delete__' },
]
Expand All @@ -151,6 +159,20 @@ async function promptUserToActOnLine(origPara: TParagraph /*, updatedPara: TPara
return res
}

/**
* Update a task's priority no matter where it was before
* @param {*} input
* @param {*} newPriority
* @returns
*/
export function updatePriority(input: TParagraph, newPriority: string): TParagraph {
const prioStr = newPriority === 'p1' ? '!' : newPriority === 'p2' ? '!!' : newPriority === 'p3' ? '!!!' : ''
const output = input
output.content = output.content.replace(/!\s*/g, '').replace(/\s+!/g, '')
output.content = `${prioStr ? `${prioStr} ` : ''}${output.content}`.trim()
return output
}

/**
* Given a user choice on a specific action to take on a line, create an {action: string, changed?: TParagraph, userChoice?: string} object for further processing
* @param {TParagraph} origPara
Expand Down Expand Up @@ -207,6 +229,13 @@ export async function prepareUserAction(origPara: TParagraph, updatedPara: TPara
case `__mdfuture__`: {
return { action: userChoice, changed: origPara }
}
case '__p0__':
case '__p1__':
case '__p2__':
case '__p3__': {
logDebug(`prepareUserAction: ${userChoice}`)
return { action: userChoice, changed: updatePriority(origPara, userChoice.replace(/_/g, '')) }
}
case `__today__`: {
origPara.content = replaceArrowDatesInString(origPara.content, '>today')
return { action: 'set', changed: origPara } // dbw NOTE: this said "updatedPara". Not sure how/why that worked before. changing it for React
Expand All @@ -224,6 +253,7 @@ export async function prepareUserAction(origPara: TParagraph, updatedPara: TPara
case '__skip__':
return { action: 'skip', changed: origPara }
}

if (typeof userChoice === 'string' && userChoice[0] === '>') {
origPara.content = replaceArrowDatesInString(origPara.content, userChoice)
return { action: 'set', changed: origPara, userChoice }
Expand Down Expand Up @@ -394,6 +424,18 @@ async function reviewNote(notesToUpdate: Array<Array<TParagraph>>, noteIndex: nu
await appendTaskToCalendarNote(getTodaysDateHyphenated())
return updates.length ? noteIndex - 1 : noteIndex
}
case '__p0__':
case '__p1__':
case '__p2__':
case '__p3__': {
logDebug(`reviewNote: index:${index}, updates.length=${updates.length} currentTaskIndex=${currentTaskIndex}`)
clo(updates, `reviewNote: updates:`)
if (result?.changed) {
updates[index] = result.changed
note.updateParagraph(updates[index])
return noteIndex - 1
}
}
}
//user selected an item in the list to come back to later (in splitview)
// const range = note.paragraphs[Number(res) || 0].contentRange
Expand Down
49 changes: 34 additions & 15 deletions np.Shared/requiredFiles/react.c.Root.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ var RootBundle = (function (exports, React$1) {
// color this component's output differently in the console
const consoleStyle = 'background: #222; color: #62AFEC';
const logDebug = (msg, ...args) => console.log(`${window.webkit ? '' : '%c'}${msg}`, consoleStyle, ...args);
const logSubtle = (msg, ...args) => console.log(`%c${msg}`, 'color: #6D6962', ...args);
const logSubtle = (msg, ...args) => console.log(`${window.webkit ? '' : '%c'}${msg}`, 'color: #6D6962', ...args);

// used by the ErrorBoundary component
const myErrorLogger = (error, info) => {
Expand Down Expand Up @@ -323,18 +323,35 @@ var RootBundle = (function (exports, React$1) {
}); // dispatch the message to the reducer
};

/**
* Ignore messages that have nothing to do with the plugin
* @param {Event} event
* @returns {boolean}
*/
const shouldIgnoreMessage = event => {
const {
origin,
source,
data
} = event;
// logDebug(
// `Root: shouldIgnoreMessage origin=${origin} source=${source} data=${JSON.stringify(data)} data.source=${
// data?.source
// } /react-devtools/.test(data?.source=${/react-devtools/.test(data?.source)}}`,
// )
return typeof data === 'string' && data?.startsWith('setImmediate$') || typeof data === 'object' && data?.hasOwnProperty('iframeSrc') || /react-devtools/.test(data?.source);
};

/**
* This is effectively a reducer we will use to process messages from the plugin
* And also from components down the tree, using the dispatch command
*/
const onMessageReceived = event => {
const {
origin,
source,
data
} = event;
if (data && !(typeof data === 'string' && data.startsWith('setImmediate$')) && !data.iframeSrc) {
JSON.stringify(event, null, 4);
if (!shouldIgnoreMessage(event) && data) {
// const str = JSON.stringify(event, null, 4)
try {
// $FlowFixMe
const {
Expand Down Expand Up @@ -451,7 +468,7 @@ var RootBundle = (function (exports, React$1) {
// send some info to the plugin
// first param is the action type and the rest are data (can be any form you want)
// data.foo = 'bar'
sendMessageToPlugin(['commsBridgeTest', 'drink green', 'tea']);
sendMessageToPlugin(['commsBridgeTest', 'some sample', 'data passed']);
};

/**
Expand Down Expand Up @@ -516,12 +533,8 @@ var RootBundle = (function (exports, React$1) {
data: npData,
dispatch: dispatch
}), (debug) && /*#__PURE__*/React__default["default"].createElement(React__default["default"].StrictMode, null, /*#__PURE__*/React__default["default"].createElement("div", {
onClick: () => dispatch('SHOW_BANNER', {
msg: 'Banner test succeeded'
}, `banner test`)
}, "Local Banner Display Test"), /*#__PURE__*/React__default["default"].createElement("div", {
onClick: testCommsBridge
}, "Test Communication Bridge"), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("span", {
className: "w3-container w3-green"
}, "Debugging information (Plugin passed debug variable = true)"), /*#__PURE__*/React__default["default"].createElement("div", null, /*#__PURE__*/React__default["default"].createElement("span", {
id: "debugHistory"
}, "History (most recent first):"), /*#__PURE__*/React__default["default"].createElement("ul", null, history.slice().reverse().map((h, i) => /*#__PURE__*/React__default["default"].createElement("li", {
style: {
Expand All @@ -530,9 +543,15 @@ var RootBundle = (function (exports, React$1) {
key: i
}, "[", h?.date || '', "]: ", h?.msg || ''))), /*#__PURE__*/React__default["default"].createElement("div", {
className: "monospaceData"
}, "overdue paras: ", JSON.stringify(globalSharedData.overdueParas, null, 2)), /*#__PURE__*/React__default["default"].createElement("div", {
className: "monospaceData"
}, "globalSharedData: ", JSON.stringify(globalSharedData, null, 2))))));
}, "globalSharedData: ", JSON.stringify(globalSharedData, null, 2))), /*#__PURE__*/React__default["default"].createElement("div", {
className: "w3-button w3-black",
onClick: () => dispatch('SHOW_BANNER', {
msg: 'Banner test succeeded'
}, `banner test`)
}, "Local Banner Display Test"), /*#__PURE__*/React__default["default"].createElement("div", {
className: "w3-button w3-black",
onClick: testCommsBridge
}, "Test Communication Bridge"))));
}

exports.Root = Root;
Expand Down
Loading

0 comments on commit 5788611

Please sign in to comment.