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

Changes reorder column events to use source and destination #6733

Merged
merged 14 commits into from
Jan 31, 2024

Conversation

hoonji
Copy link
Member

@hoonji hoonji commented Jan 25, 2024

Motivation for features / changes

To prepare for showing shared hparam columns across runs and scalar tables, we need to unify the column re-ordering logic to use the same source/destination parameters (introduced in #6727).

Technical description of changes

  • Changes the DataTable component (shared by runs and scalar tables) to use the new ReorderColumnEvent type when column order is changed. The changes propagate to scalar card scalar column editor containers. Most of the changes are getting the tests to pass with the new signature.
  • Changes the metrics reducers to correctly handle these new events. Logic is mostly unchanged, except that sort order will now be preserved even after column toggle (previously, toggling would group all disabled columns together, which destroys relative column order

misc:

  • creates moveColumn utility to abstract shared logic between the hparams and metrics reducers. Removes redundant tests in hparams reducer

Detailed steps to verify changes work correctly (as executed by you)

  • Unit tests pass
  • Manually tested sorting behavior

@@ -18,10 +18,8 @@
<tb-data-table
[headers]="columnHeaders"
[sortingInfo]="sortingInfo"
[columnCustomizationEnabled]="columnCustomizationEnabled"
Copy link
Member Author

Choose a reason for hiding this comment

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

unused

Copy link
Contributor

Choose a reason for hiding this comment

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

👏

(sortDataBy)="sortDataBy.emit($event)"
(orderColumns)="orderColumns($event)"
(removeColumn)="removeColumn.emit($event)"
Copy link
Member Author

Choose a reason for hiding this comment

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

scalar tables shouldn't be able to remove columns, just hide them. But there will be no functional change atm because this is currently disabled.

Copy link
Contributor

Choose a reason for hiding this comment

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

Once the scalar card show hparam columns I would expect to be able to remove them from there.

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree that showing both "hide" and "remove" buttons is also reasonable, but showing both in the same context menu might make a lot of users wondering what the difference is. Meanwhile, allowing only one of these functionalities per table might make the distinction a bit clearer.

In any case, I think it's important to gather more feedback from the team and from users on what the ideal context menu setup should be. It should be trivial to add/remove items later as necessary.

Copy link
Contributor

Choose a reason for hiding this comment

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

We definitely shouldn't show both in the same context menu. I'm not sure splitting the functionality by table will be clearer for users.

@@ -21,16 +21,16 @@
(selectedTabChange)="tabChange($event)"
>
<mat-tab [label]="'Single'">
<ngContext
Copy link
Member Author

@hoonji hoonji Jan 25, 2024

Choose a reason for hiding this comment

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

ngContext doesn't seem to be a valid directive? replaced with ng-container, which is.

@@ -48,16 +56,27 @@ import {DataTableMode} from '../../../../widgets/data_table/types';
export class ScalarColumnEditorContainer {
constructor(private readonly store: Store<State>) {}

readonly singleHeaders$ = this.store.select(getSingleSelectionHeaders);
readonly rangeHeaders$ = this.store.select(getRangeSelectionHeaders);
readonly singleHeaders$ = this.store
Copy link
Member Author

Choose a reason for hiding this comment

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

runs are now hidden in the edit menu so they will no longer be sortable or hidable

@@ -235,7 +235,8 @@ export class OSSSettingsConverter extends SettingsConverter<
if (
Array.isArray(backendSettings.singleSelectionHeaders) &&
// If the settings stored in the backend are invalid, reset back to default.
backendSettings.singleSelectionHeaders[0].name !== undefined
backendSettings.singleSelectionHeaders[0].name !== undefined &&
backendSettings.singleSelectionHeaders[0].type === 'RUN'
Copy link
Member Author

Choose a reason for hiding this comment

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

adds check when loading from existing localstorage as downstream sorting logic depends on RUN being first

return newColumns;
}

export const DataTableUtils = {
Copy link
Member Author

Choose a reason for hiding this comment

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

this export style is ugly, but necessary due to #5991

@hoonji hoonji requested a review from rileyajones January 25, 2024 09:56
(state, {source, destination, side, dataTableMode}) => {
let headers =
dataTableMode === DataTableMode.RANGE
? [...state.rangeSelectionHeaders]
Copy link
Contributor

Choose a reason for hiding this comment

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

Previously the headers were retrieved from the action, now they are being retrieved from the current state. How can the headers ever change?

Copy link
Member Author

Choose a reason for hiding this comment

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

To clarify:

  • dataTableColumnEdited is currently only used for reordering
  • runs and hparams features already define separate actions for reordering and adding (e.g. runsTableHeaderAdded, runsTableHeaderOrderChanged)

To prevent confusion (and for consistency) I'll change dataTableColumnEdited -> dataTableColumnOrderChanged

Copy link
Member Author

Choose a reason for hiding this comment

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

(a separate dataTableColumnAdded action will be added in an upcoming PR)

Copy link
Contributor

Choose a reason for hiding this comment

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

In that case can you headers from the props?

Copy link
Member Author

@hoonji hoonji Jan 30, 2024

Choose a reason for hiding this comment

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

Wait sorry - I need to correct myself. I did add a dataTableColumnAdded in #6737, but it's unused because we don't actually have a feature for adding standard columns, only hparam columns. Thus, only the hparams action dashboardHparamColumnAdded will be used to add new columns.

Regarding passing headers to the props, I propose that an action signature like dashboardHparamColumnAdded, i.e. only specifying {column, nextTo, side} and letting the reducer figure out how put it in the right place, is more in line with redux best practices, which advocate putting logic in reducers, not components; passing in headers via the action implies that the component must do some data manipulation first.

(Note that the previously implemented runs table add action already uses the "put logic in reducers" pattern, albeit with a slightly different signature.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I fully agree with everything in this statement.
The thing that I find confusing is that the action dataTableColumnEdited takes HeaderEditInfo as props which has an unused attribute headers

@hoonji hoonji requested a review from rileyajones January 29, 2024 11:08
Copy link
Contributor

@rileyajones rileyajones left a comment

Choose a reason for hiding this comment

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

Thanks for sticking with this. I would really like to see the props changed on dataTableColumnEdited but otherwise things look pretty good.
go/small-cls

Base automatically changed from hparam_common_selectors to master January 31, 2024 06:33
@hoonji
Copy link
Member Author

hoonji commented Jan 31, 2024

I would really like to see the props changed on dataTableColumnEdited

Ack - headers should be gone in the latest version

go/small-cls

Yeah my bad, I didn't realize the code would get so bloated after tests 😭 I'll take care to make them smaller next time. Thanks btw for the comprehensive reviews on these huge batches of code!

@hoonji hoonji merged commit 0d76a12 into master Jan 31, 2024
16 checks passed
@hoonji hoonji deleted the hparam_update_reorder branch January 31, 2024 12:58
@hoonji hoonji mentioned this pull request Jan 31, 2024
hoonji added a commit that referenced this pull request Feb 1, 2024
## Motivation for features / changes
Recently merged hparam column PRs (#6732, #6733, #6736) will cause build
and lint errors during 1p sync.

## Technical description of changes
- import map from rxjs/operators instead of rxjs
- `DataTableUtils` -> `dataTableUtils`
- use proper string signature on CardStateMap in tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants