Skip to content

Commit

Permalink
Fixed types (DH-18086)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmingles committed Jan 9, 2025
1 parent fffb123 commit bf1b44c
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 48 deletions.
8 changes: 4 additions & 4 deletions packages/app-utils/src/components/ConnectionBootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function ConnectionBootstrap({
if (connection == null || isShutdown) return;

// handles the disconnect event
function handleDisconnect(event: CustomEvent): void {
function handleDisconnect(event: dh.Event<unknown>): void {
const { detail } = event;
log.info('Disconnect', `${JSON.stringify(detail)}`);
setConnectionState('reconnecting');
Expand All @@ -105,7 +105,7 @@ export function ConnectionBootstrap({
if (connection == null || isShutdown) return;

// handles the reconnect event
function handleReconnect(event: CustomEvent): void {
function handleReconnect(event: dh.Event<unknown>): void {
const { detail } = event;
log.info('Reconnect', `${JSON.stringify(detail)}`);
setConnectionState('connected');
Expand All @@ -125,7 +125,7 @@ export function ConnectionBootstrap({
if (connection == null) return;

// handles the shutdown event
function handleShutdown(event: CustomEvent): void {
function handleShutdown(event: dh.Event<unknown>): void {
const { detail } = event;
log.info('Shutdown', `${JSON.stringify(detail)}`);
setError(`Server shutdown: ${detail ?? 'Unknown reason'}`);
Expand All @@ -146,7 +146,7 @@ export function ConnectionBootstrap({
if (connection == null || isShutdown) return;

// handles the auth failed event
function handleAuthFailed(event: CustomEvent): void {
function handleAuthFailed(event: dh.Event<unknown>): void {
const { detail } = event;
log.warn(
'Reconnect authentication failed',
Expand Down
14 changes: 10 additions & 4 deletions packages/chart/src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
type DateTimeFormatSettings,
} from '@deephaven/jsapi-utils';
import Log from '@deephaven/log';
import type { dh as DhType } from '@deephaven/jsapi-types';
import {
type Config as PlotlyConfig,
type Layout,
Expand Down Expand Up @@ -440,7 +441,7 @@ class Chart extends Component<ChartProps, ChartState> {
this.setState({ downsamplingError: null });
}

handleModelEvent(event: CustomEvent): void {
handleModelEvent(event: DhType.Event<unknown>): void {
const { type, detail } = event;
log.debug2('Received data update', type, detail);

Expand All @@ -453,7 +454,7 @@ class Chart extends Component<ChartProps, ChartState> {
layout.datarevision += 1;
}
return {
data: detail,
data: detail as Partial<Data>[] | null,
layout,
revision: revision + 1,
};
Expand Down Expand Up @@ -497,7 +498,8 @@ class Chart extends Component<ChartProps, ChartState> {
}
case ChartModel.EVENT_DOWNSAMPLENEEDED:
case ChartModel.EVENT_DOWNSAMPLEFAILED: {
const downsamplingError = detail.message ?? detail;
const downsamplingError =
(detail as { message?: string }).message ?? detail;
this.setState({
isDownsampleFinished: false,
isDownsampleInProgress: false,
Expand All @@ -506,7 +508,11 @@ class Chart extends Component<ChartProps, ChartState> {
});

const { onError } = this.props;
onError(new DownsamplingError(downsamplingError));
onError(
new DownsamplingError(
downsamplingError == null ? undefined : `${downsamplingError}`
)
);
break;
}
case ChartModel.EVENT_ERROR: {
Expand Down
11 changes: 10 additions & 1 deletion packages/chart/src/ChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,16 @@ import { type Formatter } from '@deephaven/jsapi-utils';
import type { Layout, Data } from 'plotly.js';
import { type FilterColumnMap, type FilterMap } from './ChartUtils';

export type ChartEvent = CustomEvent;
export type ChartEvent = DhType.Event<unknown>;

export interface FigureUpdateEventData {
series: DhType.plot.Series[];
getArray: (
series: DhType.plot.Series,
sourceType: number,
mappingFunc: (value: unknown) => unknown
) => unknown[];
}

export type RenderOptions = {
/** Allow WebGL as an option. Defaults to `true`, explicitly set to `false` to disable. */
Expand Down
12 changes: 8 additions & 4 deletions packages/chart/src/FigureChartModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ import type {
DateTimeColumnFormatter,
Formatter,
} from '@deephaven/jsapi-utils';
import ChartModel, { type ChartEvent, type RenderOptions } from './ChartModel';
import ChartModel, {
type ChartEvent,
type FigureUpdateEventData,
type RenderOptions,
} from './ChartModel';
import ChartUtils, {
type AxisTypeMap,
type ChartModelSettings,
Expand Down Expand Up @@ -472,7 +476,7 @@ class FigureChartModel extends ChartModel {
this.fireDownsampleNeeded(event.detail);
}

handleFigureUpdated(event: ChartEvent): void {
handleFigureUpdated(event: DhType.Event<FigureUpdateEventData>): void {
const { detail: figureUpdateEvent } = event;
const { series: seriesArray } = figureUpdateEvent;

Expand Down Expand Up @@ -549,7 +553,7 @@ class FigureChartModel extends ChartModel {
this.resubscribe();
}

handleFigureDisconnected(event: CustomEvent): void {
handleFigureDisconnected(event: DhType.Event<unknown>): void {
log.debug('Figure disconnected', event);

this.isConnected = false;
Expand All @@ -561,7 +565,7 @@ class FigureChartModel extends ChartModel {
this.fireDisconnect();
}

handleFigureReconnected(event: CustomEvent): void {
handleFigureReconnected(event: DhType.Event<unknown>): void {
log.debug('Figure reconnected', event);

this.isConnected = true;
Expand Down
14 changes: 12 additions & 2 deletions packages/console/src/Console.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,20 @@ export class Console extends PureComponent<ConsoleProps, ConsoleState> {
this.consoleInput.current?.clear();
}

handleCommandStarted(event: CustomEvent): void {
handleCommandStarted(
event: DhType.Event<{
code: string;
result: {
message: string;
error?: string;
changes: DhType.ide.VariableChanges;
cancel: () => unknown;
};
}>
): void {
const { code, result } = event.detail;
const wrappedResult = this.pending.add(result);
const historyItem = {
const historyItem: ConsoleHistoryActionItem = {
command: code,
disabledObjects: [],
startTime: Date.now(),
Expand Down
23 changes: 13 additions & 10 deletions packages/console/src/ConsoleStatusBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ function ConsoleStatusBar({
}: ConsoleStatusBarProps): ReactElement {
const [pendingCommandCount, setPendingCommandCount] = useState(0);

const handleCommandStarted = useCallback(async (event: CustomEvent) => {
setPendingCommandCount(count => count + 1);
const handleCommandStarted = useCallback(
async (event: DhType.Event<{ result: Promise<unknown> }>) => {
setPendingCommandCount(count => count + 1);

try {
const { result } = event.detail;
await result;
} catch (error) {
// No-op, fall through
}
try {
const { result } = event.detail;
await result;
} catch (error) {
// No-op, fall through
}

setPendingCommandCount(count => count - 1);
}, []);
setPendingCommandCount(count => count - 1);
},
[]
);

useEffect(
function startListening() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class AdvancedFilterCreatorSelectValueList<T = unknown> extends PureComponent<
this.updateItemSelection();
}

handleTableUpdate(event: CustomEvent): void {
handleTableUpdate(event: DhType.Event<DhType.ViewportData>): void {
const { table, formatter } = this.props;
if (!table) return;

Expand Down
2 changes: 1 addition & 1 deletion packages/iris-grid/src/IrisGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2101,7 +2101,7 @@ class IrisGrid extends Component<IrisGridProps, IrisGridState> {
// It's possible that the key table does not have any rows of data yet, so just wait until it does have one
keyTable.addEventListener(
dh.Table.EVENT_UPDATED,
(event: CustomEvent<DhType.ViewportData>) => {
(event: DhType.Event<DhType.ViewportData>) => {
try {
const { detail: data } = event;
if (data.rows.length === 0) {
Expand Down
6 changes: 3 additions & 3 deletions packages/iris-grid/src/IrisGridTableModelTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,19 +337,19 @@ class IrisGridTableModelTemplate<
this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.RECONNECT));
}

handleTableUpdate(event: CustomEvent): void {
handleTableUpdate(event: DhType.Event<DhType.ViewportData>): void {
this.copyViewportData(event.detail);

this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
}

handleTotalsUpdate(event: CustomEvent): void {
handleTotalsUpdate(event: DhType.Event<DhType.ViewportData>): void {
this.copyTotalsData(event.detail);

this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
}

handleRequestFailed(event: CustomEvent): void {
handleRequestFailed(event: DhType.Event<unknown>): void {
this.dispatchEvent(
new EventShimCustomEvent(IrisGridModel.EVENT.REQUEST_FAILED, event)
);
Expand Down
2 changes: 1 addition & 1 deletion packages/jsapi-components/src/TableDropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function TableDropdown({

subscription.addEventListener(
dh.Table.EVENT_UPDATED,
(event: CustomEvent<DhType.ViewportData>) => {
(event: DhType.Event<DhType.ViewportData>) => {
const { detail } = event;
// Core JSAPI returns undefined for null table values,
// coalesce with null to differentiate null from no selection in the dropdown
Expand Down
2 changes: 1 addition & 1 deletion packages/jsapi-components/src/useTableListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const log = Log.module('useTableListener');
export const useTableListener = <T = unknown>(
eventEmitter: dh.HasEventHandling | undefined | null,
eventName: string,
callback: (event: CustomEvent<T>) => void
callback: (event: dh.Event<T>) => void
): void =>
useEffect(
function initEventEmitter() {
Expand Down
12 changes: 0 additions & 12 deletions packages/jsapi-utils/src/SessionUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ export interface SessionWrapper {
dh: typeof DhType;
}

/**
* @returns New connection to the server
*/
export function createConnection(
dh: typeof DhType,
websocketUrl: string
): DhType.IdeConnection {
log.info(`Starting connection to '${websocketUrl}'...`);

return new dh.IdeConnection(websocketUrl);
}

/**
* Create a new session using the default URL
* @returns A session and config that is ready to use
Expand Down
6 changes: 3 additions & 3 deletions packages/jsapi-utils/src/TableUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ export class TableUtils {
table: DhType.Table | DhType.TreeTable,
eventName: string,
timeout = 0,
matcher: ((event: CustomEvent) => boolean) | null = null
): CancelablePromise<CustomEvent> {
matcher: ((event: DhType.Event<unknown>) => boolean) | null = null
): CancelablePromise<DhType.Event<unknown>> {
let eventCleanup: () => void;
let timeoutId: ReturnType<typeof setTimeout>;
let isPending = true;
Expand All @@ -650,7 +650,7 @@ export class TableUtils {
isPending = false;
resolve(event);
});
}) as CancelablePromise<CustomEvent>;
}) as CancelablePromise<DhType.Event<unknown>>;
wrappedPromise.cancel = () => {
if (isPending) {
log.debug2('Pending promise cleanup.');
Expand Down
2 changes: 1 addition & 1 deletion packages/jsapi-utils/src/ViewportDataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { type KeyedItem, type ValueOf } from '@deephaven/utils';

export const ITEM_KEY_PREFIX = 'DH_ITEM_KEY';

export type OnTableUpdatedEvent = CustomEvent<{
export type OnTableUpdatedEvent = dh.Event<{
offset: number;
columns: dh.Column[];
rows: dh.Row[];
Expand Down

0 comments on commit bf1b44c

Please sign in to comment.