Fixed an issue where internal settings for the separate tools tab were not being restored during application relaunch. #8988#9600
Conversation
…e not being restored during application relaunch. pgadmin-org#8988
WalkthroughStores and propagates toolbar preferences: ERDTool reads Changes
Sequence Diagram(s)sequenceDiagram
participant ERDTool as ERDTool
participant Backend as Backend
participant EventBus as EventBus
participant MainToolBar as MainToolBar
ERDTool->>Backend: restoreToolContent(request)
Backend-->>ERDTool: toolContent (includes connectionInfo.preferences)
ERDTool->>ERDTool: set toolbarPrefs = connectionInfo.preferences
ERDTool->>EventBus: emit DIRTY(true, toolContent.data, null, toolbarPrefs)
EventBus->>MainToolBar: DIRTY event (includes toolbarPrefs)
MainToolBar->>MainToolBar: apply toolbarPrefs (notation/cardinality/sql_with_drop)
MainToolBar->>EventBus: user changes -> emit save (includes toolbarPrefs)
EventBus->>Backend: saveToolData(payload includes preferences)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (4)
web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffButtonComponent.jsx (2)
67-74:⚠️ Potential issue | 🟡 Minor
filterParamslost its default value — risk ofTypeErrorif passedundefined.Previously
filterParamshad a default of[DIFFERENT, SOURCE_ONLY, TARGET_ONLY]. Now it has none, soselectedFiltersinitializes toundefinediffilterParamsis everundefined. Downstream.includes()calls onselectedFilters(lines 215–222) would throw.Currently
SchemaDiffCompare.jsxalways passes an array viagetFilterParams(), so this won't crash today, but the removed safety net makes the component fragile.Proposed fix — restore a safe default
-export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowIds, onServerSchemaChange, rows, compareParams, filterParams, filters }) { +export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowIds, onServerSchemaChange, rows, compareParams, filterParams = [], filters }) {
228-236:⚠️ Potential issue | 🟡 MinorMissing
filtersin PropTypes declaration.The
filtersprop is accepted and used in the component but not declared in the PropTypes block.Proposed fix
SchemaDiffButtonComponent.propTypes = { sourceData: PropTypes.object, targetData: PropTypes.object, selectedRowIds: PropTypes.array, onServerSchemaChange:PropTypes.func, rows: PropTypes.array, compareParams: PropTypes.object, - filterParams: PropTypes.array + filterParams: PropTypes.array, + filters: PropTypes.array, };web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffCompare.jsx (1)
157-165:⚠️ Potential issue | 🟡 MinorInconsistent null-safety on
oldSchemaDiffData.current.dataaccess.Line 159 accesses
.datawithout optional chaining, while lines 685 and 709 useoldSchemaDiffData.current?.data. IfgetToolContentreturns an object without adataproperty (e.g. empty or malformed response), this will throw.Proposed fix — add optional chaining for consistency
- _.each(oldSchemaDiffData.current.data,(d)=>{ + _.each(oldSchemaDiffData.current?.data,(d)=>{web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx (1)
229-236:⚠️ Potential issue | 🔴 CriticalExisting DIRTY event fires omit
toolbarPrefs, causing downstream data loss.
linksUpdatedandnodesUpdated(lines 231, 235) fire the DIRTY event with only 3 arguments, leavingtoolbarPrefsasundefinedin the MainToolBar handler. As noted in the MainToolBar review, this overwrites previously saved toolbar preferences.To fix this at the source, either pass
this.toolbarPrefsin all DIRTY events, or (preferably) fix the MainToolBar handler to preserve existingtoolbarPrefswhen none are provided — see the MainToolBar comment.
🤖 Fix all issues with AI agents
In `@web/pgadmin/tools/erd/static/js/erd_tool/components/MainToolBar.jsx`:
- Around line 90-98: The checkMenuClick and onCardinalityNotationChange handlers
call setSaveERDData with a functional updater that spreads prev (which can be
null before any DIRTY event), producing an incomplete save payload and causing
useDelayDebounce to invoke saveToolData with undefined data; update those
handlers (the setSaveERDData updater used in checkMenuClick and
onCardinalityNotationChange) to guard against prev === null by either
initializing a full default saveERDData shape (including data, fileName,
isDirty, toolbarPrefs) when prev is null or by early-returning / skipping the
debounce when the existing payload is incomplete, so
useDelayDebounce/saveToolData always receives a complete payload.
- Around line 163-168: The DIRTY event handler currently writes toolbarPrefs
directly from the event args, which can be undefined and overwrite persisted
prefs; update the handler (the ERD_EVENTS.DIRTY callback in MainToolBar.jsx that
calls isDirtyRef.current, setDisableButton('save', ...),
isSaveToolDataEnabled('ERD') and setSaveERDData) to only replace toolbarPrefs
when the incoming toolbarPrefs argument is defined—otherwise preserve the
existing toolbarPrefs from the previous saveERDData state (or a ref) and pass
that into setSaveERDData so undefined event args do not erase stored toolbar
preferences.
- Around line 123-148: The useEffect uses lodash helpers (_.isUndefined,
_.isNull) but lodash is not imported, causing ReferenceError; fix by either
adding an import for lodash (e.g. import _ from 'lodash') at the top of
MainToolBar.jsx so _.isUndefined/_.isNull are defined, or replace those calls
with native checks (e.g. toolbarPrefs !== undefined && toolbarPrefs !== null or
using Object.prototype.hasOwnProperty/typeof) in the useEffect that references
toolbarPrefs, preferences, checkedMenuItems, notationRef and onNotationChange.
🧹 Nitpick comments (2)
web/pgadmin/tools/schema_diff/static/js/components/SchemaDiffCompare.jsx (1)
807-809: BothfilterParamsandfiltersprops passed — verify intent of dual-prop design.
SchemaDiffButtonComponentreceives bothfilterParams={getFilterParams()}(used to initializeselectedFiltersstate) andfilters={filterOptions}(used in auseEffectto overrideselectedFilterswhen restored). This works but is somewhat confusing — two props that ultimately set the same state. Consider consolidating into a single prop in a follow-up to reduce cognitive overhead.web/pgadmin/tools/erd/static/js/erd_tool/components/ERDTool.jsx (1)
180-180:toolbarPrefsis a plain class property, not React state.Since
this.toolbarPrefsisn't state, changes to it from MainToolBar (viacheckMenuClick/onCardinalityNotationChange) won't flow back toERDTool. Currently that's acceptable because MainToolBar manages persistence independently. However, if future code in ERDTool needs the current toolbar prefs (e.g., for additional DIRTY events), it would read stale data.Consider promoting
toolbarPrefsto component state or using a ref, but this is not blocking for the current scope.Also applies to: 1088-1092
e52eef5 to
3df14ae
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@web/pgadmin/tools/erd/static/js/erd_tool/components/MainToolBar.jsx`:
- Around line 124-149: The effect in MainToolBar.jsx (the useEffect that reads
toolbarPrefs/preferences and updates notationRef and calls onNotationChange) is
missing onNotationChange and notation in its dependency array; update the
dependency array to include onNotationChange and notation so the effect re-runs
when the notation prop or the onNotationChange callback changes, ensuring
notationRef.current and the onNotationChange call use the latest values (keep
existing checks for toolbarPrefs/preferences and still update checkedMenuItems
via setCheckedMenuItems as before).
🧹 Nitpick comments (1)
web/pgadmin/tools/erd/static/js/erd_tool/components/MainToolBar.jsx (1)
388-389: Ref read during render — menu checked state won't update without a parent re-render.
notationRef.currentis read during render to derive thecheckedprop. Since mutating a ref doesn't trigger a re-render, the checked state only updates when something else (e.g.,onNotationChangepropagating a state change in the parent) forces a re-render. This works today becauseonNotationChangedoes trigger a parent re-render, but it's fragile — if the parent ever optimizes away that re-render, the menu items will show stale checked states.Consider using a state variable instead of a ref for the notation value, or accept the coupling and add a comment noting the dependency on the parent re-render.
Summary by CodeRabbit
New Features
Improvements