@@ -104,27 +104,67 @@ export const getConfigOverridesFromQueryParams = (
104
104
export const initializeInspectorConfig = (
105
105
localStorageKey : string ,
106
106
) : InspectorConfig => {
107
- const savedConfig = localStorage . getItem ( localStorageKey ) ;
108
- let baseConfig : InspectorConfig ;
109
- if ( savedConfig ) {
110
- // merge default config with saved config
111
- const mergedConfig = {
112
- ...DEFAULT_INSPECTOR_CONFIG ,
113
- ...JSON . parse ( savedConfig ) ,
114
- } as InspectorConfig ;
115
-
116
- // update description of keys to match the new description (in case of any updates to the default config description)
117
- for ( const [ key , value ] of Object . entries ( mergedConfig ) ) {
118
- mergedConfig [ key as keyof InspectorConfig ] = {
119
- ...value ,
120
- label : DEFAULT_INSPECTOR_CONFIG [ key as keyof InspectorConfig ] . label ,
121
- } ;
122
- }
123
- baseConfig = mergedConfig ;
124
- } else {
125
- baseConfig = DEFAULT_INSPECTOR_CONFIG ;
107
+ // Read persistent config from localStorage
108
+ const savedPersistentConfig = localStorage . getItem ( localStorageKey ) ;
109
+ // Read ephemeral config from sessionStorage
110
+ const savedEphemeralConfig = sessionStorage . getItem (
111
+ `${ localStorageKey } _ephemeral` ,
112
+ ) ;
113
+
114
+ // Start with default config
115
+ let baseConfig = { ...DEFAULT_INSPECTOR_CONFIG } ;
116
+
117
+ // Apply saved persistent config
118
+ if ( savedPersistentConfig ) {
119
+ const parsedPersistentConfig = JSON . parse ( savedPersistentConfig ) ;
120
+ baseConfig = { ...baseConfig , ...parsedPersistentConfig } ;
126
121
}
122
+
123
+ // Apply saved ephemeral config
124
+ if ( savedEphemeralConfig ) {
125
+ const parsedEphemeralConfig = JSON . parse ( savedEphemeralConfig ) ;
126
+ baseConfig = { ...baseConfig , ...parsedEphemeralConfig } ;
127
+ }
128
+
129
+ // Ensure all config items have the latest labels/descriptions from defaults
130
+ for ( const [ key , value ] of Object . entries ( baseConfig ) ) {
131
+ baseConfig [ key as keyof InspectorConfig ] = {
132
+ ...value ,
133
+ label : DEFAULT_INSPECTOR_CONFIG [ key as keyof InspectorConfig ] . label ,
134
+ description :
135
+ DEFAULT_INSPECTOR_CONFIG [ key as keyof InspectorConfig ] . description ,
136
+ is_session_item :
137
+ DEFAULT_INSPECTOR_CONFIG [ key as keyof InspectorConfig ] . is_session_item ,
138
+ } ;
139
+ }
140
+
127
141
// Apply query param overrides
128
142
const overrides = getConfigOverridesFromQueryParams ( DEFAULT_INSPECTOR_CONFIG ) ;
129
143
return { ...baseConfig , ...overrides } ;
130
144
} ;
145
+
146
+ export const saveInspectorConfig = (
147
+ localStorageKey : string ,
148
+ config : InspectorConfig ,
149
+ ) : void => {
150
+ const persistentConfig : Partial < InspectorConfig > = { } ;
151
+ const ephemeralConfig : Partial < InspectorConfig > = { } ;
152
+
153
+ // Split config based on is_session_item flag
154
+ for ( const [ key , value ] of Object . entries ( config ) ) {
155
+ if ( value . is_session_item ) {
156
+ ephemeralConfig [ key as keyof InspectorConfig ] = value ;
157
+ } else {
158
+ persistentConfig [ key as keyof InspectorConfig ] = value ;
159
+ }
160
+ }
161
+
162
+ // Save persistent config to localStorage
163
+ localStorage . setItem ( localStorageKey , JSON . stringify ( persistentConfig ) ) ;
164
+
165
+ // Save ephemeral config to sessionStorage
166
+ sessionStorage . setItem (
167
+ `${ localStorageKey } _ephemeral` ,
168
+ JSON . stringify ( ephemeralConfig ) ,
169
+ ) ;
170
+ } ;
0 commit comments