-
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
[Actionable Observability] save alerts config in different localStorage key for overview and ale… #130538
Conversation
@@ -311,7 +310,7 @@ export function AlertsTableTGrid(props: AlertsTableTGridProps) { | |||
|
|||
const [flyoutAlert, setFlyoutAlert] = useState<TopAlert | undefined>(undefined); | |||
const [tGridState, setTGridState] = useState<Partial<TGridModel> | null>( | |||
JSON.parse(localStorage.getItem(ALERT_TABLE_STATE_STORAGE_KEY) ?? 'null') | |||
JSON.parse(localStorage.getItem(stateStorageKey) ?? 'null') |
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.
Isn't unsafe to parse JSON without a try/catch block? I believe there is a helper/util in Kibana that handles that. /src/plugins/kibana_utils/public/storage/storage.ts
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 let me check 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.
@fkanout I made a quick search in the whole project for imports of kibana_utils/public/storage
, but I didn't find anything. So I was wondering how I should properly use Storage
from this file. My guess is that it should be part of a kbn pacakge? Do you have any idea? I can simply try to import this file, but I didn't find any other imports of it in the whole project, that's why I am wondering if there is a proper way to do 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.
Ok I found something. Here's how I can import it import { IStorage, Storage } from '@kbn/kibana-utils-plugin/public';
. This is a very recent change from kibana-operations team on how we can import stuff. This change would require a bit more refactoring. Should it be part of this PR?
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.
@@ -195,6 +195,7 @@ export function OverviewPage({ routeParams }: Props) { | |||
rangeFrom={relativeStart} | |||
rangeTo={relativeEnd} | |||
indexNames={indexNames} | |||
stateStorageKey="xpack.observability.overview.alert.tableState" |
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.
Isn't better to share this hardcoded value in a commonplace then be used here and there https://github.com/elastic/kibana/pull/130538/files#diff-ab4cbe22bf9a1c9bbaf3a3cb32b5aa5b0c8b8e33c34b88ed3c99dbde6fedadb9R333
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.
The values are different (unless they are used somewhere else that I missed) so I wouldn't put them in a commonplace until they are duplicated somewhere. The only thing I would suggest is to put that in a constant at the top of the file.
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.
@fkanout Thanks for the feedback. That's the whole point of this fix. Let me explain more. Before my fix the localStorage key was shared between overview and alerts page (xpack.observability.alert.tableState
) and this was causing the alerts table columns bug explained in this issue.
With my current change I introduced two different localStorage keys xpack.observability.alert.tableState
and xpack.observability.overview.alert.tableState
for alerts page and overview page accordingly.
@estermv I can put the keys in a constant at the top of the files.
if (newState !== localStorage.getItem(ALERT_TABLE_STATE_STORAGE_KEY)) { | ||
localStorage.setItem(ALERT_TABLE_STATE_STORAGE_KEY, newState); | ||
if (newState !== localStorage.getItem(stateStorageKey)) { | ||
localStorage.setItem(stateStorageKey, newState); |
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.
Could you help me understand why we keep altering the localStorage value for the alert table? Like this aren't we changing the o11y alerts table settings to match the other TGrid settings which we don't want?
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.
@fkanout Sure I'll try to explain. Short answer is we keep altering the localStorage value to reflect the user UI changes (for example visible columns or sorting column).
The only change I did here was to:
- not use the common
ALERT_TABLE_STATE_STORAGE_KEY
that was used in bothOverview
andAlerts
page and was causing this bug Alerts table will reset fields to a different table config that the default #126765, - but use the
stateStorageKey
which is a new prop I introduced to theAlertsTableTGrid
component
So now the two consumers alerts page and old overview page pass the prop to the AlertsTableTGrid component. and a different localStorage key is used for the two pages to keep track of the user specified settings. Nothing else changed in the previous logic, just the parameterization of the localStorage key.
Regarding the existing localStorage functionality (which didn't change in this PR) it works in a way that when the tGridState
is changed, it will update the localStorage to the new user settings, if they are of course different from what is currently saved in that localStorage key. tGridState
will be changed when any of the following is changed onStateChange (columns, sort, selectedEventIds). You can play around a bit with the UI and change table columns or sorting for example and see what is saved in localStorage.
Does it make sense?
@elasticmachine merge upstream |
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Async chunks
History
To update your PR or re-run it, just comment with: cc @mgiota |
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
…ge key for overview and ale… (elastic#130538) * save alerts config in different localStorage key for overview and alerts page * remove ALERT_TABLE_STATE_STORAGE_KEY
Fixes #126765