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

[RAM] Make RuleStatusDropdown shareable #130205

Merged
merged 16 commits into from
Apr 19, 2022

Conversation

Zacqary
Copy link
Contributor

@Zacqary Zacqary commented Apr 13, 2022

Summary

Closes #129774 and #128956

Adds a lazy loadable getRuleStatusDropdown function to the triggersActionsUI root. It can be shared with other plugins in a similar manner to the Alert Flyout, such as this use by the infra plugin.

Moves previousSnoozeInterval logic into Localstorage, so that it can persist across plugins and page usages.

Also adds an internal __components_sandbox route to TriggersActionsUI, which can only be enabled using an experimental feature flag intended only to be used by the functional testing suite. This enables us to run some rudimentary functional tests on just the RuleStatusDropdown by itself.

Checklist

@Zacqary Zacqary added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Alerting/RulesManagement Issues related to the Rules Management UX v8.3.0 labels Apr 13, 2022
@Zacqary Zacqary requested a review from a team as a code owner April 13, 2022 23:17
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@@ -55,34 +56,55 @@ const COMMON_SNOOZE_TIMES: Array<[number, SnoozeUnit]> = [
[1, 'd'],
];

const PREV_SNOOZE_INTERVAL_KEY = 'previousSnoozeInterval';
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we prefix this key with our plugin name or something?

Copy link
Contributor

@JiaweiWu JiaweiWu Apr 19, 2022

Choose a reason for hiding this comment

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

do we foresee there being a use case where the consumer might need to pass their own key? if not feel free to disregard this comment.

edit: nevermind, chris already mentioned this in another comment

@@ -227,6 +230,9 @@ export class Plugin
getAlertsTable: (props: AlertsTableProps) => {
return getAlertsTableLazy(props);
},
getRuleStatusDropdown: (props: RuleStatusDropdownProps) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps we want to give consumers a choice if they want to inherit the previous history or start a new history for just their use case? Right now, it's all shared without choice

const interval = localStorage.getItem(PREV_SNOOZE_INTERVAL_KEY);
const [previousSnoozeInterval, setPreviousSnoozeInterval] = useState<string | null>(interval);
const storeAndSetPreviousSnoozeInterval = (newInterval: string) => {
localStorage.setItem(PREV_SNOOZE_INTERVAL_KEY, newInterval);
Copy link
Contributor

Choose a reason for hiding this comment

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

So local storage never expires - do we care/want to manage that somehow? I'm not sure - this is a small amount of data

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not too worried about storing a single string indefinitely but if it's a blocker I can add an expiration system

@Zacqary
Copy link
Contributor Author

Zacqary commented Apr 14, 2022

Not sure why the functional test is failing on CI, it's passing on local fine. Will investigate and see if I can get it to be more reliable.

@mgiota
Copy link
Contributor

mgiota commented Apr 15, 2022

@Zacqary Great! I tested out the use of RuleStatusDropdown component in Observability and works fine with one extra change I had to do in the triggers_actions_ui plugin. Could you export unsnoozeRule and snoozeRule in the this file https://github.com/elastic/kibana/blob/main/x-pack/plugins/triggers_actions_ui/public/index.ts as part of your PR?
Screenshot 2022-04-15 at 11 36 30

@mgiota
Copy link
Contributor

mgiota commented Apr 15, 2022

A small bug I noticed is in the tooltip in case user snoozed indefinitely
Screenshot 2022-04-15 at 12 02 56

@mgiota mgiota requested review from mgiota and removed request for mgiota April 15, 2022 10:04
@Zacqary Zacqary enabled auto-merge (squash) April 15, 2022 20:25
import React, { useState } from 'react';
import { getRuleStatusDropdownLazy } from '../../../common/get_rule_status_dropdown';

export const InternalShareableComponentsSandbox: React.FC<{}> = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

So for the components that I'm working on, I am rebasing off of this branch since I also need to E2E test the components. I'm wondering if we could maybe move the rule status dropdown rendering to its own file? so I can add my components in this sandbox as well

maybe something like?

return (
  <div>
    <RuleStatusDropdownSandbox />
    <OtherSandboxes />
  </div>
);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can do

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome!

Zacqary added 2 commits April 18, 2022 10:36
…atus-dropdown

# Conflicts:
#	x-pack/plugins/triggers_actions_ui/public/types.ts
…atus-dropdown

# Conflicts:
#	x-pack/plugins/triggers_actions_ui/public/plugin.ts
Copy link
Contributor

@JiaweiWu JiaweiWu left a comment

Choose a reason for hiding this comment

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

Aside from Chris's comments, this LGTM!

Copy link
Contributor

@chrisronline chrisronline left a comment

Choose a reason for hiding this comment

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

LGTM!

@Zacqary Zacqary requested a review from a team as a code owner April 19, 2022 19:41
@Zacqary
Copy link
Contributor Author

Zacqary commented Apr 19, 2022

@elastic/kibana-operations I upped the triggersActionsUi limit by 1kb because the CI was failing on a 213 byte overage. Can I get an approval on that?

Copy link
Contributor

@tylersmalley tylersmalley left a comment

Choose a reason for hiding this comment

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

@Zacqary is going to assist with prioritizing the work to reduce this. This is tracked in #95871

onRuleChanged: () => void;
enableRule: () => Promise<void>;
disableRule: () => Promise<void>;
snoozeRule: (snoozeEndTime: string | -1, interval: string | null) => Promise<void>;
unsnoozeRule: () => Promise<void>;
isEditable: boolean;
previousSnoozeInterval: string | null;
previousSnoozeInterval?: string | null;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need this prop? I feel like we should not have this prop anymore, am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chrisronline requested we keep it: #130205 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. I might have missed how this ended up. I think we can provide consumers with the choice to change the key used in local storage so they don't need to inherit previously stored intervals for other solutions

const usePreviousSnoozeInterval: (p?: string | null) => [string | null, (n: string) => void] = (
propsInterval
) => {
const intervalFromStorage = localStorage.getItem(PREV_SNOOZE_INTERVAL_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we should allow different SNOOZE_INTERVAL_KEY for different solutions, maybe let's see if we get this requirement in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

match with this comment #130205 (comment)

@XavierM XavierM disabled auto-merge April 19, 2022 20:14
@XavierM
Copy link
Contributor

XavierM commented Apr 19, 2022

Maybe in the future we can try to investigate to test our shareable components like that https://github.com/elastic/kibana/blob/main/x-pack/test/plugin_functional/plugins/timelines_test/public/plugin.ts to avoid dead code in our plugin. what do you think @chrisronline @JiaweiWu @Zacqary ?

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
triggersActionsUi 362 365 +3

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
triggersActionsUi 296 307 +11

Async chunks

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

id before after diff
triggersActionsUi 700.5KB 711.7KB +11.2KB

Public APIs missing exports

Total count of every type that is part of your API that should be exported but is not. This will cause broken links in the API documentation system. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats exports for more detailed information.

id before after diff
triggersActionsUi 24 25 +1

Page load bundle

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

id before after diff
triggersActionsUi 99.4KB 100.2KB +791.0B
Unknown metric groups

API count

id before after diff
triggersActionsUi 310 321 +11

async chunk count

id before after diff
triggersActionsUi 75 77 +2

ESLint disabled line counts

id before after diff
triggersActionsUi 168 170 +2

Total ESLint disabled count

id before after diff
triggersActionsUi 174 176 +2

History

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

@Zacqary
Copy link
Contributor Author

Zacqary commented Apr 19, 2022

@XavierM sorry didn't realize there was an established convention for writing tests like this, we can port that over. Might help with the bundle size issue anyway

@Zacqary Zacqary merged commit c0ab947 into elastic:main Apr 19, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Apr 19, 2022
@JiaweiWu
Copy link
Contributor

Yea I can work on creating a separate plugins for testing purposes, since I'm gonna be writing more of these tests.

@mgiota
Copy link
Contributor

mgiota commented Apr 20, 2022

@Zacqary We need unsnoozeRule and snoozeRule to be exported for the status dropdown to work for us. I will create a PR and add you as a reviewer

Update: I just saw your change! Thx

@@ -57,6 +57,8 @@ export { enableRule } from './application/lib/rule_api/enable';
export { disableRule } from './application/lib/rule_api/disable';
export { muteRule } from './application/lib/rule_api/mute';
export { unmuteRule } from './application/lib/rule_api/unmute';
export { snoozeRule } from './application/lib/rule_api/snooze';
Copy link
Contributor

Choose a reason for hiding this comment

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

@Zacqary Oops somehow I missed it! Thanks I can now reuse your component. Thanks a ton!

kertal pushed a commit to kertal/kibana that referenced this pull request May 24, 2022
* Add shareable e dropdown and move snooze interval to localstorage

* Add internal components sandbox page and status dropdown test

* Remove components sandbox tab

* Fix typecheck

* Fix typechecks and tests

* Attempt to deflake tests

* Reenable previousSnoozeInterval from props and prefix storage key

* Export missing apis

* Fix tooltip for indefinite snooze

* Attempt to deflake functional test

* Modularize Sandbox

* Up triggersActionsUi package limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Alerting/RulesManagement Issues related to the Rules Management UX release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[RAM] Make RuleStatusDropdown shareable
9 participants