Skip to content

Commit 3f647a1

Browse files
authored
Improve the prompt message per @ bono (#657)
1 parent 7e6d83a commit 3f647a1

3 files changed

Lines changed: 24 additions & 30 deletions

File tree

m1well.Expenses/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# m1well.Expenses Plugin Changelog
22

3+
## [1.7.3] - 2022-07-23 (@dwertheimer)
4+
### Changed
5+
- add more descriptive text for text input
6+
37
## [1.7.2] - 2022-04-26 (@jgclark)
48
### Changed
59
- remove references to previous _configuration note system; all comes through Plugin settings screen

m1well.Expenses/plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"plugin.description": "Plugin to track your expenses for further analyis",
88
"plugin.author": "@m1well",
99
"plugin.url": "https://github.com/NotePlan/plugins/blob/main/m1well.Expenses/README.md",
10-
"plugin.version": "1.7.2",
10+
"plugin.version": "1.7.3",
1111
"plugin.dependencies": [],
1212
"plugin.script": "script.js",
1313
"plugin.commands": [

m1well.Expenses/src/expenses.js

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
createAggregationExpenseRowWithDelimiter,
1414
createTrackingExpenseRowWithConfig,
1515
extractExpenseRowFromCsvRow,
16-
stringifyShortcutList
16+
stringifyShortcutList,
1717
} from './expensesHelper'
1818
import type { Config, ExpenseTrackingRow } from './expensesModels'
1919
import { amountOk, categoryOk, validateConfig } from './expensesChecks'
@@ -29,9 +29,7 @@ const CONFIG_KEYS = {
2929
fixedExpenses: 'fixedExpenses',
3030
}
3131

32-
const TRACKING_MODE = [
33-
'Individual', 'Shortcuts', 'Fixed'
34-
]
32+
const TRACKING_MODE = ['Individual', 'Shortcuts', 'Fixed']
3533

3634
// if there is no config in the '_configuration' file, then provide an example config
3735
const EXAMPLE_CONFIG = `
@@ -154,16 +152,14 @@ const expensesAggregate = async (): Promise<boolean> => {
154152
const year = Number(await CommandBar.showInput('Please type in the year to aggregate', 'Start aggregate'))
155153

156154
const noteTitleTracking = `${year} Expenses Tracking`
157-
if (!await provideAndCheckNote(noteTitleTracking, config.folderPath, false, year)) {
155+
if (!(await provideAndCheckNote(noteTitleTracking, config.folderPath, false, year))) {
158156
return false
159157
}
160158

161159
const trackingNote = DataStore.projectNoteByTitle(noteTitleTracking)?.[0]
162160

163161
if (trackingNote) {
164-
const trackedData = trackingNote.paragraphs
165-
.filter(para => !para.rawContent.startsWith('#'))
166-
.map(para => extractExpenseRowFromCsvRow(para.rawContent, config))
162+
const trackedData = trackingNote.paragraphs.filter((para) => !para.rawContent.startsWith('#')).map((para) => extractExpenseRowFromCsvRow(para.rawContent, config))
167163

168164
if (!checkDataQualityBeforeAggregate(trackedData, year, config)) {
169165
return false
@@ -172,7 +168,7 @@ const expensesAggregate = async (): Promise<boolean> => {
172168
const aggregatedData = aggregateByCategoriesAndMonth(trackedData, config.delimiter)
173169

174170
const noteTitleAggregate = `${year} Expenses Aggregate`
175-
if (!await provideAndCheckNote(noteTitleAggregate, config.folderPath, true)) {
171+
if (!(await provideAndCheckNote(noteTitleAggregate, config.folderPath, true))) {
176172
return false
177173
}
178174

@@ -182,9 +178,9 @@ const expensesAggregate = async (): Promise<boolean> => {
182178
await Editor.openNoteByTitle(noteTitleAggregate)
183179
const note = Editor.note
184180
if (note) {
185-
note.removeParagraphs(note.paragraphs.filter(para => !para.rawContent.startsWith('#')))
181+
note.removeParagraphs(note.paragraphs.filter((para) => !para.rawContent.startsWith('#')))
186182
// add results
187-
aggregatedData.forEach(aggregated => {
183+
aggregatedData.forEach((aggregated) => {
188184
if (aggregated.year) {
189185
lines.push(createAggregationExpenseRowWithDelimiter(aggregated, config))
190186
}
@@ -214,12 +210,12 @@ const individualTracking = async (): Promise<boolean> => {
214210

215211
const title = `${getYear(currentDate)} Expenses Tracking`
216212

217-
if (!await provideAndCheckNote(title, config.folderPath, true)) {
213+
if (!(await provideAndCheckNote(title, config.folderPath, true))) {
218214
return false
219215
}
220216

221217
const category = await CommandBar.showOptions(config.categories, 'Please choose category')
222-
const text = await getInputTrimmed('Please type in some text (no semicolon)', 'Add text to expenses line')
218+
const text = await getInputTrimmed('Please type in some text (no semicolon)', 'Add text to expenses line', 'What was it?')
223219
let amount = await inputNumber('Please type in amount')
224220

225221
let amountCheck = amountOk(amount)
@@ -244,7 +240,7 @@ const individualTracking = async (): Promise<boolean> => {
244240
}
245241
if (note) {
246242
note.appendParagraph(createTrackingExpenseRowWithConfig(expenseRow, config), 'text')
247-
await CommandBar.showOptions([ 'OK' ], 'Individual Expenses saved')
243+
await CommandBar.showOptions(['OK'], 'Individual Expenses saved')
248244
}
249245

250246
return true
@@ -266,7 +262,7 @@ const shortcutsTracking = async (): Promise<boolean> => {
266262

267263
const title = `${getYear(currentDate)} Expenses Tracking`
268264

269-
if (!await provideAndCheckNote(title, config.folderPath, true)) {
265+
if (!(await provideAndCheckNote(title, config.folderPath, true))) {
270266
return false
271267
}
272268

@@ -305,7 +301,7 @@ const shortcutsTracking = async (): Promise<boolean> => {
305301
}
306302
if (note) {
307303
note.appendParagraph(createTrackingExpenseRowWithConfig(expenseRow, config), 'text')
308-
await CommandBar.showOptions([ 'OK' ], 'Shortcut Expenses saved')
304+
await CommandBar.showOptions(['OK'], 'Shortcut Expenses saved')
309305
}
310306

311307
return true
@@ -327,7 +323,7 @@ const fixedTracking = async (): Promise<boolean> => {
327323

328324
const title = `${getYear(currentDate)} Expenses Tracking`
329325

330-
if (!await provideAndCheckNote(title, config.folderPath, true)) {
326+
if (!(await provideAndCheckNote(title, config.folderPath, true))) {
331327
return false
332328
}
333329

@@ -337,14 +333,14 @@ const fixedTracking = async (): Promise<boolean> => {
337333

338334
const note = DataStore.projectNoteByTitle(title)?.[0]
339335
config.fixedExpenses
340-
.filter(exp => exp.active && (exp.month === 0 || exp.month === month))
341-
.map(exp => {
336+
.filter((exp) => exp.active && (exp.month === 0 || exp.month === month))
337+
.map((exp) => {
342338
if (!categoryOk(exp.category, config.categories)) {
343339
exp.category = `>>WRONG CATEGORY (${exp.category})<<`
344340
}
345341
return exp
346342
})
347-
.forEach(exp => {
343+
.forEach((exp) => {
348344
const expenseRow = {
349345
date: currentDate,
350346
category: exp.category,
@@ -356,7 +352,7 @@ const fixedTracking = async (): Promise<boolean> => {
356352

357353
if (note) {
358354
note.appendParagraph(lines.join('\n'), 'text')
359-
await CommandBar.showOptions([ 'OK' ], 'Fixed Expenses saved')
355+
await CommandBar.showOptions(['OK'], 'Fixed Expenses saved')
360356
}
361357

362358
return true
@@ -378,23 +374,18 @@ const provideConfig = async (): Promise<any> => {
378374
throw new Error(`Cannot find settings for Expenses plugin`)
379375
}
380376
return fromSettings
381-
}
382-
catch (err) {
377+
} catch (err) {
383378
logError(pluginJson, `${err.name}: ${err.message}`)
384379
return null // for completeness
385380
}
386-
387381
}
388382

389383
/**
390384
* check if one note exists by name, if mulitple exists - throw error, of none extist -> create it
391385
*
392386
* @private
393387
*/
394-
const provideAndCheckNote = async (title: string,
395-
folderPath: string,
396-
createNote: boolean,
397-
year?: number): Promise<boolean> => {
388+
const provideAndCheckNote = async (title: string, folderPath: string, createNote: boolean, year?: number): Promise<boolean> => {
398389
const notes = DataStore.projectNoteByTitle(title)
399390

400391
// create note if it de
@@ -444,7 +435,6 @@ const checkDataQualityBeforeAggregate = (rows: ExpenseTrackingRow[], year: numbe
444435
logError(pluginJson, `amount at: ${createTrackingExpenseRowWithConfig(row, config)}`)
445436
return false
446437
}
447-
448438
}
449439

450440
return true

0 commit comments

Comments
 (0)