Skip to content

Commit

Permalink
Merge branch 'main' into increase-code-coverage-in-package-jsapi-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyhuxng committed Mar 13, 2023
2 parents 305466d + 0be0850 commit 0c8fb0f
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 110 deletions.
2 changes: 1 addition & 1 deletion packages/chart/src/ChartModelFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class ChartModelFactory {
* This causes TS issues in 1 or 2 spots. Once this is TS it can be returned to just FigureChartModel
*/
static async makeModel(
settings: Record<string, unknown> | undefined,
settings: ChartModelSettings | undefined,
figure: Figure,
theme = ChartTheme
): Promise<ChartModel> {
Expand Down
19 changes: 11 additions & 8 deletions packages/chart/src/ChartUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ import ChartTheme from './ChartTheme';

export interface ChartModelSettings {
hiddenSeries?: string[];
type: keyof SeriesPlotStyle;
series: string[];
xAxis: string;
type?: keyof SeriesPlotStyle;
series?: string[];
xAxis?: string;
title?: string;
}

Expand Down Expand Up @@ -1805,18 +1805,21 @@ class ChartUtils {
*/
static hydrateSettings(
settings: ChartModelSettings
): Omit<ChartModelSettings, 'type'> & { type: SeriesPlotStyle } {
): Omit<ChartModelSettings, 'type'> & { type?: SeriesPlotStyle } {
return {
...settings,
type: dh.plot.SeriesPlotStyle[settings.type],
type:
settings.type != null
? dh.plot.SeriesPlotStyle[settings.type]
: undefined,
};
}

static titleFromSettings(settings: ChartModelSettings): string {
const {
series,
xAxis,
title = `${series.join(', ')} by ${xAxis}`,
title = `${(series ?? []).join(', ')} by ${xAxis}`,
} = settings;

return title;
Expand Down Expand Up @@ -1872,13 +1875,13 @@ class ChartUtils {
{
chartType: `${dh.plot.ChartType.XY}`,
axes: [xAxis, yAxis],
series: series.map(name => ({
series: (series ?? []).map(name => ({
plotStyle: `${type}`,
name,
dataSources: [
{
type: `${dh.plot.SourceType.X}`,
columnName: settingsAxis,
columnName: settingsAxis ?? '',
axis: xAxis,
table,
},
Expand Down
3 changes: 1 addition & 2 deletions packages/code-studio/src/main/WidgetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ export const createChartModel = async (
};
const figure = await connection.getObject(definition);

// eslint-disable-next-line @typescript-eslint/no-explicit-any
return ChartModelFactory.makeModel(settings as any, figure);
return ChartModelFactory.makeModel(settings, figure);
}

const definition = {
Expand Down
12 changes: 7 additions & 5 deletions packages/code-studio/src/redux/selectors.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { RootState, ServerConfigValues } from '@deephaven/redux';
import { RootState } from '@deephaven/redux';
import LayoutStorage from '../storage/LayoutStorage';

/**
* Get the layout storage used by the app
* @param store The redux store
* @returns The layout storage instance
*/
export const getLayoutStorage = (store: RootState): LayoutStorage =>
store.layoutStorage as LayoutStorage;
export const getLayoutStorage = <State extends RootState = RootState>(
store: State
): LayoutStorage => store.layoutStorage as LayoutStorage;

/**
* Get the configuration values of the server
* @param store The redux store
* @returns The layout storage instance
*/
export const getServerConfigValues = (store: RootState): ServerConfigValues =>
store.serverConfigValues;
export const getServerConfigValues = <State extends RootState = RootState>(
store: State
): State['serverConfigValues'] => store.serverConfigValues;
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,7 @@ export class ColumnSpecificSectionContent extends PureComponent<
isNewRule: true,
};
return {
formatSettings:
formatSettings != null ? [...formatSettings, newFormat] : [newFormat],
formatSettings: [...formatSettings, newFormat],
formatRulesChanged: true,
};
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
IntegerColumnFormatter,
DecimalColumnFormatter,
TableUtils,
FormattingRule,
} from '@deephaven/jsapi-utils';
import Log from '@deephaven/log';
import {
Expand Down Expand Up @@ -363,7 +362,7 @@ export class FormattingSectionContent extends PureComponent<
const { settings, saveSettings } = this.props;
const newSettings: WorkspaceSettings = {
...settings,
formatter: formatter as FormattingRule[],
formatter,
defaultDateTimeFormat,
showTimeZone,
showTSeparator,
Expand Down
18 changes: 11 additions & 7 deletions packages/code-studio/src/settings/SettingsUtils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
IntegerColumnFormatter,
DecimalColumnFormatter,
TableColumnFormat,
FormattingRule,
} from '@deephaven/jsapi-utils';
import Log from '@deephaven/log';

Expand All @@ -13,14 +14,15 @@ export type FormatOption = {
defaultFormatString?: string;
};

export type FormatterItem = {
columnType: string;
columnName: string;
format: Partial<TableColumnFormat>;
export type ValidFormatterItem = FormattingRule & {
id?: number;
isNewRule?: boolean;
};

export type FormatterItem = Omit<ValidFormatterItem, 'format'> & {
format: Partial<TableColumnFormat>;
};

function isFormatStringFormat(
format: Partial<TableColumnFormat>
): format is Pick<TableColumnFormat, 'formatString'> {
Expand Down Expand Up @@ -92,13 +94,15 @@ export function isValidFormat(
}

export function removeFormatRuleExtraProps(
item: FormatterItem
): Omit<FormatterItem, 'id' | 'isNewRule'> {
item: ValidFormatterItem
): FormattingRule {
const { id, isNewRule, ...rest } = item;
return rest;
}

export function isFormatRuleValidForSave(rule: FormatterItem): boolean {
export function isFormatRuleValidForSave(
rule: FormatterItem
): rule is ValidFormatterItem {
return (
isValidColumnName(rule.columnName) &&
isValidFormat(rule.columnType, rule.format)
Expand Down
3 changes: 1 addition & 2 deletions packages/dashboard-core-plugins/src/ChartBuilderPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ export function ChartBuilderPlugin(
}) => {
const { settings } = metadata;
const makeModel = () =>
// eslint-disable-next-line @typescript-eslint/no-explicit-any
ChartModelFactory.makeModelFromSettings(settings as any, table);
ChartModelFactory.makeModelFromSettings(settings, table);
const title = ChartUtils.titleFromSettings(settings);

const config = {
Expand Down
5 changes: 4 additions & 1 deletion packages/dashboard/src/layout/LayoutUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,10 @@ class LayoutUtils {
* @param config Tab config to match
* @returns True if the tab is active
*/
static isActiveTab(root: ContentItem, config: Config): boolean {
static isActiveTab(
root: ContentItem,
config: Partial<ReactComponentConfig>
): boolean {
const stack = LayoutUtils.getStackForRoot(root, config, false);
if (!stack) {
log.error('Could not find stack for config', config);
Expand Down
18 changes: 10 additions & 8 deletions packages/iris-grid/src/IrisGridUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ export interface DehydratedSort {
direction: SortDirection;
}

export interface TableSettings {
quickFilters?: readonly DehydratedQuickFilter[];
advancedFilters?: readonly DehydratedAdvancedFilter[];
inputFilters?: readonly InputFilter[];
sorts?: readonly (DehydratedSort | LegacyDehydratedSort)[];
partition?: unknown;
partitionColumn?: ColumnName;
}

export interface DehydratedIrisGridState {
advancedFilters: readonly DehydratedAdvancedFilter[];
aggregationSettings: AggregationSettings;
Expand Down Expand Up @@ -876,14 +885,7 @@ class IrisGridUtils {
*/
static applyTableSettings(
table: Table,
tableSettings: {
quickFilters?: readonly DehydratedQuickFilter[];
advancedFilters?: readonly DehydratedAdvancedFilter[];
inputFilters?: readonly InputFilter[];
sorts?: readonly (DehydratedSort | LegacyDehydratedSort)[];
partition?: unknown;
partitionColumn?: ColumnName;
},
tableSettings: TableSettings,
timeZone: string
): void {
const { columns } = table;
Expand Down
2 changes: 1 addition & 1 deletion packages/jsapi-types/src/dh.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ export interface Figure extends Evented {
readonly EVENT_SERIES_ADDED: string;

/** Given a client-created figure descriptor, generate a figure that can be subscribed to */
create(figure: Partial<FigureDescriptor>): Figure;
create(figure: Partial<FigureDescriptor>): Promise<Figure>;

readonly title: string;
readonly titleFont: string;
Expand Down
Loading

0 comments on commit 0c8fb0f

Please sign in to comment.