-
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
[RAC] Store Alerts View table state in localStorage #118207
Conversation
@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 I ended up attaching the subscriber in I'm wondering how you managed to get the |
# Conflicts: # x-pack/plugins/observability/public/pages/alerts/alerts_table_t_grid.tsx
# Conflicts: # x-pack/test/observability_functional/apps/observability/index.ts
# Conflicts: # x-pack/plugins/observability/public/pages/alerts/alerts_table_t_grid.tsx
let me take a look |
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. |
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.
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) |
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.
Is the !
a TS feature? I would expect the optional chaining operator ?.
here.
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.
!
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.
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.
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
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.
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; |
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: 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.
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.
Moving to request changes to flag build failures - the PR does not seem complete.
@elasticmachine merge upstream |
@claudiopro Build failures block merges, so you don't need to switch to Request Changes in the future if you spot that |
…ibana into 117698-alert-view-save
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.
LGTM! Ship it 🚀
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
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.
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 👍
Friendly reminder: Looks like this PR hasn’t been backported yet. |
* [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>
* [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>
* [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>
Pinging @elastic/apm-ui (Team:apm) |
* [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>
Summary
Closes #117698
On the Alerts View, this PR stores the state of columns and sort in localStorage.
Checklist