Skip to content
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
20 changes: 15 additions & 5 deletions helpers/userInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,22 @@ export async function chooseOptionWithModifiers<T, TDefault = T>(
* @param {Array<TCommandBarOptionObject>} options - array of options to display
* @param {boolean} allowCreate - add an option to create a new item (default: false)
* @returns {Promise<{value: T, label: string, index: number, keyModifiers: Array<string>}>} - Promise resolving to the result
* see CommandBar.showOptions for more info
* Sends back the object that was chosen, plus an index of the chosen option and keyModifiers array
*/
export async function chooseOptionWithModifiersV2(
message: string,
options: Array<TCommandBarOptionObject>,
options: Array<{ ...TCommandBarOptionObject, label?: string }>,
additionalCreateNewOption?: TCommandBarOptionObject,
): Promise<{ index: number, keyModifiers: Array<string>, label: string, value: string }> {
): Promise<{ index: number, keyModifiers: Array<string>, label?: string, ...TCommandBarOptionObject, text?: string, value?: string }> {
logDebug('userInput / chooseOptionWithModifiersV2()', `About to showOptions with ${options.length} options & prompt: "${message}"`)

// label field is used elsewhere, but @eduardme made showOptions use text instead, so we map it back to label
if (Array.isArray(options) && options.length > 0 && options[0].label && !options[0].text) {
options.forEach((option, i) => {
options[i] = { ...option, text: option.label ?? option.text } // $FlowFixMe[incompatible-type]
})
}

// Add the "Add new item" option at the start, if given
const displayOptions = options.slice()
if (additionalCreateNewOption) {
Expand All @@ -150,7 +157,9 @@ export async function chooseOptionWithModifiersV2(
logDebug('userInput / chooseOptionWithModifiersV2()', `displayOptions: ${displayOptions.length} options`)

// Use newer CommandBar.showOptions() from v3.18
const { index, keyModifiers } = await CommandBar.showOptions(displayOptions, message)
const result = await CommandBar.showOptions(displayOptions, message)
const { index, keyModifiers } = result
clo(result, `chooseOptionWithModifiersV2 chosen result (${typeof result})`)

// Check if the user selected "Add new item"
if (additionalCreateNewOption && index === 0) {
Expand All @@ -160,13 +169,14 @@ export async function chooseOptionWithModifiersV2(
return {
value: result,
label: result,
text: result,
index: -1, // -1 indicates a custom entry
keyModifiers: keyModifiers || [],
}
}
}

return { value: displayOptions[index].text ?? '', label: displayOptions[index].text ?? '', index, keyModifiers }
return { ...displayOptions[index], index, keyModifiers }
}

/**
Expand Down
4 changes: 4 additions & 0 deletions np.CallbackURLs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

See Plugin [README](https://github.com/NotePlan/plugins/blob/main/np.CallbackURLs/README.md) for details on available commands and use cases.

## [1.9.1] - 2025-08-19 @dwertheimer

- Fix bug in wizard when using showOptions()

## [1.9.0] - 2025-08-18 @dwertheimer

- Fix template runner wizard bug
Expand Down
4 changes: 2 additions & 2 deletions np.CallbackURLs/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"noteplan.minAppVersion-NOTE": "Includes folder view picker",
"plugin.id": "np.CallbackURLs",
"plugin.name": "🔗 Link Creator",
"plugin.version": "1.9.0",
"plugin.lastUpdateInfo": "1.9.0: Added folder view picker to wizard",
"plugin.version": "1.9.1",
"plugin.lastUpdateInfo": "1.9.1: Added folder view picker to wizard",
"plugin.description": "Interactively helps you form links/x-callback-urls (and also Template Tags with runPlugin commands) to perform actions from within NotePlan or between other applications and NotePlan.",
"plugin.author": "dwertheimer",
"plugin.dependencies": [],
Expand Down
17 changes: 11 additions & 6 deletions np.CallbackURLs/src/NPOpenFolders.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,20 +95,20 @@ async function selectFolder(folderOptions: Array<Object>): Promise<Object | null
* @param {Array<Object>} views - Array of named views for the folder
* @returns {Array<Object>} Array of view option objects
*/
function createViewOptions(views: Array<Object>): Array<TCommandBarOptionObject> {
let viewOptions: Array<TCommandBarOptionObject> = []
function createViewOptions(views: Array<Object>): Array<Object> {
let viewOptions: Array<Object> = []

// If there are named views, add them as options
if (views && views.length > 0) {
viewOptions = views.map((view: Object) => ({
label: `${view.name}`,
text: `${view.name}`,
value: view.name,
shortDescription: `(${view.layout})`,
}))
}

// Always add option to open folder view default
viewOptions.unshift({ label: '< Open the folder view default >', value: '_folder_', shortDescription: 'Default folder view' })
viewOptions.unshift({ text: '< Open the folder view default >', value: '_folder_', shortDescription: 'Default folder view' })

clo(viewOptions, `createViewOptions: viewOptions`)
return viewOptions
Expand All @@ -127,8 +127,13 @@ async function selectView(viewOptions: Array<Object>, selectedFolder: string): P
if (viewOptions.length === 1) {
return viewOptions[0].value
}

return await chooseOption(`Choose a view for '${selectedFolder}'`, viewOptions, '')
clo(viewOptions, `selectView viewOptions`)
const responseObj = await chooseOptionWithModifiersV2(`Choose a view for '${selectedFolder}'`, viewOptions)
if (responseObj) {
clo(responseObj, `selectView responseObj`)
return responseObj.value
}
return ''
}

/**
Expand Down
Loading