Skip to content

refactor: Switch to generated jsapi types#1842

Merged
mattrunyon merged 17 commits intodeephaven:mainfrom
mattrunyon:jsapi-types
Mar 5, 2024
Merged

refactor: Switch to generated jsapi types#1842
mattrunyon merged 17 commits intodeephaven:mainfrom
mattrunyon:jsapi-types

Conversation

@mattrunyon
Copy link
Copy Markdown
Collaborator

@mattrunyon mattrunyon commented Feb 28, 2024

Fixes #1770

Here's the list of changes that weren't just updating the type import

ChartUtils

  • dh.plot.AxisType.Z does not exist any more. Changed to null for Z for now since we don't do any specific checks for Z axis in the template creation
  • addTickSpacing add a null check to gapBetweenMajorTicks

Console

  • Changed openObject to take VariableDescriptor instead of VariableDefinition. Removed title from openObject calls since it's not part of the descriptor

MonacoProviders

  • monacoToLspPosition added a pick to the return type

TableSaver

  • cast readonly to non-readonly column array for snapshot call

Integer/Decimal/DateTimeColumnFormatter

  • Add format.formatString null check in isValid

IrisGridUtils

  • Removed readonly on columnHeaderGroups line 138
  • Changed DehydratedSort.direction to just string

IrisGrid

  • Casting api sort direction (just string) to TableUtils SortDirection (enum)
  • Changed getOperationMap return type to not readonly (JSAPI doesn't mark as readonly)
  • Removed readonly from CommonTypes OperationMap
  • Changed CommonTypes UITotalsTableConfig to not extend dh.TotalsTableConfig because of readonly issues

IrisGridContextMenuHandler

  • Casted a few ofNumber calls to value as number since we mark it unknown
  • dateFilterActions changed value to type Date and convert to DateWrapper before number filter value
  • Throw if value is not Date at line ~500

FormatContextMenuUtils

  • Line 91 add formatString ?? undefined to coerce string | null | undefined to just string | undefined

IrisGridTreeTableModel

  • Removed formatRowColor from virtualColumns in constructor. It's marked as static in the types
  • Cast as unknown as DisplayColumn because it's not a real column

IrisGridTableModelTemplate

  • Added ?? null to line 1318 because TreeTable setViewport returns void. Table setViewport returns TableViewportSubscription

ServerConfigBootstrap

  • Added cast to getServerConfigValues to make Map constructor happy

AuthConfigBootstrap

  • Added cast to getAuthConfigValues to make Map constructor happy

ConsolePanel, Console, useObjectFetcher

  • Changed some VariableDefinition uses to dh.ide.VariableDescriptor & { title?: string }

DashboardLayout

  • Removed title from hydrateDefault when metadata.id is null (it's redundant as name is the field we want and title is not part of the descriptor)

FileStorage

  • Changed FileType to just string to match JS API

IrisGridPanelTypes

  • Added Partial to isLegacyIrisGridPanelMetadata

Added a blank line to logo.css because of stylelint? Might have accidentally bumped stylelint

@mattrunyon mattrunyon requested a review from mofojed February 28, 2024 20:53
@mattrunyon mattrunyon self-assigned this Feb 28, 2024
@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 49.56710% with 233 lines in your changes are missing coverage. Please review.

Project coverage is 46.08%. Comparing base (fe6c779) to head (f14f40b).

Files Patch % Lines
...d/src/mousehandlers/IrisGridContextMenuHandler.tsx 4.76% 20 Missing ⚠️
...ckages/iris-grid/src/IrisGridTableModelTemplate.ts 54.76% 19 Missing ⚠️
packages/jsapi-utils/src/TableUtils.ts 67.34% 16 Missing ⚠️
packages/iris-grid/src/EmptyIrisGridModel.ts 0.00% 15 Missing ⚠️
packages/iris-grid/src/IrisGridUtils.ts 62.16% 14 Missing ⚠️
packages/iris-grid/src/IrisGridProxyModel.ts 60.86% 9 Missing ⚠️
packages/iris-grid/src/IrisGridTreeTableModel.ts 0.00% 8 Missing ⚠️
...ode-studio/src/styleguide/MockIrisGridTreeModel.ts 12.50% 7 Missing ⚠️
...rd-core-plugins/src/panels/DropdownFilterPanel.tsx 12.50% 7 Missing ⚠️
packages/iris-grid/src/IrisGridTableModel.ts 65.00% 7 Missing ⚠️
... and 54 more
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1842   +/-   ##
=======================================
  Coverage   46.07%   46.08%           
=======================================
  Files         635      635           
  Lines       37978    38013   +35     
  Branches     9586     9608   +22     
=======================================
+ Hits        17499    17517   +18     
- Misses      20425    20443   +18     
+ Partials       54       53    -1     
Flag Coverage Δ
unit 46.08% <49.56%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
Member

@mofojed mofojed left a comment

Choose a reason for hiding this comment

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

Not done yet but posting some minor feedback so far. Couple of things to change.

Still need to review the rest.

Comment thread jest.config.base.cjs Outdated
Comment on lines +51 to +54
const newAuthConfigValues = (await client.getAuthConfigValues()) as [
string,
string,
][];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This kind of sucks, but I don't have any clever solutions. Would need a type predicate to map the string[][] to [string, string][] by checking each element I guess? isMapConstructorArray or something.
I also assume that GWT can't express this typing, otherwise that would be the best option to fix it in the jsapi-types source (though can have this temporarily).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I did note this in a non-critical improvements ticket deephaven/deephaven-core#5082

Ya we could add a util to actually check it since this is just assuming it's an array of string pairs

Comment thread packages/app-utils/src/components/ConnectionBootstrap.tsx
Comment thread packages/chart/src/ChartTestUtils.ts
Comment thread packages/chart/src/ChartTestUtils.ts
xaxis: this.makeLayoutAxis(dh.plot.AxisType.X, theme),
yaxis: this.makeLayoutAxis(dh.plot.AxisType.Y, theme),
zaxis: this.makeLayoutAxis(dh.plot.AxisType.Z, theme),
zaxis: this.makeLayoutAxis(null, theme),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah, on Enterprise it did used to have this constant. I guess we still need to set this for theming purposes of 3d plots in plotly-express? Wondering if we can just remove it and makeLayoutAxis doesn't need to take null then.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We use just the X or Y in makeLayoutAxis to add a few params to X or Y axis specifically

That said, w/ the theme changes I think that could be removed entirely and in the defaults here we could instead do something like this for the 1-2 props we add to the X and Y axis. I'd say do that as a followup though to keep this PR just related to types

xaxix: {
  ...this.makeLayoutAxis(theme),
  showgrid: true
}

Comment thread packages/file-explorer/src/FileStorage.ts Outdated
Comment thread packages/iris-grid/src/IrisGrid.tsx Outdated
column,
advancedFilterOptions,
sortDirection,
sortDirection as SortDirection,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Guessing GWT can't express Literal types for sort either... rather than casting should we have a method to convert it and throw if it can't be converted? Would be more "correct".

Side note, not sure how this isn't an error currently, since null shouldn't match SortDirection | undefined

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ya I think there were some issues with it/not a high priority. I'll add a typeguard and check for this.

SortDirection is `"ASC" | "DESC" | "REVERSE" | null``, so that's why it doesn't fail

Comment thread packages/iris-grid/src/IrisGridTableModelTemplate.ts Outdated
Comment thread packages/iris-grid/src/IrisGridUtils.ts Outdated
Comment thread packages/iris-grid/src/IrisGridUtils.ts Outdated
Comment on lines +1039 to +1041
if (name == null) {
throw new Error('Column header group has no name');
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can make this kind of check a one-liner:

Suggested change
if (name == null) {
throw new Error('Column header group has no name');
}
assertNotNull(name, 'Column header group has no name');

Possibly we should be verifying the group name isn't an empty string either, but that doesn't need to be this PR.

Comment thread packages/chart/src/ChartTestUtils.ts
}

listenerCleanup: RemoverFn | null;
listenerCleanup: (() => void) | null;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thought for future - this pattern of a cleanup function is common enough, we should have a utility type defined for () => void. Referencing ReturnType<DhType.HasEventHandling['addEventListener']> is possible too but gross. () => void is find and concise, but concern is someone making a mistake when using with other types (e.g. here, doing listenerCleanup: () => void | null instead of listenerCleanup: (() => void) | null).

Anyway just some food for thought.

Comment thread packages/iris-grid/src/mousehandlers/IrisGridContextMenuHandler.tsx Outdated
Comment on lines +1781 to +1783
return dh.FilterValue.ofNumber(
TableUtils.removeCommas(value) as unknown as number
);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gross. Do we have a follow up ticket to improve JS API? I feel like I commented on this at the time on the JS API review as well as ofNumber needing to take string, but unsure why that wasn't added to the Union type.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Comment thread packages/jsapi-utils/src/ViewportDataUtils.ts Outdated
@mattrunyon mattrunyon requested a review from mofojed March 5, 2024 02:42
@mattrunyon mattrunyon merged commit aee4047 into deephaven:main Mar 5, 2024
@mattrunyon mattrunyon deleted the jsapi-types branch March 5, 2024 20:35
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consume generated jsapi types

2 participants