-
Notifications
You must be signed in to change notification settings - Fork 12
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
faster sortable table #1740
faster sortable table #1740
Conversation
Only if you find a nice way to
Another thing I recall is that SortableTable is for client only data, but it has some styling on headers. Is there a way to have a config that would make SortableTable work with a remote data source also? I think that supporting optional pagination and remote data source will allow us to design a better component api. But, we can always iterate on a V7 with that and leave pagination and remote out of the picture for now. |
6e7043c
to
cb83dc4
Compare
@@ -326,15 +314,15 @@ dataWithCode = | |||
|
|||
{-| -} | |||
type alias State = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💭 let's make this type opaque
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
f8b3ddd
to
42525da
Compare
870e3bf
to
f28e4e2
Compare
07de989
to
0800441
Compare
74bdc4c
to
2ef31c5
Compare
c2655d4
to
678adf7
Compare
src/Nri/Ui/SortableTable/V6.elm
Outdated
{ column : id | ||
, sortDirection : SortDirection | ||
, entries : Dict.Dict ( id, SortDirection ) (List entry) | ||
, sorter : id -> Sorter entry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we need this to rebuild the model with new entries. The config of the table is usually in the view function.
This is fine, I personally would move into an idiom of having a tableConfig
as a top level function that we can use from the view and from the update. That way we avoid the need to store functions in the model. But is fine as is. Just sharing thoughts.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you elaborate here. I don't totally see what you'd do to make this better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we do
type alias Columns id entry msg = List (Column id entry msg)
rebuild : Config data id -> Model id entry -> List entry -> Model id entry
view : Config data id -> List (Attribute id entry msg) -> Html msg -- flip the order of the first two arguments
update : Config data id -> Msg id -> Model id entry -> Model id entry
Then the model no longer needs the sorter. It deviates from other Nri.Ui components a little bit. But the config is usally fixed and bound to a specific "table instance", but we need to wire things manually for each rebuil / view / update.
Otherwise we could give more "essence" to a "table instance"
myTable =
let
config = ...
in
{ rebulid = SortableTable.rebuild config
, view = SortableTable.view config
, update = SortableTable.update config
}
view = ...
myTable.view ...
Again, nothing wrong with the current design. Just a thought.
src/Nri/Ui/SortableTable/V6.elm
Outdated
|
||
|
||
{-| -} | ||
init : id -> List (Column id entry msg) -> List entry -> Model id entry |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the init
, rebuild
haves a mandatory List entry
and the config can have a missing state it seems the user will be forced to do some tricky stuff to implement a "refresh button".
Should we make init
and rebuild
have a Maybe (List entry)
instead?
I imagine:
- the app makes a request to load some entries remotely
- we don't have a table model yet.. ok. In the view I will not pass a model doing List.filerMap or something
- the app get the request
- we can initialize a table model now, with some choice of which column to sort with
- the user changes the sorting
- we have a refresh button to refetch things (but preserving the order) how we do that?
- we need to know that the records are in Loading state, and in that case we don't include a model
- we then rebuild the table model when the records arrived
- it works but is odd that we need to leave the table model out of sync. we could at least rebuild it with an empty list of entries...
But if the List entry
becomes a Maybe (List entry)
we can rebuild things more easily and straight forward from a RemoteData (as anything that is not Succeed is mapped to Nothing).
(Slightly odd that the loading state don't show the arrows in the table header)
Not 100% sure. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah I think this is a good idea.
21dab09
to
6ed4544
Compare
6ed4544
to
3391cda
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
What changes does this release include?
Adds a more performant sortable table by caching sorted data in the state.
easiest to review commit-by-commit
How has the API changed?
Please paste the output of
elm diff
run on latest master in the code block:Rejiggers the API for SortableTable a bit.
update
functionSortableTable
has no model attribute, it is "Loading", else it is loaded.