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

dashboard-core-plugins typescript conversion #693

Merged
merged 31 commits into from
Aug 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
88035d6
convert to ts
Zhou-Ziheng May 17, 2022
2ef053f
convert js to ts in styleguide
Zhou-Ziheng May 18, 2022
fd9ab19
added requested changes
Zhou-Ziheng May 26, 2022
6fa849c
finished fixing requested changes
Zhou-Ziheng May 27, 2022
2d02906
fixed merge conflicts
Zhou-Ziheng Jun 8, 2022
68ae4d4
fixed meerge errors
Zhou-Ziheng Jun 29, 2022
df7466b
Minor UX fixes to go to row
dsmmcken Jul 15, 2022
2e56756
self-review
dsmmcken Jul 15, 2022
4778da9
Merge remote-tracking branch 'origin/main'
Zhou-Ziheng Jul 21, 2022
d836ebd
WIP plugins conversion
Zhou-Ziheng Jul 21, 2022
f34ec25
Merge remote-tracking branch 'origin/main' into 579-plugins-ts
Zhou-Ziheng Jul 21, 2022
23d4334
WIP
Zhou-Ziheng Jul 27, 2022
0159ade
WIP
Zhou-Ziheng Jul 28, 2022
63bd1f5
wip
Zhou-Ziheng Jul 29, 2022
a1e3d0a
Merge remote-tracking branch 'origin/main' into 579-plugins-ts
Zhou-Ziheng Jul 29, 2022
a2d5c83
second last chunk
Zhou-Ziheng Jul 29, 2022
99be5d1
final chunk - errors
Zhou-Ziheng Jul 29, 2022
f2e3250
WIP
Zhou-Ziheng Aug 3, 2022
c7bb2b2
WIP
Zhou-Ziheng Aug 3, 2022
6e46614
wip
Zhou-Ziheng Aug 3, 2022
5e62263
chart
Zhou-Ziheng Aug 3, 2022
33b9895
final chunk plugins conversio
Zhou-Ziheng Aug 3, 2022
02e1cb1
fixed requested changes
Zhou-Ziheng Aug 8, 2022
c0b115d
Merge remote-tracking branch 'origin/main' into 579-plugins-ts
Zhou-Ziheng Aug 8, 2022
e0c51bf
fixed requested changes
Zhou-Ziheng Aug 9, 2022
dee6609
requested changes and test file conversion
Zhou-Ziheng Aug 15, 2022
3d131a0
asdf
Zhou-Ziheng Aug 17, 2022
f594ae8
unsaved file
Zhou-Ziheng Aug 17, 2022
ee248c3
fixed import errors
Zhou-Ziheng Aug 17, 2022
9a2554f
improved type sfor Linker
Zhou-Ziheng Aug 17, 2022
8deef88
final change?
Zhou-Ziheng Aug 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/chart/src/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -533,9 +533,11 @@ export class Chart extends Component<ChartProps, ChartState> {
) {
// Call relayout to resize avoiding the debouncing plotly does
// https://github.com/plotly/plotly.js/issues/2769#issuecomment-402099552
Plotly.relayout(this.plot.current.el, { autosize: true }).catch(e => {
log.debug('Unable to resize, promise rejected', e);
});
Plotly.relayout(this.plot.current.el, { autosize: true }).catch(
(e: unknown) => {
log.debug('Unable to resize, promise rejected', e);
}
);
}
}

Expand Down
4 changes: 2 additions & 2 deletions packages/components/src/TimeSlider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type TimeSliderProps = {

/**
* Creates a time slider for setting a start and end time, that can also run overnight
* @param {startTime, endTime, onChange} props takes times in seconds 0 - 86399 and a callback
* @param props takes times in seconds 0 - 86399 and a callback
*/
const TimeSlider = ({
startTime: propStartTime,
Expand Down Expand Up @@ -293,7 +293,7 @@ const Handle = (props: HandleProps): JSX.Element => {
* The handle offset changes for the first and last tick range dynmaically. Normally,
* the center of the handle (size/2) is the selection origin, but at edges, it becomes either
* end of the handle, requireing a relative offset range of 0 - 0.5, and 0.5 - 1 of handle size.
* @param {number} t time in seconds
* @param t time in seconds
*/
const transform = useMemo(() => {
const ONE_HOUR = 60 * 60;
Expand Down
6 changes: 3 additions & 3 deletions packages/dashboard-core-plugins/src/FilterPlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ export const FilterPlugin = (props: FilterPluginProps): JSX.Element => {
/**
* Handler for the COLUMNS_CHANGED event.
* @param panel The component that's emitting the filter change
* @param {Column|Array<Column>} columns The columns in this panel
* @param columns The columns in this panel
*/
const handleColumnsChanged = useCallback(
(panel: Component, columns) => {
(panel: Component, columns: Column | Column[]) => {
log.debug2('handleColumnsChanged', panel, columns);
panelColumns.set(panel, [].concat(columns) as Column[]);
panelColumns.set(panel, ([] as Column[]).concat(columns));
sendUpdate();
},
[panelColumns, sendUpdate]
Expand Down
3 changes: 2 additions & 1 deletion packages/dashboard-core-plugins/src/linker/Linker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import LinkerUtils, {
LinkFilterMap,
LinkType,
} from './LinkerUtils';
import { ColumnSelectionValidator } from '../panels/ColumnSelectionValidator';

const log = Log.module('Linker');

Expand Down Expand Up @@ -550,7 +551,7 @@ export class Linker extends Component<LinkerProps, LinkerState> {
case ToolType.LINKER:
setDashboardColumnSelectionValidator(
localDashboardId,
this.isColumnSelectionValid
this.isColumnSelectionValid as ColumnSelectionValidator
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead I think isColumnSelectionValid should also take a Partial<LinkColumn> rather than just LinkColumn - you'll need to put the appropriate checks for undefineds in there as well.

In particular - in LinkerUtils, there's a check on the columnType, checking for null:

    // Null columnType in ending link point allows linking to any type
    const isCompatibleType =
      endColumnType === null ||
      TableUtils.isCompatibleType(startColumnType, endColumnType);

);
break;
default:
Expand Down
15 changes: 5 additions & 10 deletions packages/dashboard-core-plugins/src/panels/ChartPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import ChartColumnSelectorOverlay, {
import './ChartPanel.scss';
import { Link } from '../linker/LinkerUtils';
import { PanelState as IrisGridPanelState } from './IrisGridPanel';
import { ColumnSelectionValidator } from './ColumnSelectionValidator';

const log = Log.module('ChartPanel');
const UPDATE_MODEL_DEBOUNCE = 150;
Expand Down Expand Up @@ -111,10 +112,7 @@ interface ChartPanelProps {
isLinkerActive: boolean;
source?: TableTemplate;
sourcePanel?: PanelComponent;
columnSelectionValidator: (
value: unknown,
column: { name: string; type: string } | null
) => boolean;
columnSelectionValidator?: ColumnSelectionValidator;
setActiveTool: (tool: string) => void;
setDashboardIsolatedLinkerPanelId: (
id: string,
Expand Down Expand Up @@ -414,10 +412,7 @@ export class ChartPanel extends Component<ChartPanelProps, ChartPanelState> {
(
columnMap: ColumnMap,
linkedColumnMap: LinkedColumnMap,
columnSelectionValidator: (
value: unknown,
column: { name: string; type: string } | null
) => boolean
columnSelectionValidator?: ColumnSelectionValidator
) =>
Array.from(columnMap.values()).map(column => ({
name: column.name,
Expand Down Expand Up @@ -501,7 +496,7 @@ export class ChartPanel extends Component<ChartPanelProps, ChartPanelState> {
if (!columnSelectionValidator) {
return;
}
columnSelectionValidator(this, null);
columnSelectionValidator(this, undefined);
}

handleDisconnect(): void {
Expand Down Expand Up @@ -758,7 +753,7 @@ export class ChartPanel extends Component<ChartPanelProps, ChartPanelState> {

/**
* Set chart filters based on the filter map
* @param {Map<string, Object>} filterMapParam Filter map
* @param filterMapParam Filter map
*/
setFilterMap(
filterMapParam: Map<string, { columnType: string; value: string }>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { PanelComponent } from '@deephaven/dashboard';
import { LinkColumn } from '../linker/LinkerUtils';

export type ColumnSelectionValidator = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file should probably be in the linker folder... or just even defined in LinkerUtils.

panel: PanelComponent,
tableColumn?: Partial<LinkColumn>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think instead of using Partial<LinkColumn>, you want to define a new type, LinkColumnSelection = { name: string, type?: string } and use that.

With Partial, you then also have to check that name is defined, which it always will be.

) => boolean;
37 changes: 0 additions & 37 deletions packages/dashboard-core-plugins/src/panels/ConsolePanel.test.jsx

This file was deleted.

50 changes: 50 additions & 0 deletions packages/dashboard-core-plugins/src/panels/ConsolePanel.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import { render } from '@testing-library/react';
import { CommandHistoryStorage } from '@deephaven/console';
import { Container } from '@deephaven/golden-layout';
import { ConsolePanel } from './ConsolePanel';
import { SessionWrapper } from '../../../code-studio/src/main/SessionUtils';

jest.mock('@deephaven/console', () => ({
...(jest.requireActual('@deephaven/console') as Record<string, unknown>),
Console: jest.fn(() => null),
default: jest.fn(() => null),
}));

jest.mock('./Panel', () => jest.fn(() => null));

function makeSession() {
return {
addEventListener: jest.fn(),
subscribeToFieldUpdates: jest.fn(() => () => null),
removeEventListener: jest.fn(),
getTable: jest.fn(),
getObject: jest.fn(),
runCode: jest.fn(),
};
}

it('renders without crashing', () => {
const eventHub = {
emit: () => undefined,
on: () => undefined,
off: () => undefined,
trigger: () => undefined,
unbind: () => undefined,
};
const container: Partial<Container> = {
emit: () => undefined,
on: () => undefined,
off: () => undefined,
};
const session = makeSession();
render(
<ConsolePanel
glEventHub={eventHub}
glContainer={container as Container}
commandHistoryStorage={{} as CommandHistoryStorage}
timeZone="MockTimeZone"
sessionWrapper={({ session, config: {} } as unknown) as SessionWrapper}
/>
);
});
15 changes: 4 additions & 11 deletions packages/dashboard-core-plugins/src/panels/ConsolePanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import type { JSZipObject } from 'jszip';
import { ConsoleEvent } from '../events';
import './ConsolePanel.scss';
import Panel from './Panel';
import { getDashboardSessionWrapper } from '../redux';
import { getDashboardSessionWrapper, SessionWrapper } from '../redux';

const log = Log.module('ConsolePanel');

Expand All @@ -45,13 +45,6 @@ interface PanelState {

type ItemIds = Map<string, string>;

interface SessionWrapper {
session: IdeSession;
config: {
type: string;
id: string;
};
}
interface ConsolePanelProps {
commandHistoryStorage: CommandHistoryStorage;
glContainer: Container;
Expand Down Expand Up @@ -260,8 +253,8 @@ export class ConsolePanel extends PureComponent<
}

/**
* @param {VariableDefinition} widget The widget to open
* @param {dh.Session} session The session object
* @param widget The widget to open
* @param session The session object
*/
openWidget(widget: VariableDefinition, session: IdeSession): void {
const { glEventHub } = this.props;
Expand All @@ -285,7 +278,7 @@ export class ConsolePanel extends PureComponent<

/**
* Close the disconnected panels from this session
* @param {boolean} force True to force the panels closed regardless of the current setting
* @param force True to force the panels closed regardless of the current setting
*/
closeDisconnectedPanels(force = false): void {
const { consoleSettings, itemIds } = this.state;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import './DropdownFilterPanel.scss';
import ToolType from '../linker/ToolType';
import WidgetPanel from './WidgetPanel';
import { Link } from '../linker/LinkerUtils';
import { ColumnSelectionValidator } from './ColumnSelectionValidator';

const log = Log.module('DropdownFilterPanel');

Expand All @@ -50,10 +51,7 @@ interface DropdownFilterPanelProps {
panelState?: PanelState;
isLinkerActive: boolean;
columns: Column[];
columnSelectionValidator?: (
value: unknown,
column: DropdownFilterColumn | null
) => boolean;
columnSelectionValidator?: ColumnSelectionValidator;
disableLinking: boolean;
settings: {
formatter: FormattingRule[];
Expand Down Expand Up @@ -240,7 +238,7 @@ class DropdownFilterPanel extends Component<
{ type, name }: DropdownFilterColumn,
formatter: Formatter
) => {
if (TableUtils.isDateType(type)) {
if (type && TableUtils.isDateType(type)) {
return rawValues.map(value =>
DropdownFilterPanel.DATETIME_FORMATTER.format(value as number)
);
Expand Down Expand Up @@ -479,8 +477,8 @@ class DropdownFilterPanel extends Component<

/**
* Set the filter value, card side, selected column
* @param {Object} state Filter state to set
* @param {boolean} sendUpdate Emit filters changed event if true
* @param state Filter state to set
* @param sendUpdate Emit filters changed event if true
*/
setPanelState(
state: {
Expand Down Expand Up @@ -671,7 +669,7 @@ class DropdownFilterPanel extends Component<
if (!columnSelectionValidator) {
return;
}
columnSelectionValidator(this, null);
columnSelectionValidator(this, undefined);
}

render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ class InputFilterPanel extends Component<

/**
* Set the filter value, card side, selected column
* @param {Object} state Filter state to set
* @param {boolean} sendUpdate Emit filters changed event if true
* @param state Filter state to set
* @param sendUpdate Emit filters changed event if true
*/
setPanelState(state: PanelState, sendUpdate = false) {
// Set the skipUpdate flag so the next onChange handler call doesn't emit the FILTERS_CHANGED event
Expand Down