Skip to content

Commit 403e128

Browse files
committed
b17 tried and failed to get 'Rename Perspective' to actually save it fully to settings.json
1 parent 01189f1 commit 403e128

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

jgclark.Dashboard/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ For more details see the [plugin's documentation](https://github.com/NotePlan/pl
88
- TODO: fix long-standing layout bug where some tooltips were getting clipped
99
- TODO: fix isNoteFromAllowedFolder() for teamspace or possibly 2025-W21.md
1010
-->
11-
<!-- - ??? dev: check winowID throughout -->
1211

1312
## [2.4.0.b17] 2026-01-21
1413
### New
1514
- added new way to select items to show from Calendar sections: "Calendar note Sections to Include". There is already a way to exclude specific sections in a calendar note; this adds a way to only include specific sections. The matches are partial, so 'Home' will include 'Home' and 'The Home Areas' etc. If left blank, all sections are still included.
15+
- WIP: tried and failed to get 'Rename Perspective' to actually save it fully to settings.json
1616

1717
## [2.4.0.b16] 2026-01-20
1818
### Fixes
@@ -24,6 +24,7 @@ For more details see the [plugin's documentation](https://github.com/NotePlan/pl
2424
- dev: suppress "backup settings" messages to users on upgrades
2525
- align the two different sidebar icon colours
2626
- dev: fix a wrong windowID that had crept in
27+
- dev: check using same winowID throughout
2728

2829
## [2.4.0.b15] 2026-01-17
2930
### Changed

jgclark.Dashboard/src/dashboardSettings.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export const dashboardSettingDefs: Array<TSettingItem> = [
110110
description:
111111
"Comma-separated list of folder(s) to ignore when selecting open tasks/checklists to show. The matches are partial, so 'Work' will exclude 'Work' and 'Work/CompanyA' etc. To ignore notes at the top-level (not in a folder), include '/' in the list. (@Trash is always ignored, but other special folders need to be specified, e.g. @Archive, @Templates.)",
112112
type: 'input',
113-
default: '@Archive, @Templates, Saved Searches',
113+
default: '@Archive, @Templates, @Searches, @WindowSets',
114114
compactDisplay: true,
115115
},
116116
{

jgclark.Dashboard/src/perspectiveClickHandlers.js

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// clickHandlers.js
44
// Handler functions for dashboard clicks that come over the bridge
55
// The routing is in pluginToHTMLBridge.js/bridgeClickDashboardItem()
6-
// Last updated 2025-06-04 for v2.3.0
6+
// Last updated 2026-01-22 for v2.4.0.b17
77
//-----------------------------------------------------------------------------
88

99
import { getDashboardSettings, handlerResult, setPluginData, getDashboardSettingsDefaults } from './dashboardHelpers'
@@ -27,23 +27,25 @@ import {
2727
import { clo, dt, JSP, logDebug, logError, logInfo, logTimer, logWarn } from '@helpers/dev'
2828
import { getSettings, saveSettings } from '@helpers/NPConfiguration'
2929

30-
/****************************************************************************************************************************
31-
* NOTES
32-
****************************************************************************************************************************
33-
30+
/**
31+
* -----------------------------------------------------------------------------
32+
* Notes
33+
* -------------------------------------------------------------------------------
3434
- Handlers should use the standard return type of TBridgeClickHandlerResult
3535
- handlerResult() can be used to create the result object
3636
- Types are defined in types.js
3737
- type TActionOnReturn = 'UPDATE_CONTENT' | 'REMOVE_LINE' | 'REFRESH_JSON' | 'START_DELAYED_REFRESH_TIMER' etc.
38+
*/
3839

39-
/****************************************************************************************************************************
40-
* Data types + constants
41-
****************************************************************************************************************************/
40+
//-----------------------------------------------------------------------------
41+
// Constants
42+
//-----------------------------------------------------------------------------
4243

4344
const pluginID = 'jgclark.Dashboard'
44-
/****************************************************************************************************************************
45-
* HANDLERS
46-
****************************************************************************************************************************/
45+
46+
//-----------------------------------------------------------------------------
47+
// Handlers
48+
//-----------------------------------------------------------------------------
4749

4850
export async function doAddNewPerspective(_data: MessageDataObject): Promise<TBridgeClickHandlerResult> {
4951
clo(_data, `doAddNewPerspective starting ...`)
@@ -115,12 +117,25 @@ export async function doRenamePerspective(data: MessageDataObject): Promise<TBri
115117
if (newName === '') return handlerResult(false, [], { errorMsg: `doRenamePerspective: newName is empty` })
116118
if (origName === '-') return handlerResult(false, [], { errorMsg: `Perspective "-" cannot be renamed` })
117119
if (newName === '-') return handlerResult(false, [], { errorMsg: `Perspectives cannot be renamed to "-".` })
120+
const dashboardSettings = await getDashboardSettings()
118121
const perspectiveSettings = await getPerspectiveSettings()
119122
const existingDef = getPerspectiveNamed(origName, perspectiveSettings)
120-
if (!existingDef) return handlerResult(false, [], { errorMsg: `can't get definition for perspective ${origName}` })
123+
if (!existingDef) return handlerResult(false, [], { errorMsg: `Can't find the definition for perspective "${origName}"` })
121124
const revisedDefs = renamePerspective(origName, newName, perspectiveSettings)
122-
if (!revisedDefs) return handlerResult(false, [], { errorMsg: `savePerspectiveSettings failed` })
123-
const res = await savePerspectiveSettings(revisedDefs)
125+
if (!revisedDefs) return handlerResult(false, [], { errorMsg: `renamePerspective failed` })
126+
127+
// v1
128+
// const res = await savePerspectiveSettings(revisedDefs)
129+
// if (!res) {
130+
// return handlerResult(false, [], { errorMsg: `saveSettings failed` })
131+
// }
132+
// v2. But still not saving the dashboardSettings.
133+
const res = await saveSettings(pluginID, {
134+
...(await getSettings('jgclark.Dashboard')),
135+
dashboardSettings: dashboardSettings,
136+
perspectiveSettings: revisedDefs,
137+
})
138+
124139
await setPluginData({ perspectiveSettings: revisedDefs }, `_Saved perspective ${newName}`)
125140
if (!res) {
126141
return handlerResult(false, [], { errorMsg: `savePerspectiveSettings failed` })

jgclark.Dashboard/src/perspectiveHelpers.js

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// @flow
33
//-----------------------------------------------------------------------------
44
// Dashboard plugin helper functions for Perspectives
5-
// Last updated 2025-12-01 for v2.3.1
5+
// Last updated 2026-01-22 for v2.4.0.b17, @jgclark
66
//-----------------------------------------------------------------------------
77

88
import pluginJson from '../plugin.json'
@@ -287,28 +287,38 @@ export function replacePerspectiveDef(perspectiveSettings: Array<TPerspectiveDef
287287
* Set the isActive flag for the perspective with the given name (and false for all others) & reset isModified flag on all
288288
* @param {string} name
289289
* @param {Array<TPerspectiveDef>} perspectiveSettings
290-
* @returns {Array<TPerspectiveDef>}
290+
* @returns {Array<TPerspectiveDef>} the revised perspectiveSettings array
291291
*/
292292
export function setActivePerspective(name: string, perspectiveSettings: Array<TPerspectiveDef>): Array<TPerspectiveDef> {
293293
// map over perspectiveSettings, setting isActive to true for the one with name === name, and false for all others
294-
return perspectiveSettings ? perspectiveSettings.map((s) => ({ ...s, isActive: s.name === name, isModified: false })) : []
294+
return perspectiveSettings ? perspectiveSettings.map((s) => ({
295+
...s,
296+
isActive: s.name === name,
297+
isModified: false,
298+
})) : []
295299
}
296300

297301
/**
298-
* Set the isActive flag for the perspective with the given name (and false for all others) & reset isModified flag on all
299-
* @param {string} name
302+
* Set the isActive flag for the perspective with the given name (and false for all others) & reset isModified flag on all. The isModified flag is only reset for the renamed perspective.
303+
* @param {string} oldName
304+
* @param {string} newName - the new name for the perspective
300305
* @param {Array<TPerspectiveDef>} perspectiveSettings
301-
* @returns {Array<TPerspectiveDef>}
306+
* @returns {Array<TPerspectiveDef>} the revised perspectiveSettings array
302307
*/
303308
export function renamePerspective(oldName: string, newName: string, perspectiveSettings: Array<TPerspectiveDef>): Array<TPerspectiveDef> {
304-
return perspectiveSettings.map((s) => ({ ...s, name: s.name === oldName ? newName : s.name }))
309+
return perspectiveSettings.map((s) => (
310+
{
311+
...s,
312+
name: s.name === oldName ? newName : s.name,
313+
isModified: s.name === oldName ? false : s.isModified // Reset isModified for renamed perspective
314+
}))
305315
}
306316

307317
/**
308318
* Private function to add a new Perspective definition to the array
309319
* @param {Array<TPerspectiveDef>} perspectiveSettings
310320
* @param {TPerspectiveDef} newDef
311-
* @returns {Array<TPerspectiveDef>}
321+
* @returns {Array<TPerspectiveDef>} the revised perspectiveSettings array
312322
*/
313323
function addPerspectiveDef(perspectiveSettings: Array<TPerspectiveDef>, newDef: TPerspectiveDef): Array<TPerspectiveDef> {
314324
return [...perspectiveSettings, newDef]
@@ -318,7 +328,7 @@ function addPerspectiveDef(perspectiveSettings: Array<TPerspectiveDef>, newDef:
318328
* Private function to delete a Perspective definition from the array
319329
* @param {Array<TPerspectiveDef>} perspectiveSettings
320330
* @param {string} name
321-
* @returns {Array<TPerspectiveDef>}
331+
* @returns {Array<TPerspectiveDef>} the revised perspectiveSettings array
322332
*/
323333
function deletePerspectiveDef(perspectiveSettings: Array<TPerspectiveDef>, name: string): Array<TPerspectiveDef> {
324334
return perspectiveSettings.filter((s) => s.name !== name)
@@ -726,17 +736,6 @@ export async function addNewPerspective(nameArg?: string): Promise<void> {
726736
*/
727737
export async function deleteAllNamedPerspectiveSettings(): Promise<void> {
728738
logDebug('deleteAllNamedPerspectiveSettings', `Attempting to delete all Perspective settings (other than default) ...`)
729-
// v1
730-
// const pluginSettings = DataStore.settings
731-
// pluginSettings.perspectiveSettings = "[]"
732-
// const dSettings = await getDashboardSettings()
733-
// $FlowIgnore
734-
// delete dSettings.perspectiveSettings
735-
// pluginSettings.dashboardSettings = JSON.stringify(dSettings)
736-
// clo(pluginSettings.perspectiveSettings, `... leaves: pluginSettings.perspectiveSettings =`)
737-
// DataStore.settings = pluginSettings
738-
739-
// V2
740739
let allDefs = await getPerspectiveSettings()
741740
for (const p of allDefs) {
742741
if (p.name !== '-') {
@@ -745,15 +744,16 @@ export async function deleteAllNamedPerspectiveSettings(): Promise<void> {
745744
}
746745
logDebug('deleteAllNamedPerspectiveSettings', `Deleted all named perspectives, other than default.`)
747746

748-
allDefs = await getPerspectiveSettings()
749-
const updatedListOfPerspectives = getDisplayListOfPerspectiveNames(allDefs)
747+
const onlyDefaultPerspectiveDef: Array<TPerspectiveDef> = await getPerspectiveSettings()
748+
const updatedListOfPerspectives = getDisplayListOfPerspectiveNames(onlyDefaultPerspectiveDef)
750749
logDebug('deleteAllNamedPerspectiveSettings', `New default list of available perspectives: [${String(updatedListOfPerspectives ?? [])}]`)
751750

752751
// Set current perspective to default ("-")
753-
const newPerspectiveSettings = await switchToPerspective('-', allDefs)
752+
const newPerspectiveSettings = await switchToPerspective('-', onlyDefaultPerspectiveDef)
754753
await setPluginData({ perspectiveSettings: newPerspectiveSettings }, `_Deleted all named perspectives`)
755754

756-
// TODO: Update tagCache definition list json
755+
// Update tagCache definition list json
756+
updateTagMentionCacheDefinitionsFromAllPerspectives(onlyDefaultPerspectiveDef)
757757
logDebug('deleteAllNamedPerspectiveSettings', `Result of switchToPerspective("-"): ${String(newPerspectiveSettings)}`)
758758
}
759759

0 commit comments

Comments
 (0)