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

issue 1478/column width #1505

Merged
merged 1 commit into from
Sep 6, 2023
Merged

issue 1478/column width #1505

merged 1 commit into from
Sep 6, 2023

Conversation

kaulfield23
Copy link
Contributor

Description

This PR fixes a bug that columns' widths in view is not saved as user set. It goes back to the default width(150) after sorting or refreshing the page.

Screenshots

New.View.Mozilla.Firefox.2023-09-06.11-44-44.mp4

Changes

  • Adds export to loadConfig
  • Adds property onColumnResize
  • Adds saved widths from localStorage to columns

Notes to reviewer

I used loadConfig. I found another bug(#1039 ) while I work on this, and thought loadConfig could be useful for fixing that issue later on

Related issues

Resolves #1478

Copy link
Member

@niklasva82 niklasva82 left a comment

Choose a reason for hiding this comment

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

This looks good to me and verified to be working!

@kaulfield23 kaulfield23 merged commit eae969b into main Sep 6, 2023
4 checks passed
@kaulfield23 kaulfield23 deleted the issue-1478/column-width branch September 6, 2023 12:45
Copy link
Member

@richardolsson richardolsson left a comment

Choose a reason for hiding this comment

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

This PR should not have been merged as is. It is much too complicated to achieve what it does. It could have used useConfigurableDataGridColumns correctly and just worked, instead of making changes to the interface of the useConfigurableDataGridColumns.

There were red flags here (see below) and I think it was a mistake to approve it. I have asked @kaulfield23 to submit a new PR that replaces the changes in this PR with more reasonable ones. All in all, a good learning experience for anyone who wants to learn from it.

@@ -98,7 +98,7 @@ export default function useConfigurableDataGridColumns(
};
}

function loadConfig(storage: StorageBackend, key: string): ColumnConfig {
export function loadConfig(storage: StorageBackend, key: string): ColumnConfig {
Copy link
Member

Choose a reason for hiding this comment

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

This is a major red flag. Never export something like this without first fully understanding it (and never approve such exports without understanding whether they're necessary).

There are two red flags here:

  1. In general, exporting something that was previously not exported is a red flag in itself. Assume that the person who wrote the code refrained from exporting for a reason. Make sure you understand why, before going against that original design.
  2. The name of this module is useConfigurableDataGridColumns. It had a single default export by the same name (and some relevant types). This is a common pattern. The name of the module indicates that it should have a single export. Adding another export probably goes against the original author's design, and if it does, there better be a good reason (which requires first understanding that design).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the feedback! It is really helpful and I will make a note of it so it wouldn't be repeated!

...columnTypes[col.type].getColDef(col, accessLevel),
})),
];
const { setColumnWidth } = useConfigurableDataGridColumns(
Copy link
Member

Choose a reason for hiding this comment

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

This hook returns an object which includes the re-configured columns. It would have been possible to just do:

const { columns: gridColumns, setcolumnWidth } = useConfigurableDataGridColumns(

(And make the necessary changes to avoid the naming conflict of gridColumns).

This would have made all other changes in this PR unnecessary.

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.

View column width not saved when sorting
3 participants