Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Read settings from props/server config when available #1558

Merged
merged 27 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 12 additions & 20 deletions packages/code-studio/src/main/AppInit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import { useApi, useClient } from '@deephaven/jsapi-bootstrap';
import type { dh as DhType, IdeConnection } from '@deephaven/jsapi-types';
import { useConnection } from '@deephaven/jsapi-components';
import {
DecimalColumnFormatter,
getSessionDetails,
IntegerColumnFormatter,
loadSessionWrapper,
SessionWrapper,
} from '@deephaven/jsapi-utils';
Expand All @@ -39,12 +37,14 @@ import {
setPlugins as setPluginsAction,
setUser as setUserAction,
setWorkspace as setWorkspaceAction,
setDefaultWorkspaceSettings as setDefaultWorkspaceSettingsAction,
setWorkspaceStorage as setWorkspaceStorageAction,
setServerConfigValues as setServerConfigValuesAction,
User,
Workspace,
WorkspaceStorage,
ServerConfigValues,
WorkspaceSettings,
CustomizableWorkspace,
} from '@deephaven/redux';
import { useServerConfig, useUser } from '@deephaven/app-utils';
import { type PluginModuleMap, usePlugins } from '@deephaven/plugin';
Expand All @@ -58,7 +58,7 @@ import GrpcFileStorage from '../storage/grpc/GrpcFileStorage';
const log = Log.module('AppInit');

interface AppInitProps {
workspace: Workspace;
workspace: CustomizableWorkspace;
workspaceStorage: WorkspaceStorage;

setActiveTool: (type: (typeof ToolType)[keyof typeof ToolType]) => void;
Expand All @@ -74,7 +74,8 @@ interface AppInitProps {
setDashboardSessionWrapper: (id: string, wrapper: SessionWrapper) => void;
setPlugins: (map: PluginModuleMap) => void;
setUser: (user: User) => void;
setWorkspace: (workspace: Workspace) => void;
setWorkspace: (workspace: CustomizableWorkspace) => void;
setDefaultWorkspaceSettings: (settings: WorkspaceSettings) => void;
setWorkspaceStorage: (workspaceStorage: WorkspaceStorage) => void;
setServerConfigValues: (config: ServerConfigValues) => void;
}
Expand All @@ -97,6 +98,7 @@ function AppInit(props: AppInitProps): JSX.Element {
setUser,
setWorkspace,
setWorkspaceStorage,
setDefaultWorkspaceSettings,
setServerConfigValues,
} = props;

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

// Fill in settings that have not yet been set
const { settings } = data;
if (settings.defaultDecimalFormatOptions === undefined) {
settings.defaultDecimalFormatOptions = {
defaultFormatString: DecimalColumnFormatter.DEFAULT_FORMAT_STRING,
};
}

if (settings.defaultIntegerFormatOptions === undefined) {
settings.defaultIntegerFormatOptions = {
defaultFormatString: IntegerColumnFormatter.DEFAULT_FORMAT_STRING,
};
}

if (settings.truncateNumbersWithPound === undefined) {
settings.truncateNumbersWithPound = false;
}

// Set any shortcuts that user has overridden on this platform
const { shortcutOverrides = {} } = settings;
Expand Down Expand Up @@ -195,6 +182,9 @@ function AppInit(props: AppInitProps): JSX.Element {
setUser(user);
setWorkspaceStorage(workspaceStorage);
setWorkspace(loadedWorkspace);
setDefaultWorkspaceSettings(
LocalWorkspaceStorage.makeDefaultWorkspaceSettings(serverConfig)
);
} catch (e) {
log.error(e);
setError(e);
Expand All @@ -217,6 +207,7 @@ function AppInit(props: AppInitProps): JSX.Element {
setDashboardSessionWrapper,
setUser,
setWorkspace,
setDefaultWorkspaceSettings,
setWorkspaceStorage,
setServerConfigValues,
user,
Expand Down Expand Up @@ -281,6 +272,7 @@ const ConnectedAppInit = connect(mapStateToProps, {
setPlugins: setPluginsAction,
setUser: setUserAction,
setWorkspace: setWorkspaceAction,
setDefaultWorkspaceSettings: setDefaultWorkspaceSettingsAction,
setWorkspaceStorage: setWorkspaceStorageAction,
setServerConfigValues: setServerConfigValuesAction,
})(AppInit);
Expand Down
4 changes: 2 additions & 2 deletions packages/code-studio/src/main/AppMainContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ import {
setActiveTool as setActiveToolAction,
updateWorkspaceData as updateWorkspaceDataAction,
getPlugins,
Workspace,
WorkspaceData,
RootState,
User,
ServerConfigValues,
CustomizableWorkspace,
} from '@deephaven/redux';
import { bindAllMethods, PromiseUtils } from '@deephaven/utils';
import GoldenLayout from '@deephaven/golden-layout';
Expand Down Expand Up @@ -130,7 +130,7 @@ interface AppMainContainerProps {
updateDashboardData: (id: string, data: Partial<AppDashboardData>) => void;
updateWorkspaceData: (workspaceData: Partial<WorkspaceData>) => void;
user: User;
workspace: Workspace;
workspace: CustomizableWorkspace;
plugins: PluginModuleMap;
serverConfigValues: ServerConfigValues;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function renderContent({
timeZone = '',
truncateNumbersWithPound = false,
settings = {} as WorkspaceSettings,
saveSettings = jest.fn(),
updateSettings = jest.fn(),
scrollTo = undefined,
defaultDecimalFormatOptions = {
defaultFormatString: DEFAULT_DECIMAL_STRING,
Expand All @@ -45,7 +45,7 @@ function renderContent({
timeZone={timeZone}
truncateNumbersWithPound={truncateNumbersWithPound}
settings={settings}
saveSettings={saveSettings}
updateSettings={updateSettings}
scrollTo={scrollTo}
defaultDecimalFormatOptions={defaultDecimalFormatOptions}
defaultIntegerFormatOptions={defaultIntegerFormatOptions}
Expand Down
89 changes: 10 additions & 79 deletions packages/code-studio/src/settings/ColumnSpecificSectionContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,13 @@ import {
import type { dh as DhType } from '@deephaven/jsapi-types';
import {
getApi,
getDefaultDateTimeFormat,
getDefaultDecimalFormatOptions,
getDefaultIntegerFormatOptions,
getFormatter,
getTimeZone,
getShowTimeZone,
getShowTSeparator,
getTruncateNumbersWithPound,
getSettings,
saveSettings as saveSettingsAction,
updateSettings as updateSettingsAction,
RootState,
WorkspaceSettings,
} from '@deephaven/redux';
Expand All @@ -53,13 +50,10 @@ import DateTimeOptions from './DateTimeOptions';
export interface ColumnSpecificSectionContentProps {
dh: DhType;
formatter: FormatterItem[];
defaultDateTimeFormat: string;
showTimeZone: boolean;
showTSeparator: boolean;
timeZone: string;
truncateNumbersWithPound: boolean;
settings: WorkspaceSettings;
saveSettings: (settings: WorkspaceSettings) => void;
updateSettings: (settings: Partial<WorkspaceSettings>) => void;
scrollTo: (x: number, y: number) => void;
defaultDecimalFormatOptions: FormatOption;
defaultIntegerFormatOptions: FormatOption;
Expand All @@ -71,7 +65,6 @@ interface ColumnSpecificSectionContentState {
showTimeZone: boolean;
showTSeparator: boolean;
timeZone: string;
truncateNumbersWithPound: boolean;
timestampAtMenuOpen: Date;
}

Expand All @@ -81,19 +74,6 @@ export class ColumnSpecificSectionContent extends PureComponent<
> {
static defaultProps = {
scrollTo: (): void => undefined,
defaults: {
defaultDateTimeFormat:
DateTimeColumnFormatter.DEFAULT_DATETIME_FORMAT_STRING,
defaultDecimalFormatOptions: {
defaultFormatString: DecimalColumnFormatter.DEFAULT_FORMAT_STRING,
},
defaultIntegerFormatOptions: {
defaultFormatString: IntegerColumnFormatter.DEFAULT_FORMAT_STRING,
},
showTimeZone: false,
showTSeparator: true,
timeZone: DateTimeColumnFormatter.DEFAULT_TIME_ZONE_ID,
},
};

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

const {
formatter,
showTimeZone,
showTSeparator,
timeZone,
truncateNumbersWithPound,
} = props;
const { formatter, showTimeZone, showTSeparator, timeZone } = props;

const formatSettings = formatter.map((item, i) => ({
...item,
Expand All @@ -135,7 +109,6 @@ export class ColumnSpecificSectionContent extends PureComponent<
showTimeZone,
showTSeparator,
timeZone,
truncateNumbersWithPound,
timestampAtMenuOpen: new Date(),
};
}
Expand Down Expand Up @@ -273,19 +246,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
}

commitChanges(): void {
const {
formatSettings,
showTimeZone,
showTSeparator,
timeZone,
truncateNumbersWithPound,
} = this.state;

const {
defaultDateTimeFormat,
defaultDecimalFormatOptions,
defaultIntegerFormatOptions,
} = this.props;
const { formatSettings } = this.state;

const { dh } = this.props;

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

const { settings, saveSettings } = this.props;
const newSettings: WorkspaceSettings = {
...settings,
const { updateSettings } = this.props;
const newSettings = {
formatter: formatter as FormattingRule[],
defaultDateTimeFormat,
showTimeZone,
showTSeparator,
timeZone,
truncateNumbersWithPound,
};
if (
isValidFormat(
dh,
TableUtils.dataType.DECIMAL,
DecimalColumnFormatter.makeCustomFormat(
defaultDecimalFormatOptions.defaultFormatString
)
)
) {
newSettings.defaultDecimalFormatOptions = defaultDecimalFormatOptions;
}
if (
isValidFormat(
dh,
TableUtils.dataType.INT,
IntegerColumnFormatter.makeCustomFormat(
defaultIntegerFormatOptions.defaultFormatString
)
)
) {
newSettings.defaultIntegerFormatOptions = defaultIntegerFormatOptions;
}
saveSettings(newSettings);
updateSettings(newSettings);
}

scrollToFormatBlockBottom(): void {
Expand Down Expand Up @@ -577,6 +510,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
isInvalid: boolean
): ReactElement {
const { defaultIntegerFormatOptions } = this.props;
assertNotNull(defaultIntegerFormatOptions);
const { defaultFormatString } = defaultIntegerFormatOptions;
const value = format.formatString ?? '';
return (
Expand Down Expand Up @@ -688,21 +622,18 @@ export class ColumnSpecificSectionContent extends PureComponent<

const mapStateToProps = (
state: RootState
): Omit<ColumnSpecificSectionContentProps, 'saveSettings' | 'scrollTo'> => ({
): Omit<ColumnSpecificSectionContentProps, 'updateSettings' | 'scrollTo'> => ({
formatter: getFormatter(state),
defaultDateTimeFormat: getDefaultDateTimeFormat(state),
defaultDecimalFormatOptions: getDefaultDecimalFormatOptions(state),
defaultIntegerFormatOptions: getDefaultIntegerFormatOptions(state),
dh: getApi(state),
showTimeZone: getShowTimeZone(state),
showTSeparator: getShowTSeparator(state),
truncateNumbersWithPound: getTruncateNumbersWithPound(state),
timeZone: getTimeZone(state),
settings: getSettings(state),
});

const ConnectedColumnSpecificSectionContent = connect(mapStateToProps, {
saveSettings: saveSettingsAction,
updateSettings: updateSettingsAction,
})(ColumnSpecificSectionContent);

export default ConnectedColumnSpecificSectionContent;
Loading