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

[WIP] Reordering hidden columns #185

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

vitch
Copy link
Contributor

@vitch vitch commented May 17, 2023

This PR addresses #152 by tweaking the way reordering is done...

From the commit message of the last commit:

In order to make the previously added test pass we need to give
the column reordering plugin access to all columns, not just the
visible ones.
When moving left or right we need to iteratively swap the position
of adjacent columns, continuing until we have swapped with a visible
column.
There are some failing tests for internals of the component on this
commit but they can be fixed up later. I want to see if the new UX
is desirable.

There is also some implementation tweaks I'd like to make (using a
simple for loop would be more efficient because I could use the index
in the array to do the swapping) but I can do that in a separate
commit.

I'm also not sure if we could do away with or simplify the entire
swapWith function (and maybe even orderOf?). There are some
TODOs in the code as well for edge cases to clean up. At the moment
I'm looking for verification that the approach seems sound and the
generated UX is an improvement...

@changeset-bot
Copy link

changeset-bot bot commented May 17, 2023

⚠️ No Changeset found

Latest commit: 41811bb

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vitch vitch force-pushed the reordering-hidden-columns branch 2 times, most recently from d42a1db to e1d905b Compare May 17, 2023 22:29
@joelamb joelamb force-pushed the turbo-and-sync-pnpm branch 4 times, most recently from 22b1ede to 3e471a7 Compare May 22, 2023 10:12
Base automatically changed from turbo-and-sync-pnpm to main May 22, 2023 13:34
@vitch vitch force-pushed the reordering-hidden-columns branch from 5795ecc to 20234d1 Compare May 24, 2023 10:38
@github-actions
Copy link
Contributor

github-actions bot commented May 24, 2023

vitch added 3 commits July 4, 2023 10:41
As described in #152, the behaviour when reordering over hidden columns
is incorrect. This test illustrates the expected behaviour so that we
can fix the implementation.
To make it easier to play with show/hiding then moving columns
vitch added 5 commits July 4, 2023 11:11
In order to make the previously added test pass we need to give
the column reordering plugin access to _all_ columns, not just the
visible ones.

When moving left or right we need to iteratively swap the position
of adjacent columns, continuing until we have swapped with a visible
column.

There are some failing tests for internals of the component on this
commit but they can be fixed up later. I want to see if the new UX
is desirable.
By adding any missing columns to the end of the list whenever the
data is passed _in_ we will be able to simplify any logic around
reordering because it will know that it is dealing with a full
set of columns
This is the next piece of guaranteeing that we are dealing with a
full set of positions within the addon code. By verifying on input
we can save ourselves verifying on every calculation / output.
It turns out that we can't test this functionality because we're hitting
some asserts in other functionality which should now be considered
unnecessary so we'll have to do some other cleaning up before this test
can go green.
@vitch vitch force-pushed the reordering-hidden-columns branch from d6a1f27 to 3139ad6 Compare July 4, 2023 10:24
@@ -297,11 +297,12 @@ module('Plugins | columnReordering', function (hooks) {
assert.strictEqual(getColumnOrder(), 'A B C D');
});

test('without setting the order of anything, we cannot retain the order of the columns when they are added or removed', async function (assert) {
test.skip('without setting the order of anything, we retain the order of the columns when they are added or removed', async function (assert) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test is currently skipping because it fails.

The plugin no longer supports the columns being mutated after the initial render from outside the table. Is this a legitimate thing that consumers should be able to do or was it just a simple way to initially write this test?

cc @NullVoxPopuli

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, there are 3 use cases that i'm aware of:

  • reorder each column live / immediately (like in this repos demos)
  • reorder after submitting a form (setting the whole order at once) -- this is something common in table settings menus -- and relie(d|s) on a duplicate version of the ColumnOrder class (i forget the name) to have the same behavior as the columns.
  • same as above, but without form submit.editing in a menu immediately changes the table (a hybrid of the prior two approaches, ux wise)

In all 3 of these, order is mutated from outside the table, so maybe i'm missing something, and need to go through the code.

Copy link
Contributor Author

@vitch vitch Jul 4, 2023

Choose a reason for hiding this comment

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

reorder each column live / immediately (like in this repos demos)

This works by using the plugins API, not by mutating the passed array

reorder after submitting a form

There is an API for this too (setAll IIRC)

editing in a menu immediately changes the table

I think that could use the API too...

I guess the bigger question is - should we expect consumers to use provided APIs to do things or should we let them mutate the inputs?

Copy link
Contributor

Choose a reason for hiding this comment

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

This works by using the plugins API, not by mutating the passed array

Ah i see, that was the key part i was missing when you said mutation -- like a TrackedArray that has had additional columns added or removed or something.

should we expect consumers to use provided APIs to do things or should we let them mutate the inputs?

I mean, one of the nice things deriving data from inputs gets us is that all of that can be handled.

Like, it could be a choice to require tearing down and recreating whatever when additional data is added to the table, but predefining all that before rendering is a common enough pattern, where it should probably be ok... If people want to asynchronously add more columns, they could probably deal with extra computation needed to re-position, re-size, etc the existing columns in addition to the new columns.

Like, personally, i'm not a fan of (what i see as) breaking reactivity (we can't know how deep or shallow a reactive abstraction is, and when we assume any depth, we can inherently any consuming usage -- now, maybe the maintainence burden in too great here, and that's fine! An assertion or something could be added to communicate that mutating the array passed to the ColumnOrder class isn't supported (tho, idk how common of a use case it is -- it's all kind of 'possibilities' here ))

So that we don't need to worry about checking for and filling
consecutive slots throughout the code
@johanrd
Copy link
Contributor

johanrd commented May 22, 2024

@vitch hey, great work.

I'm curious: What did you end up doing here – are you using this functionality in a fork?

@vitch
Copy link
Contributor Author

vitch commented May 22, 2024

@vitch hey, great work.

I'm curious: What did you end up doing here – are you using this functionality in a fork?

I'm afraid I did the work because I needed it at work and I no longer work there... @joelamb might know if there is any active work on it?

@NullVoxPopuli
Copy link
Contributor

Would there be interest in more distributed maintenance?

repo could be transferred to https://github.com/universal-ember/ ?

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.

None yet

3 participants