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

[RAC] Store Alerts View table state in localStorage #118207

Merged
merged 19 commits into from
Nov 22, 2021

Conversation

Zacqary
Copy link
Contributor

@Zacqary Zacqary commented Nov 10, 2021

Summary

Closes #117698

On the Alerts View, this PR stores the state of columns and sort in localStorage.

Checklist

@Zacqary Zacqary added release_note:enhancement v8.0.0 Feature:RAC label obsolete v8.1.0 Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" labels Nov 10, 2021
@Zacqary
Copy link
Contributor Author

Zacqary commented Nov 11, 2021

@XavierM Wondering if you can help me figure out how to replicate the things you were doing with TGrid state in the security solution.

I was hoping to add a state subscriber to the TGrid Redux component, and to merge some prefilled selectedEventIds into the initialTGridState there, but I wasn't able to delete the Timeline Plugin's this._store without crashing Kibana.

I ended up attaching the subscriber in getTGrid, but I wasn't able to figure out how to pass in any initial state, so I'm initializing some preselected rows using some hacky useEffect code.

I'm wondering how you managed to get the this._store = undefined line in getTGrid to function without crashing, because I think that would help me implement the subscriber and initial state functionality in a cleaner way.

# Conflicts:
#	x-pack/plugins/observability/public/pages/alerts/alerts_table_t_grid.tsx
# Conflicts:
#	x-pack/test/observability_functional/apps/observability/index.ts
@Zacqary Zacqary marked this pull request as ready for review November 15, 2021 18:30
@Zacqary Zacqary requested a review from a team as a code owner November 15, 2021 18:30
@elastic elastic deleted a comment from kibanamachine Nov 15, 2021
@Zacqary Zacqary requested a review from a team November 16, 2021 16:57
@XavierM
Copy link
Contributor

XavierM commented Nov 16, 2021

let me take a look

@Zacqary
Copy link
Contributor Author

Zacqary commented Nov 16, 2021

Update: Removed the behavior of persisting selected rows rather than trying to find a technical solution, as it's not good UX anyway. If the sort changes or new rows are added, the selected rows could disappear from view but still be selected.

Copy link
Contributor

@claudiopro claudiopro 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! I would also add a functional test for adding a column, but looks good to ship as-is.

if (props.onTGridStateChange) {
this._storeUnsubscribe = this._store.subscribe(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
throttle(() => props.onTGridStateChange!(getState()), 500)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the ! a TS feature? I would expect the optional chaining operator ?. here.

Copy link
Contributor Author

@Zacqary Zacqary Nov 18, 2021

Choose a reason for hiding this comment

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

! is to tell TS that a value is definitely not null. In this case, we already did an if (props.onTGridStateChange) check, but for some reason that's not good enough for Typescript here? So I had to add this ! operator to assure the compiler that everything is fine.

You'll notice I had to disable the linting rule:

// eslint-disable-next-line @typescript-eslint/no-non-null-assertion

Usually we don't want to use this ! operator if it's avoidable, but in this case there must be some deeper architectural issues going on if the surrounding if block isn't reassuring the compiler that everything is okay. Out of the scope of this PR, IMO. It's probably something with the different proptypes for standalone vs integrated TGrids.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok and now I just tried removing the ! and it's no longer erroring anymore???? What are computers what is typescript I don't know what's going on

Copy link
Contributor Author

Choose a reason for hiding this comment

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

LOL NOPE it broke again but my VSCode didn't realize it until after I already merged and pushed

@@ -107,6 +107,7 @@ export interface TGridStandaloneProps {
itemsPerPageOptions: number[];
query: Query;
onRuleChange?: () => void;
onTGridStateChange?: (state: State) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: what about simply onStateChange? None of the other props references the TGrid explicitly. This one somewhat couples the component interface (props) with the concrete implementation.

Copy link
Contributor

@claudiopro claudiopro left a comment

Choose a reason for hiding this comment

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

Moving to request changes to flag build failures - the PR does not seem complete.

@Zacqary
Copy link
Contributor Author

Zacqary commented Nov 18, 2021

@elasticmachine merge upstream

@Zacqary
Copy link
Contributor Author

Zacqary commented Nov 18, 2021

@claudiopro Build failures block merges, so you don't need to switch to Request Changes in the future if you spot that

Copy link
Contributor

@claudiopro claudiopro left a comment

Choose a reason for hiding this comment

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

LGTM! Ship it 🚀

@Zacqary Zacqary enabled auto-merge (squash) November 22, 2021 17:33
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
timelines 869 879 +10

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
observability 353.2KB 353.9KB +733.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
timelines 164.4KB 164.6KB +206.0B
Unknown metric groups

API count

id before after diff
timelines 987 1013 +26

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@kqualters-elastic kqualters-elastic left a comment

Choose a reason for hiding this comment

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

eventually I think it would make sense to have this done via adding a new prop to tGrid, like propsToPersist: ['columns', 'sort'] or something, as a separate plugin shouldn't have to serialize parts of the redux store, that's an implementation detail of the plugin but this works and lgtm 👍

@Zacqary Zacqary merged commit c012dd8 into elastic:main Nov 22, 2021
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Nov 24, 2021
@kibanamachine
Copy link
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create backports run node scripts/backport --pr 118207 or prevent reminders by adding the backport:skip label.

Zacqary added a commit to Zacqary/kibana that referenced this pull request Nov 24, 2021
* [RAC] Store Alerts View table state in localStorage

* Use Redux store subscriber instead of callback

* Fix typecheck

* Fix bad merge

* Add tests

* Remove persisting selected rows

* Fix bad merge

* onTGridStateChange => onStateChange

* Remove non-null assertion

* Put non-null assertion back because typescript hates me, personally

* Fix checks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Nov 25, 2021
Zacqary added a commit that referenced this pull request Nov 25, 2021
* [RAC] Store Alerts View table state in localStorage

* Use Redux store subscriber instead of callback

* Fix typecheck

* Fix bad merge

* Add tests

* Remove persisting selected rows

* Fix bad merge

* onTGridStateChange => onStateChange

* Remove non-null assertion

* Put non-null assertion back because typescript hates me, personally

* Fix checks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
dmlemeshko pushed a commit that referenced this pull request Nov 29, 2021
* [RAC] Store Alerts View table state in localStorage

* Use Redux store subscriber instead of callback

* Fix typecheck

* Fix bad merge

* Add tests

* Remove persisting selected rows

* Fix bad merge

* onTGridStateChange => onStateChange

* Remove non-null assertion

* Put non-null assertion back because typescript hates me, personally

* Fix checks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@KOTungseth KOTungseth added the Team:APM - DEPRECATED Use Team:obs-ux-infra_services. label Dec 8, 2021
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:apm)

TinLe pushed a commit to TinLe/kibana that referenced this pull request Dec 22, 2021
* [RAC] Store Alerts View table state in localStorage

* Use Redux store subscriber instead of callback

* Fix typecheck

* Fix bad merge

* Add tests

* Remove persisting selected rows

* Fix bad merge

* onTGridStateChange => onStateChange

* Remove non-null assertion

* Put non-null assertion back because typescript hates me, personally

* Fix checks

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:RAC label obsolete release_note:enhancement Team: Actionable Observability - DEPRECATED For Observability Alerting and SLOs use "Team:obs-ux-management", for AIops "Team:obs-knowledge" Team:APM - DEPRECATED Use Team:obs-ux-infra_services. v8.0.0 v8.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RAC: Alerts View - remember Alerts View settings when navigating away and back to the Alerts View
8 participants