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

Simplify working with columns #40

Merged
merged 4 commits into from
Nov 2, 2022
Merged

Conversation

NullVoxPopuli
Copy link
Contributor

@NullVoxPopuli NullVoxPopuli commented Oct 20, 2022

This was a feature request / feedback from @vitch a while back when we were first open sourcing this library.


Motivation

Prior to this PR, working with columns from the plugins in a hierarchical way leaked the hierarchy between the plugins, preventing consistent use of columns APIs for the consumer -- a plugin author would need to know the hierarchy, and know which plugin to access to get the correct columns.

This has now all bee abstracted away in a new set of queries helpers called columns.


Requires: #12

  • implement "optionally requires" to imply a hierarchy, as hard-requiring another plugin to be used "should be" rare can be done in a later PR, when the need arises
  • implement helpers
    • columnsForPlugin(table, requestingPlugin)
      gets the columns appropriate for the requesting plugin - automatically figures out plugin hierarchy
    • these helpers are plugin-relative, based on columnsForPlugin (but that's an implementation detail)
      • nextColumn(focusedColumn, requestingPlugin)
      • previousColumn(focusedColumn, requestingPlugin)
      • columnsAfter(column, requestingPlugin)
      • columnsBefore(column, requestingPlugin)
  • ensure that all plugins can be used in isolation
    • ColumnResizing
    • StickyColumns
    • ColumnReordering
    • ColumnResizing

For review

First, you'll want to look at the tests, in particular for ColumnReordering and ColumnResizing -- these are refactors that were enabled after all the above was implemented.

Then, you'll want to read through the changes to plugin/-private/base.ts, and then see how those changes had an effect on each plugin.

I'm hesitant to update the demos to match the tests now, because the non-gjs ergonomics are really sub-par, and I need to add gjs/gts support to Docfy. I have minimally updated the demos that were directly accessing plugins' Meta to get the columns tho.

@NullVoxPopuli NullVoxPopuli force-pushed the simplify-working-with-columns branch 3 times, most recently from b8ca44b to 31e70e0 Compare October 22, 2022 22:09
@github-actions
Copy link
Contributor

github-actions bot commented Oct 24, 2022

@NullVoxPopuli NullVoxPopuli force-pushed the simplify-working-with-columns branch 2 times, most recently from adc2e7a to 98b31af Compare October 26, 2022 05:33
* This works recursively up the plugin tree up until a plugin has no requirements, and then
* all colums from the table are returned.
*/
function columnsFor<DataType = any>(
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 is the code that powers all the refactors in this PR.

It's also some of the messier code.
I wasn't really in a headspace to do recursive trees, so this is what works for now.

If we add another plugin that needs to tweak columns rendered, then we'll have to do this proper

@@ -45,6 +44,10 @@ export class ColumnReordering extends BasePlugin<Signature> {

tableMeta.reset();
}

get columns() {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

new API on plugins -- allows overriding of what columns should be rendered

@NullVoxPopuli NullVoxPopuli marked this pull request as ready for review October 26, 2022 05:37
There is now a new "columns" query-API that "does the right thing",
based on a "requester" (plugin class).
There is a hierarchy of column behaviors that can be statically known,
and the resolution of columns allows plugins to be independent of other
plugins, while also layering in the correct order, based on if the
plugin defines a columns property.
@NullVoxPopuli NullVoxPopuli force-pushed the simplify-working-with-columns branch from 4d45e14 to 355e4ab Compare October 26, 2022 05:53
Copy link
Contributor

@ynotdraw ynotdraw left a comment

Choose a reason for hiding this comment

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

This is super exciting. I really appreciated all of the in-depth comments to help with documentation and explain how/why things work!

docs/plugins/sticky-column/index.md Outdated Show resolved Hide resolved
ember-headless-table/src/plugins/-private/base.ts Outdated Show resolved Hide resolved
ember-headless-table/src/plugins/-private/base.ts Outdated Show resolved Hide resolved
import { meta } from 'ember-headless-table/plugins';
import { ColumnVisibility } from 'ember-headless-table/plugins/column-visibility';
import { meta, columns } from 'ember-headless-table/plugins';
import { ColumnVisibility, hide, show } from 'ember-headless-table/plugins/column-visibility';
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice, I like how these methods (hide & show) are exposed (same with above plugin tests) - this is really clean!

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! <3

test-app/tests/plugins/queries/columns-test.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@nicolechung nicolechung left a comment

Choose a reason for hiding this comment

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

Looks good to me, I left a few small comments but maybe I am still learning the new API

@NullVoxPopuli NullVoxPopuli merged commit ebb6675 into main Nov 2, 2022
@NullVoxPopuli NullVoxPopuli deleted the simplify-working-with-columns branch November 2, 2022 19:51
@github-actions
Copy link
Contributor

github-actions bot commented Nov 2, 2022

🎉 This PR is included in version 1.0.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

assert(`First argument passed to columns.for must be an instance of Table`, table[TABLE_KEY]);

let visibility = findPlugin(table.plugins, 'columnVisibility');
let reordering = findPlugin(table.plugins, 'columnOrder');
Copy link
Contributor

Choose a reason for hiding this comment

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

Trying to work on #152 and stumbled across this after some digging...

Is this how the column order plugin ends up getting the columns with visibility already applied?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, there is a graph of plugins determined at lookup time. You can choose:

  • get all columns
  • get columns for the plugin (subject to the graph)
  • get user land columns (after all plugins are applied)

Copy link
Contributor

Choose a reason for hiding this comment

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

I get that the column order plugin needs to be aware of individual column's visibility values but I think it still needs to be able to loop over all columns...

Looking at those things you can choose, after a bunch of clicking through the code I think the APIs are:

  • get all columns: table.columns (assuming you have a reference to table, otherwise you'll need to thread it down
  • get columns for the plugin (subject to the graph): columns.for(table, PluginClass) (again, you need a reference to the table
  • get user land columns (after all plugins are applied): I haven't needed this one yet so I haven't found it...

Does that seem right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ye! 🎉

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.

5 participants