11import type { UndoPartial } from '@deephaven/utils' ;
22import { memoize } from 'proxy-memoize' ;
33import type { RootState , WorkspaceSettings } from './store' ;
4+ import { dhPython } from 'packages/icons/dist' ;
5+ import { set } from 'node_modules/@types/lodash' ;
46
57const EMPTY_OBJECT = Object . freeze ( { } ) ;
68
@@ -55,6 +57,38 @@ export const getWorkspace = <State extends RootState>(
5557 return workspace ;
5658} ;
5759
60+ /**
61+ * Helpter function to replace settings values
62+ * Any nested objects under workspace settings need to be handled here
63+ * @param key the key of the setting to replace
64+ * @param settings current settings object
65+ * @param customizedSettings customized settings to apply
66+ */
67+ const replaceSettings = (
68+ key : keyof WorkspaceSettings ,
69+ settings : WorkspaceSettings ,
70+ customizedSettings : UndoPartial < WorkspaceSettings >
71+ ) : void => {
72+ let newSettings = customizedSettings [ key ] ;
73+ if ( key === 'notebookSettings' ) {
74+ const customizedLinter =
75+ customizedSettings . notebookSettings ?. python ?. linter ;
76+ const settingsLinter = settings . notebookSettings ?. python ?. linter ;
77+ newSettings = {
78+ ...settings . notebookSettings ,
79+ ...customizedSettings . notebookSettings ,
80+ python : {
81+ linter : {
82+ isEnabled : customizedLinter ?. isEnabled ?? settingsLinter ?. isEnabled ,
83+ config : customizedLinter ?. config ?? settingsLinter ?. config ,
84+ } ,
85+ } ,
86+ } ;
87+ }
88+ // @ts -expect-error assign non-undefined customized settings to settings
89+ settings [ key ] = newSettings ;
90+ } ;
91+
5892// Settings
5993export const getSettings = memoize (
6094 < State extends RootState > (
@@ -67,8 +101,11 @@ export const getSettings = memoize(
67101 for ( let i = 0 ; i < keys . length ; i += 1 ) {
68102 const key = keys [ i ] ;
69103 if ( customizedSettings [ key ] !== undefined ) {
70- // @ts -expect-error assign non-undefined customized settings to settings
71- settings [ key ] = customizedSettings [ key ] ;
104+ replaceSettings (
105+ key ,
106+ settings ,
107+ customizedSettings as UndoPartial < WorkspaceSettings >
108+ ) ;
72109 }
73110 }
74111 return settings as UndoPartial < State [ 'workspace' ] [ 'data' ] [ 'settings' ] > ;
0 commit comments