-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Table list view] Add state in URL #145517
Conversation
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.
Great work @sebelga ! Still reviewing, overall code LGTM. However when I tested locally in Dashboard
without these changes:
And with these changes
The "my dash" dashboard is not being filtered out which looks like a regression?
@@ -183,8 +274,8 @@ function TableListViewComp<T extends UserContentCommonSchema>({ | |||
selectedIds: [], | |||
searchQuery: | |||
initialQuery !== undefined | |||
? { text: initialQuery, query: new Query(ast, undefined, initialQuery) } | |||
: { text: '', query: new Query(ast, undefined, '') }, | |||
? { text: initialQuery, query: new Query(Ast.create([]), undefined, initialQuery) } |
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.
nit nit: if I read this correctly looks like we are instantiating this object on every render, is it possible to memoize it?
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.
Good point 👍 Done in c84425b
Thanks for the review @jloleysens ! Full list Searching for "Web" Anything else I should do to reproduce the error? Cheers |
…-ref HEAD~1..HEAD --fix'
… into table-list-view/url-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.
Tested again locally, looks like I had not rebuilt my packages so ignore the issue!
Great work @sebelga !
const params = useQuery<Q>(); | ||
const [urlState, setUrlState] = useState<T>({} as T); | ||
|
||
const updateQuerParams = useCallback( |
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.
const updateQuerParams = useCallback( | |
const updateQueryParams = useCallback( |
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.
Great work!
I played a bit with the listing pages and I found a couple things that I don't think are expected:
- As you type the search query, the query is update on each keystroke and each keystroke gets into the history stack. This leads to a very weird back button experience
- Also I found that back button for sorting doesn't work for me in some case. For example - land on visualise, switch from recently updates to Name A-Z, click back - URL has changed back, but state on the page wasn't update (probably something with the initial state)
sort.back.bug.mov
I'd also suggest considering using history.replace. Not sure this really needs history.
I respect this strategy if this is what your team has decided upon, but I personally feel quite strongly that we should avoid storing this sort of state in the URL for the following reasons:
I would suggest an alternative method to get roughly the same behaviour:
With this implementation any navigation during the session including the back button, would restore the last state unless it was explicitly cleared. The one caveat of this approach is that it doesn't support deep-linking. Is there a use case that requires deep-linking? If so, there are many ways to accomplish it in this paradigm which I can go into more detail on if required. Again, I will approve this if the team is adamant that it's the right direction to go, but I believe that browser or session storage is a better approach. |
@ThomThomson thanks for raising many valid points for consideration. Dashboard was certainly a case in point of why we should try to avoid app state in the URL! I have a few general comments and refinements/counter points that I wanted to share. Happy to talk more sync! I think there are kinds of state that are OK living in the URL. State that: (1) will not need to migrate often (fairly constant over time) (2) state that the application/plugin has full ownership of (3) relatively small in size. A search term and sort state seem to be the kind of "innocuous" state that would be OK to store in the URL given what it enables and relatively simple implementation. One complication with (2) in this case: this component is imported from a package, this means it is reaching into a global resource (the URL) and updating it. To make this "safer" we could lift the search term and sort state to the plugin/application and let them decide where to store it. But for these table list pages I wonder how useful that would be, might just make integration harder without much benefit. FWIW, I am also happy if this were stored in sessionStorage and we used locators for deep linking, I just wanted to share thoughts on state+URL and how I was thinking about it in this case. |
Thanks for your input @ThomThomson and @jloleysens 👍 I agree that this deserve a sync meeting as it could impact many pages and workflows (hopefully in a good way! 😊 ) The goal of this PR is to have the state in the URL. Using the URL as the source of truth and being able to deeplink to a table state. I think we all agree that the fact that Github gives us this URL:
makes our life easier to send a list of issue for our team. It is not a "pretty" URL but a useful one. The goal here is to reproduce this experience, allowing our users to filter the table list based on certain tags and send it over to other users and collaborate on their content. Before going any further I also want to mention: keeping the table state in the URL is optional. It can be turned off with the This should answers your question on "what is the behaviour when there are multiple tables in one page": we would turn the url state off for both table.
Indeed we need to be cautious. For that I'd expect to have solid test coverage like the one I am adding in #145618. Once those are in place we should have confidence that we will handle gracefully possible changes in contract (as I've done here to maintain support for the "title" query param from Dashboard)
I changed that behaviour by using
Not sure I understand your concern. The way it is implemented is (1) update the URL (2) react to url changes. The URL is the source of truth, the app state is derived from it.
Actually I have bumped in the reverse problem. I wanted the state to be reset after navigating to a different app and then clicking on the app link (main menu) to go back I still had the state in the URL... I think there is some magic with the top level Kibana router that I am not aware of and that is currently a blocker. I'll need to investigate.
Answered above. We would turn off the URL state in this case.
From my Github example above, I think the benefit outweights the "cluterness". I would even say the current |
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.
Especially with the feature temporarily disabled, Presentation team changes LGTM.
Thanks for all the discussion about this!
search: '', | ||
}), | ||
useHistory: () => ({ | ||
push: () => undefined, |
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.
Should this be replace
now?
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.
Thanks @Dosant ! yes it seems that this could be it.
@ThomThomson I've disabled the feature by default and hoping to get a green CI. If you agree can you approve and merge the current work and we can re-enable it once we align on the behaviour (and fixes what Anton pointed out)?
Cheers 👍
👍
Let's make sure we've capture the bugs we've found
And I'll create a separate issue to discuss and agree on the kbnUrlTracker stuff. Hope will just agree we can remove it
@sebelga, I created an issue to discuss getting rid of app link url changes #146318 |
@Dosant Not sure I see the workaround in the issue description... 🤔 |
|
Thanks @Dosant The whole thing seem hacky to me. But this workaround could be used to unblock this work. I still think we should remove automagic URL creation and rely on a different mechanism/UX to restore state. |
Update on the PR
@Dosant Can we retake the discussion in case you have any more concern on keeping the filter and sort state of the table in the URL? |
Sorry Anton, I meant to tag @ThomThomson on my above comment. |
Hey @sebelga, yes - I'm convinced that adding filter and sort state in the URL is the right choice here, as I don't see any major problems cropping up due to it! Thanks for checking in again. |
Great, thanks @ThomThomson 👍 |
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.
Visualizations changes LGTM, I tested it locally on the Visualize listing page and works fine
💚 Build Succeeded
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Page load bundle
Unknown metric groupsAPI count
ESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @sebelga |
Thanks for the review @stratoula! 👍 |
In this PR I've updated the
<TableListView />
component to support storing the table state (search term, tag selection, column sorted and sorting direction "asc" or "desc").This allow deep linking to a particular state of the table list view. This also allows using the back button of the browser and going back to the filtered table to open another content.
Note: Tests will come in a following PR.
Release note
The list view of the Dashboard, Visualize library, Maps and Graphs apps now store the latest state of the table in the URL to allow quickly go back to a filtered table.
Fixes #135203