Skip to content
This repository has been archived by the owner on Dec 10, 2021. It is now read-only.

feat: add drag and drop column rearrangement for table plugin #1423

Closed

Conversation

stevetracvc
Copy link
Contributor

@stevetracvc stevetracvc commented Oct 22, 2021

🏆 Enhancements
Add the ability for the end user to drag and drop columns for a table visualization

📜 Documentation
Table designer can enable column rearrangement in the config options when building the table. Then, user can drag columns around

These are volatile changes, so when the browser is refreshed, the column order goes back to default. Demo is in the chart edit page, which is just for simple demonstration purposes. This is intended for the end user to be allowed to rearrange the columns.

Not enabled
chrome-capture

Enabled
chrome-capture (1)

closes #1420

@stevetracvc stevetracvc requested a review from a team as a code owner October 22, 2021 19:57
@vercel
Copy link

vercel bot commented Oct 22, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/superset/superset-ui/Erf3zM6ixAtL3GuyvxPXXhJPBmDu
✅ Preview: https://superset-ui-git-fork-stevetracvc-feat-dnd-table-385f18-superset.vercel.app

@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #1423 (ecc1a4f) into master (3e16995) will decrease coverage by 0.02%.
The diff coverage is 20.83%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1423      +/-   ##
==========================================
- Coverage   30.91%   30.89%   -0.03%     
==========================================
  Files         502      502              
  Lines       10220    10243      +23     
  Branches     1762     1765       +3     
==========================================
+ Hits         3160     3165       +5     
- Misses       6808     6825      +17     
- Partials      252      253       +1     
Impacted Files Coverage Δ
...ugin-chart-table/src/DataTable/hooks/useSticky.tsx 4.25% <0.00%> (ø)
plugins/plugin-chart-table/src/controlPanel.tsx 0.00% <ø> (ø)
plugins/plugin-chart-table/src/transformProps.ts 63.63% <ø> (ø)
...ins/plugin-chart-table/src/DataTable/DataTable.tsx 34.82% <17.64%> (-3.08%) ⬇️
plugins/plugin-chart-table/src/TableChart.tsx 38.35% <33.33%> (-0.22%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3e16995...ecc1a4f. Read the comment docs.

@villebro
Copy link
Contributor

villebro commented Nov 1, 2021

I think this is a great improvement @stevetracvc! To make these changes stick, however, it would be nice if we could add drag'n'drop support to the "Customize columns" control, which would persist the order. If we added that support, do you think that would be sufficient, or would it make sense to also support the temporary column rearrangement introduced in this PR?

@stevetracvc
Copy link
Contributor Author

stevetracvc commented Nov 1, 2021

@villebro I don't think it's nearly as useful to the table designer, as there's already the drag-and-drop in the list of columns for reorganizing the columns on that page. This is intended to be used by the end users, so they can customize it to their liking. I only did the video on the explore page so you could see what happens after adding the check mark :) But if you think designers would want it too, that's another discussion. :)

And since it's the end users doing the reordering, I didn't see any need to make the new ordering stick (at least globally, as someone could really screw with the rearrangement and ruin it for everyone).

One possible addition I can see would be to make an individual user's reorganization something that's stored in the local session, so that coming back in the future, the columns would be in the same order. But that seems like it could get messy and we'd need to figure out how to make sure that it's the same: user, dashboard, table, among other things, to make sure there's no adverse affects.

From my testing, applying new filters and even force refreshing the data does not reset the column order, it only resets when you browser refresh the dashboard.

@stevetracvc
Copy link
Contributor Author

stevetracvc commented Nov 1, 2021

Another thing I just noticed...column widths currently will only update after a data refresh
fixed

added a toggle val to keep track of whether the columns were rearranged.
if so, then force getColumnConfigs to recalculate the widths
@junlincc
Copy link
Contributor

This is a great improvement! Thank you @stevetracvc It works similar to googlesheet and I don't think adding a control in the panel is necessary. but I do agree the changes should persist while the chart is added to dashboard.

@villebro If the code looks ok and test is sufficient , I think we should merge it in and make incremental improvement later.

@stevetracvc
Copy link
Contributor Author

@junlincc are you saying you think the column order should persist on a given end user's computer, even after closing the browser and coming back?

I think that'd be nice, but I also think it'd be great for all the filters and such to be remembered too. From what I can tell, it appears that the general design of Superset is for it to start from scratch every time the dashboard is reloaded. Is there any infrastructure yet to make any user settings non-volatile? Stored for the user in the database?

When toggling the dnd feature, it was adding or removing the useColumnOrder
hook which changed the dimensions of the memoization array. Now, useColumnOrder
is always enabled, but the column headers themselves aren't drag or drop targets
when the feature is disabled.
@rusackas
Copy link
Member

I think @junlincc's comment is intending to state that if a chart author rearranges columns, and then hits Save, then that column order should be persisted with the chart and reflected on dashboards.

I think the proper way to do this might be to have the drag and drop action also update the form data and update the order of the control values to match (dynamic controls, essentially). Then saving it would persist the form data that way, and all would be well.

Dashboard consumers could still re-order columns as much as they'd like, without persisting the state there.

@stevetracvc
Copy link
Contributor Author

stevetracvc commented Nov 30, 2021

@rusackas ok, but a few questions:

  1. does the table designer really need to be able to rearrange columns in so many ways? dnd is already an option for the column layout in the COLUMNS area of the table design.
  2. Can I accomplish this by just overwriting the all_columns value in the formData object with the array of columns in the new order? I'm not sure how to overwrite formData. I'm still looking.
  3. how can I tell whether the table is in edit mode, vs it's just some random user viewing the table? Is there harm in updating the formData object if the table is actually in a dashboard and being manipulated by the user? I get that the metadata database wouldn't be updated since the dashboard wouldn't have a "save" button, but is it bad practice to modify this when it's not necessary?

@villebro
Copy link
Contributor

The codebase on this repo has been moved to the main Apache Superset repo, and consequently the repo is in the process of being archived. See the Superset Improvement Proposal for details: apache/superset#13013 . While all currently open issues and PRs will be closed, we encourage you to reopen this PR on the main repo, which should be as simple as moving over any code changes as follows:

  • core packages: packages/** (this repo) -> superset-frontend/packages/** (main repo)
  • plugins: plugins/** (this repo) -> superset-frontend/plugins/** (main repo)

If you need help with the migration, please post a message on the SIP or reach out on the community Slack.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Drag and Drop user-reorganizable columns in the Table Viz
4 participants