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

Refactor Antd Table columns #7772

Merged
merged 13 commits into from
May 14, 2024
Merged

Refactor Antd Table columns #7772

merged 13 commits into from
May 14, 2024

Conversation

hotzenklotz
Copy link
Member

In preparation for upgrading to React 17 (#7765), I ran into trouble with Typescript and infinite recursions ("type definition to deep") resulting in crashes. Most likely this is not caused by the React update per se but some other dependency, likely any from the rc-* packages used by antd.

In particular, Typescript was unhappy with the type RowRenderer in any of the table <Column> elements:

<Column
   ...
  render: (_name: string, rowRenderer: RowRenderer) => rowRenderer.renderNameColumn()
/>

Instead of using <Column /> children for the FixedExpandableTable, I refactored this components to use objects and props instead, e.g. <Table columns={ ... } />. Judging from the antd documentation this seems to be the preferred way these days. (Similar to <Dropdown />, <Menu /> etc).

Steps to test:

  • Make sure that Dashboard > Datasets table works
  • Make sure that Admin > Tasks table works

Issues:


(Please delete unneeded items, merge only when none are left open)

@hotzenklotz hotzenklotz mentioned this pull request Apr 26, 2024
11 tasks
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer 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 fixing this 🎉

Judging from the antd documentation this seems to be the preferred way these days. (Similar to ,

etc).

Yes, you are correct as far as I remember 👍

Thanks for this PR. Please find my comments below.

One thing: The PR does not state why moving the column definition into an object instead of an react child fixes the Typescript hiccup. In case you know why, please add a short explanation in a comment in case someone later comes back to this PR and thus gets the proper reasoning / understanding for this change 🙏

Once the mini feedback is applied I'd say its all green 🟢

frontend/javascripts/components/fixed_expandable_table.tsx Outdated Show resolved Hide resolved
@@ -26,6 +26,7 @@ For upgrade instructions, please check the [migration guide](MIGRATIONS.released
- Toasts are shown until WEBKNOSSOS is running in the active browser tab again. Also, the content of most toasts that show errors or warnings is printed to the browser's console. [#7741](https://github.com/scalableminds/webknossos/pull/7741)
- Improved UI speed when editing the description of an annotation. [#7769](https://github.com/scalableminds/webknossos/pull/7769)
- Updated dataset animations to use the new meshing API. Animitation now support ad-hoc meshes and mappings. [#7692](https://github.com/scalableminds/webknossos/pull/7692)
- Slightly refactored the `<FixExpandleTable/>`component to use columns as props. [#7772](https://github.com/scalableminds/webknossos/pull/7772)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd say that the changelog entry is not necessary as these changes are not user facing. But feel free to keep this :)

key: "name",
sorter: Utils.localeCompareBy<RowRenderer>((rowRenderer) => rowRenderer.data.name),
sortOrder: sortedInfo.columnKey === "name" ? sortedInfo.order : undefined,
render: (_name: string, rowRenderer: RowRenderer) => rowRenderer.renderNameColumn(),
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer Apr 30, 2024

Choose a reason for hiding this comment

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

You still have the RowRenderer type here. So moving this type into the column prop definition fixes the bug / recursive definition? Sorry, the PR description wasn't that clear to me to why this is actually fixing the typescript hiccup.

@hotzenklotz
Copy link
Member Author

One thing: The PR does not state why moving the column definition into an object instead of an react child fixes the Typescript hiccup. In case you know why, please add a short explanation in a comment in case someone later comes back to this PR and thus gets the proper reasoning / understanding for this change 🙏

I don't know why React v17 + Typescript ran into an issue. I can only assume that TS tries to automagically infer types for <Table /> children and that the React v17 internals changed somehow which leads to an infinite recursion and TS crashing. The solution in the PR applies more(manual) type hints for the column children leading to less dark type magic by TS.

Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer 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 applying the suggestion.

Let's :shipit: 🚢

@MichaelBuessemeyer MichaelBuessemeyer self-requested a review May 6, 2024 11:34
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

I think I found a bug, let me quick investigate before merging

@MichaelBuessemeyer MichaelBuessemeyer self-requested a review May 6, 2024 11:42
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

I found the bug: It was cased by name shadowing. Please see my comments below.

After this is fix, please ask for a quick re-testing that then it should be ready to merge (hopefully 🙈).

And sorry for the take backsies, but it was necessary

frontend/javascripts/admin/task/task_list_view.tsx Outdated Show resolved Hide resolved
</div>
{task.status.pending > 0 ? (
<div>
<LinkButton onClick={_.partial(assignTaskToUser, task)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Here is an example that causes the rendering to crash as the current code shadows the lodash variable

</div>
) : null}
<div>
<LinkButton onClick={_.partial(deleteTask, task)}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Here as well btw :)

key="actions"
width={170}
fixed="right"
render={(__, task: APITask) => (
Copy link
Contributor

Choose a reason for hiding this comment

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

The previous code seems to have used two underscores to avoid the shadowing. Imo using _unused is more explicit and easier to spot than using two underscores to avoid the name shadowing. Therefore, the _unused approach is more explicit and therefore imo more preferable.

@MichaelBuessemeyer MichaelBuessemeyer self-requested a review May 6, 2024 14:25
Copy link
Contributor

@MichaelBuessemeyer MichaelBuessemeyer left a comment

Choose a reason for hiding this comment

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

Now it works 🎉

@hotzenklotz hotzenklotz enabled auto-merge (squash) May 13, 2024 06:56
@hotzenklotz hotzenklotz merged commit d08a865 into master May 14, 2024
2 checks passed
@hotzenklotz hotzenklotz deleted the table-columns branch May 14, 2024 07:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants