Skip to content

Commit 52ba2cd

Browse files
authored
feat: Read settings from props/server config when available (#1558)
Updated the follow values to use ServerConfig when possible: - defaultDateTimeFormat - timeZone - defaultDecimalFormatOptions - defaultIntegerFormatOptions - truncateNumbersWithPound - defaultNotebookSettings.isMinimapEnabled
1 parent 4875d2e commit 52ba2cd

18 files changed

Lines changed: 374 additions & 406 deletions

packages/code-studio/src/main/AppInit.tsx

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ import { useApi, useClient } from '@deephaven/jsapi-bootstrap';
2020
import type { dh as DhType, IdeConnection } from '@deephaven/jsapi-types';
2121
import { useConnection } from '@deephaven/jsapi-components';
2222
import {
23-
DecimalColumnFormatter,
2423
getSessionDetails,
25-
IntegerColumnFormatter,
2624
loadSessionWrapper,
2725
SessionWrapper,
2826
} from '@deephaven/jsapi-utils';
@@ -39,12 +37,14 @@ import {
3937
setPlugins as setPluginsAction,
4038
setUser as setUserAction,
4139
setWorkspace as setWorkspaceAction,
40+
setDefaultWorkspaceSettings as setDefaultWorkspaceSettingsAction,
4241
setWorkspaceStorage as setWorkspaceStorageAction,
4342
setServerConfigValues as setServerConfigValuesAction,
4443
User,
45-
Workspace,
4644
WorkspaceStorage,
4745
ServerConfigValues,
46+
WorkspaceSettings,
47+
CustomizableWorkspace,
4848
} from '@deephaven/redux';
4949
import { useServerConfig, useUser } from '@deephaven/app-utils';
5050
import { type PluginModuleMap, usePlugins } from '@deephaven/plugin';
@@ -58,7 +58,7 @@ import GrpcFileStorage from '../storage/grpc/GrpcFileStorage';
5858
const log = Log.module('AppInit');
5959

6060
interface AppInitProps {
61-
workspace: Workspace;
61+
workspace: CustomizableWorkspace;
6262
workspaceStorage: WorkspaceStorage;
6363

6464
setActiveTool: (type: (typeof ToolType)[keyof typeof ToolType]) => void;
@@ -74,7 +74,8 @@ interface AppInitProps {
7474
setDashboardSessionWrapper: (id: string, wrapper: SessionWrapper) => void;
7575
setPlugins: (map: PluginModuleMap) => void;
7676
setUser: (user: User) => void;
77-
setWorkspace: (workspace: Workspace) => void;
77+
setWorkspace: (workspace: CustomizableWorkspace) => void;
78+
setDefaultWorkspaceSettings: (settings: WorkspaceSettings) => void;
7879
setWorkspaceStorage: (workspaceStorage: WorkspaceStorage) => void;
7980
setServerConfigValues: (config: ServerConfigValues) => void;
8081
}
@@ -97,6 +98,7 @@ function AppInit(props: AppInitProps): JSX.Element {
9798
setUser,
9899
setWorkspace,
99100
setWorkspaceStorage,
101+
setDefaultWorkspaceSettings,
100102
setServerConfigValues,
101103
} = props;
102104

@@ -149,21 +151,6 @@ function AppInit(props: AppInitProps): JSX.Element {
149151

150152
// Fill in settings that have not yet been set
151153
const { settings } = data;
152-
if (settings.defaultDecimalFormatOptions === undefined) {
153-
settings.defaultDecimalFormatOptions = {
154-
defaultFormatString: DecimalColumnFormatter.DEFAULT_FORMAT_STRING,
155-
};
156-
}
157-
158-
if (settings.defaultIntegerFormatOptions === undefined) {
159-
settings.defaultIntegerFormatOptions = {
160-
defaultFormatString: IntegerColumnFormatter.DEFAULT_FORMAT_STRING,
161-
};
162-
}
163-
164-
if (settings.truncateNumbersWithPound === undefined) {
165-
settings.truncateNumbersWithPound = false;
166-
}
167154

168155
// Set any shortcuts that user has overridden on this platform
169156
const { shortcutOverrides = {} } = settings;
@@ -195,6 +182,9 @@ function AppInit(props: AppInitProps): JSX.Element {
195182
setUser(user);
196183
setWorkspaceStorage(workspaceStorage);
197184
setWorkspace(loadedWorkspace);
185+
setDefaultWorkspaceSettings(
186+
LocalWorkspaceStorage.makeDefaultWorkspaceSettings(serverConfig)
187+
);
198188
} catch (e) {
199189
log.error(e);
200190
setError(e);
@@ -217,6 +207,7 @@ function AppInit(props: AppInitProps): JSX.Element {
217207
setDashboardSessionWrapper,
218208
setUser,
219209
setWorkspace,
210+
setDefaultWorkspaceSettings,
220211
setWorkspaceStorage,
221212
setServerConfigValues,
222213
user,
@@ -281,6 +272,7 @@ const ConnectedAppInit = connect(mapStateToProps, {
281272
setPlugins: setPluginsAction,
282273
setUser: setUserAction,
283274
setWorkspace: setWorkspaceAction,
275+
setDefaultWorkspaceSettings: setDefaultWorkspaceSettingsAction,
284276
setWorkspaceStorage: setWorkspaceStorageAction,
285277
setServerConfigValues: setServerConfigValuesAction,
286278
})(AppInit);

packages/code-studio/src/main/AppMainContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,11 @@ import {
7171
setActiveTool as setActiveToolAction,
7272
updateWorkspaceData as updateWorkspaceDataAction,
7373
getPlugins,
74-
Workspace,
7574
WorkspaceData,
7675
RootState,
7776
User,
7877
ServerConfigValues,
78+
CustomizableWorkspace,
7979
} from '@deephaven/redux';
8080
import { bindAllMethods, PromiseUtils } from '@deephaven/utils';
8181
import GoldenLayout from '@deephaven/golden-layout';
@@ -130,7 +130,7 @@ interface AppMainContainerProps {
130130
updateDashboardData: (id: string, data: Partial<AppDashboardData>) => void;
131131
updateWorkspaceData: (workspaceData: Partial<WorkspaceData>) => void;
132132
user: User;
133-
workspace: Workspace;
133+
workspace: CustomizableWorkspace;
134134
plugins: PluginModuleMap;
135135
serverConfigValues: ServerConfigValues;
136136
}

packages/code-studio/src/settings/ColumnSpecificSectionContent.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function renderContent({
2525
timeZone = '',
2626
truncateNumbersWithPound = false,
2727
settings = {} as WorkspaceSettings,
28-
saveSettings = jest.fn(),
28+
updateSettings = jest.fn(),
2929
scrollTo = undefined,
3030
defaultDecimalFormatOptions = {
3131
defaultFormatString: DEFAULT_DECIMAL_STRING,
@@ -45,7 +45,7 @@ function renderContent({
4545
timeZone={timeZone}
4646
truncateNumbersWithPound={truncateNumbersWithPound}
4747
settings={settings}
48-
saveSettings={saveSettings}
48+
updateSettings={updateSettings}
4949
scrollTo={scrollTo}
5050
defaultDecimalFormatOptions={defaultDecimalFormatOptions}
5151
defaultIntegerFormatOptions={defaultIntegerFormatOptions}

packages/code-studio/src/settings/ColumnSpecificSectionContent.tsx

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,13 @@ import {
2222
import type { dh as DhType } from '@deephaven/jsapi-types';
2323
import {
2424
getApi,
25-
getDefaultDateTimeFormat,
2625
getDefaultDecimalFormatOptions,
2726
getDefaultIntegerFormatOptions,
2827
getFormatter,
2928
getTimeZone,
3029
getShowTimeZone,
3130
getShowTSeparator,
32-
getTruncateNumbersWithPound,
33-
getSettings,
34-
saveSettings as saveSettingsAction,
31+
updateSettings as updateSettingsAction,
3532
RootState,
3633
WorkspaceSettings,
3734
} from '@deephaven/redux';
@@ -53,13 +50,10 @@ import DateTimeOptions from './DateTimeOptions';
5350
export interface ColumnSpecificSectionContentProps {
5451
dh: DhType;
5552
formatter: FormatterItem[];
56-
defaultDateTimeFormat: string;
5753
showTimeZone: boolean;
5854
showTSeparator: boolean;
5955
timeZone: string;
60-
truncateNumbersWithPound: boolean;
61-
settings: WorkspaceSettings;
62-
saveSettings: (settings: WorkspaceSettings) => void;
56+
updateSettings: (settings: Partial<WorkspaceSettings>) => void;
6357
scrollTo: (x: number, y: number) => void;
6458
defaultDecimalFormatOptions: FormatOption;
6559
defaultIntegerFormatOptions: FormatOption;
@@ -71,7 +65,6 @@ interface ColumnSpecificSectionContentState {
7165
showTimeZone: boolean;
7266
showTSeparator: boolean;
7367
timeZone: string;
74-
truncateNumbersWithPound: boolean;
7568
timestampAtMenuOpen: Date;
7669
}
7770

@@ -81,19 +74,6 @@ export class ColumnSpecificSectionContent extends PureComponent<
8174
> {
8275
static defaultProps = {
8376
scrollTo: (): void => undefined,
84-
defaults: {
85-
defaultDateTimeFormat:
86-
DateTimeColumnFormatter.DEFAULT_DATETIME_FORMAT_STRING,
87-
defaultDecimalFormatOptions: {
88-
defaultFormatString: DecimalColumnFormatter.DEFAULT_FORMAT_STRING,
89-
},
90-
defaultIntegerFormatOptions: {
91-
defaultFormatString: IntegerColumnFormatter.DEFAULT_FORMAT_STRING,
92-
},
93-
showTimeZone: false,
94-
showTSeparator: true,
95-
timeZone: DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID,
96-
},
9777
};
9878

9979
static inputDebounceTime = 250;
@@ -111,13 +91,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
11191
this.handleFormatRuleCreate = this.handleFormatRuleCreate.bind(this);
11292
this.handleFormatRuleDelete = this.handleFormatRuleDelete.bind(this);
11393

114-
const {
115-
formatter,
116-
showTimeZone,
117-
showTSeparator,
118-
timeZone,
119-
truncateNumbersWithPound,
120-
} = props;
94+
const { formatter, showTimeZone, showTSeparator, timeZone } = props;
12195

12296
const formatSettings = formatter.map((item, i) => ({
12397
...item,
@@ -135,7 +109,6 @@ export class ColumnSpecificSectionContent extends PureComponent<
135109
showTimeZone,
136110
showTSeparator,
137111
timeZone,
138-
truncateNumbersWithPound,
139112
timestampAtMenuOpen: new Date(),
140113
};
141114
}
@@ -273,19 +246,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
273246
}
274247

275248
commitChanges(): void {
276-
const {
277-
formatSettings,
278-
showTimeZone,
279-
showTSeparator,
280-
timeZone,
281-
truncateNumbersWithPound,
282-
} = this.state;
283-
284-
const {
285-
defaultDateTimeFormat,
286-
defaultDecimalFormatOptions,
287-
defaultIntegerFormatOptions,
288-
} = this.props;
249+
const { formatSettings } = this.state;
289250

290251
const { dh } = this.props;
291252

@@ -296,39 +257,11 @@ export class ColumnSpecificSectionContent extends PureComponent<
296257
)
297258
.map(removeFormatRuleExtraProps) ?? [];
298259

299-
const { settings, saveSettings } = this.props;
300-
const newSettings: WorkspaceSettings = {
301-
...settings,
260+
const { updateSettings } = this.props;
261+
const newSettings = {
302262
formatter: formatter as FormattingRule[],
303-
defaultDateTimeFormat,
304-
showTimeZone,
305-
showTSeparator,
306-
timeZone,
307-
truncateNumbersWithPound,
308263
};
309-
if (
310-
isValidFormat(
311-
dh,
312-
TableUtils.dataType.DECIMAL,
313-
DecimalColumnFormatter.makeCustomFormat(
314-
defaultDecimalFormatOptions.defaultFormatString
315-
)
316-
)
317-
) {
318-
newSettings.defaultDecimalFormatOptions = defaultDecimalFormatOptions;
319-
}
320-
if (
321-
isValidFormat(
322-
dh,
323-
TableUtils.dataType.INT,
324-
IntegerColumnFormatter.makeCustomFormat(
325-
defaultIntegerFormatOptions.defaultFormatString
326-
)
327-
)
328-
) {
329-
newSettings.defaultIntegerFormatOptions = defaultIntegerFormatOptions;
330-
}
331-
saveSettings(newSettings);
264+
updateSettings(newSettings);
332265
}
333266

334267
scrollToFormatBlockBottom(): void {
@@ -577,6 +510,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
577510
isInvalid: boolean
578511
): ReactElement {
579512
const { defaultIntegerFormatOptions } = this.props;
513+
assertNotNull(defaultIntegerFormatOptions);
580514
const { defaultFormatString } = defaultIntegerFormatOptions;
581515
const value = format.formatString ?? '';
582516
return (
@@ -688,21 +622,18 @@ export class ColumnSpecificSectionContent extends PureComponent<
688622

689623
const mapStateToProps = (
690624
state: RootState
691-
): Omit<ColumnSpecificSectionContentProps, 'saveSettings' | 'scrollTo'> => ({
625+
): Omit<ColumnSpecificSectionContentProps, 'updateSettings' | 'scrollTo'> => ({
692626
formatter: getFormatter(state),
693-
defaultDateTimeFormat: getDefaultDateTimeFormat(state),
694627
defaultDecimalFormatOptions: getDefaultDecimalFormatOptions(state),
695628
defaultIntegerFormatOptions: getDefaultIntegerFormatOptions(state),
696629
dh: getApi(state),
697630
showTimeZone: getShowTimeZone(state),
698631
showTSeparator: getShowTSeparator(state),
699-
truncateNumbersWithPound: getTruncateNumbersWithPound(state),
700632
timeZone: getTimeZone(state),
701-
settings: getSettings(state),
702633
});
703634

704635
const ConnectedColumnSpecificSectionContent = connect(mapStateToProps, {
705-
saveSettings: saveSettingsAction,
636+
updateSettings: updateSettingsAction,
706637
})(ColumnSpecificSectionContent);
707638

708639
export default ConnectedColumnSpecificSectionContent;

0 commit comments

Comments
 (0)