Skip to content

refactor: Replace usage of Column.index with column name#1126

Merged
bmingles merged 9 commits intodeephaven:mainfrom
bmingles:965-remove-column-index
Mar 7, 2023
Merged

refactor: Replace usage of Column.index with column name#1126
bmingles merged 9 commits intodeephaven:mainfrom
bmingles:965-remove-column-index

Conversation

@bmingles
Copy link
Copy Markdown
Contributor

@bmingles bmingles commented Mar 3, 2023

resolves #965

BREAKING CHANGE: Removed index property from dh.types Column type. IrisGridUtils.dehydrateSort now returns column name instead of index. TableUtils now expects column name instead of index for functions that don't have access to a columns array.

@bmingles bmingles force-pushed the 965-remove-column-index branch from 66acca3 to fab60f7 Compare March 3, 2023 03:10
@bmingles bmingles requested a review from mattrunyon March 3, 2023 03:11
@bmingles bmingles changed the title Replace usage of Column.index with column name refactor: Replace usage of Column.index with column name Mar 3, 2023
@codecov
Copy link
Copy Markdown

codecov Bot commented Mar 3, 2023

Codecov Report

Merging #1126 (a1f8ee9) into main (57af185) will increase coverage by 0.01%.
The diff coverage is 75.00%.

@@            Coverage Diff             @@
##             main    #1126      +/-   ##
==========================================
+ Coverage   43.40%   43.41%   +0.01%     
==========================================
  Files         435      435              
  Lines       32682    32688       +6     
  Branches     8240     8244       +4     
==========================================
+ Hits        14185    14193       +8     
+ Misses      18448    18446       -2     
  Partials       49       49              
Flag Coverage Δ
unit 43.41% <75.00%> (+0.01%) ⬆️

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

Impacted Files Coverage Δ
...s/dashboard-core-plugins/src/panels/ChartPanel.tsx 61.55% <ø> (ø)
...d/src/mousehandlers/IrisGridContextMenuHandler.tsx 3.11% <0.00%> (ø)
packages/iris-grid/src/IrisGrid.tsx 27.00% <33.33%> (-0.02%) ⬇️
packages/iris-grid/src/IrisGridRenderer.ts 24.61% <75.00%> (+0.24%) ⬆️
packages/iris-grid/src/IrisGridUtils.ts 54.09% <100.00%> (+0.87%) ⬆️
packages/jsapi-utils/src/TableUtils.ts 53.43% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Comment thread packages/iris-grid/src/IrisGridUtils.ts Outdated
return dh.Table.reverse();
}
const column = IrisGridUtils.getColumn(columns, columnIndex);
const column = IrisGridUtils.getColumnByName(columns, columnName);
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 is correct, but we're going to need a migration strategy for data that was stored in the old format (testing against Enterprise). Can just check against the sort value to see if columnName is provided, or instead define the DehydratedSort type as column: ModelIndex | ColumnName, then have a typeof check and look up the column name if a ModelIndex is provided.

An example is how we handle movedColumns:


@mattrunyon implemented that migration behaviour in https://github.com/deephaven/web-client-ui/pull/642/files (though it should be typed to a ColumnName instead of a string).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The movedColumns wasn't really a migration I'd say. It was adding behavior (support for moving ranges in 1 move), not changing or removing any. This issue removes using ModelIndex for the sort column.

We'll still need to make sure the ModelIndex order is saved since we rely on that and not names for many things still. I'm not sure if that is accurate, but this ticket does remove the direct uses of column.index from the API. We still have some reliance on the column order being maintained by the engine which is a bigger issue to deal with.

Related #833 and #643

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've updated the code to support index or column name when importing a sort, but exporting uses column name.

Comment thread packages/iris-grid/src/IrisGridUtils.ts Outdated
Comment thread packages/iris-grid/src/IrisGridUtils.ts Outdated
Comment on lines +100 to +101
export type DehydratedSort = {
column: ModelIndex;
column: ColumnName | ModelIndex;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think we should make this LegacyDehydratedSort or something since moving forward we don't want DehydratedSort to use ModelIndex as the column. Then hydrate can take LegacyDehydratedSort and dehydrate return DehydratedSort without the | ModelIndex

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mattrunyon I've added the LegacyDehydratedSort interface as suggested

@bmingles bmingles force-pushed the 965-remove-column-index branch 2 times, most recently from 230a141 to f120043 Compare March 6, 2023 20:17
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.

We need to mark this as a Breaking Change, since the TableUtils API is changing to only take a string for column name.
To mark it as a Breaking change, add the BREAKING CHANGE: footer to the PR description as described in the Contributing guidelines.

expect(exportedSort).toEqual([
{ column: 3, isAbs: false, direction: 'ASC' },
{ column: 7, isAbs: true, direction: 'DESC' },
expect(exportedSort).toEqual<DehydratedSort[]>([
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.

We should also add a test that it re-hydrates a LegacyDehydratedSort as well.

[sortList.hasThree, 'name_999', 2],
];

it.each(testCases)(
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.

TIL. Didn't know there was a it.each. Could have used this in a bunch of other cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mofojed There's also a string literal syntax supported by it.each that can be used to inject test variables. I have rarely used it but worth checking out the docs. https://jestjs.io/docs/api#2-testeachtablename-fn-timeout

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.

That's pretty neat! Good to know.

@bmingles bmingles force-pushed the 965-remove-column-index branch from f120043 to 4acdaa8 Compare March 7, 2023 17:03
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.

Still need to update the PR description with the BREAKING CHANGE footer. We need to either maintain API compatibility with things exported by our packages (in this case, the functions changed in TableUtils), or mark it breaking.

@bmingles bmingles changed the title refactor: Replace usage of Column.index with column name BREAKING CHANGE: Removed index property from Column type. DehydratedSorts now use column name instead of index Mar 7, 2023
@bmingles bmingles changed the title BREAKING CHANGE: Removed index property from Column type. DehydratedSorts now use column name instead of index refactor: Replace usage of Column.index with column name Mar 7, 2023
@bmingles bmingles merged commit 7448a88 into deephaven:main Mar 7, 2023
@github-actions github-actions Bot locked and limited conversation to collaborators Mar 7, 2023
@bmingles bmingles deleted the 965-remove-column-index branch April 14, 2023 13:57
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.

Remove uses of JS API column index

3 participants