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
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ExperimentalFeatures = typeof allowedExperimentalValues;
export const allowedExperimentalValues = Object.freeze({
rulesListDatagrid: true,
internalAlertsTable: false,
internalShareableComponentsSandbox: false,
rulesDetailLogs: true,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const renderApp = (deps: TriggersAndActionsUiServices) => {

export const App = ({ deps }: { deps: TriggersAndActionsUiServices }) => {
const { savedObjects, uiSettings, theme$ } = deps;
const sections: Section[] = ['rules', 'connectors', 'alerts'];
const sections: Section[] = ['rules', 'connectors', 'alerts', '__components_sandbox'];
const isDarkMode = useObservable<boolean>(uiSettings.get$('theme:darkMode'));

const sectionsRegex = sections.join('|');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ export {
} from '../../../../alerting/common';
export { BASE_ACTION_API_PATH, INTERNAL_BASE_ACTION_API_PATH } from '../../../../actions/common';

export type Section = 'connectors' | 'rules' | 'alerts';
export type Section = 'connectors' | 'rules' | 'alerts' | '__components_sandbox';

export const routeToHome = `/`;
export const routeToConnectors = `/connectors`;
export const routeToRules = `/rules`;
export const routeToRuleDetails = `/rule/:ruleId`;
export const routeToInternalAlerts = `/alerts`;
export const routeToInternalShareableComponentsSandbox = '/__components_sandbox';
export const legacyRouteToRules = `/alerts`;
export const legacyRouteToRuleDetails = `/alert/:alertId`;

Expand Down
21 changes: 20 additions & 1 deletion x-pack/plugins/triggers_actions_ui/public/application/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { EuiSpacer, EuiButtonEmpty, EuiPageHeader } from '@elastic/eui';

import { getIsExperimentalFeatureEnabled } from '../common/get_experimental_features';
import { Section, routeToConnectors, routeToRules, routeToInternalAlerts } from './constants';
import {
Section,
routeToConnectors,
routeToRules,
routeToInternalAlerts,
routeToInternalShareableComponentsSandbox,
} from './constants';
import { getAlertingSectionBreadcrumb } from './lib/breadcrumb';
import { getCurrentDocTitle } from './lib/doc_title';
import { hasShowActionsCapability } from './lib/capabilities';
Expand All @@ -26,6 +32,9 @@ const ActionsConnectorsList = lazy(
);
const RulesList = lazy(() => import('./sections/rules_list/components/rules_list'));
const AlertsPage = lazy(() => import('./sections/alerts_table/alerts_page'));
const InternalShareableComponentsSandbox = lazy(
() => import('./internal/shareable_components_sandbox/shareable_components_sandbox')
);

export interface MatchParams {
section: Section;
Expand All @@ -45,6 +54,9 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
docLinks,
} = useKibana().services;
const isInternalAlertsTableEnabled = getIsExperimentalFeatureEnabled('internalAlertsTable');
const isInternalShareableComponentsSandboxEnabled = getIsExperimentalFeatureEnabled(
'internalShareableComponentsSandbox'
);

const canShowActions = hasShowActionsCapability(capabilities);
const tabs: Array<{
Expand Down Expand Up @@ -150,6 +162,13 @@ export const TriggersActionsUIHome: React.FunctionComponent<RouteComponentProps<
path={routeToRules}
component={suspendedComponentWithProps(RulesList, 'xl')}
/>
{isInternalShareableComponentsSandboxEnabled && (
<Route
exact
path={routeToInternalShareableComponentsSandbox}
component={suspendedComponentWithProps(InternalShareableComponentsSandbox, 'xl')}
/>
)}
{isInternalAlertsTableEnabled ? (
<Route
exact
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

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!

const [enabled, setEnabled] = useState(true);
const [snoozeEndTime, setSnoozeEndTime] = useState<Date | null>(null);
const [muteAll, setMuteAll] = useState(false);

return getRuleStatusDropdownLazy({
rule: {
enabled,
snoozeEndTime,
muteAll,
},
enableRule: async () => {
setEnabled(true);
setMuteAll(false);
setSnoozeEndTime(null);
},
disableRule: async () => setEnabled(false),
snoozeRule: async (time) => {
if (time === -1) {
setSnoozeEndTime(null);
setMuteAll(true);
} else {
setSnoozeEndTime(new Date(time));
setMuteAll(false);
}
},
unsnoozeRule: async () => {
setMuteAll(false);
setSnoozeEndTime(null);
},
onRuleChanged: () => {},
isEditable: true,
});
};

// eslint-disable-next-line import/no-default-export
export { InternalShareableComponentsSandbox as default };
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ export const ConnectorEditFlyout = suspendedComponentWithProps(
export const ActionForm = suspendedComponentWithProps(
lazy(() => import('./action_connector_form/action_form'))
);

export const RuleStatusDropdown = suspendedComponentWithProps(
lazy(() => import('./rules_list/components/rule_status_dropdown'))
);
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,10 @@ export const RuleDetails: React.FunctionComponent<RuleDetailsProps> = ({
await snoozeRule(rule, snoozeEndTime)
}
unsnoozeRule={async () => await unsnoozeRule(rule)}
item={rule as RuleTableItem}
rule={rule as RuleTableItem}
onRuleChanged={requestRefresh}
direction="row"
isEditable={hasEditButton}
previousSnoozeInterval={null}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ describe('RuleStatusDropdown', () => {
snoozeRule,
unsnoozeRule,
isEditable: true,
previousSnoozeInterval: null,
item: {
rule: {
id: '1',
name: 'test rule',
tags: ['tag1'],
Expand Down Expand Up @@ -53,7 +52,7 @@ describe('RuleStatusDropdown', () => {
index: 0,
updatedAt: new Date('2020-08-20T19:23:38Z'),
snoozeEndTime: null,
},
} as ComponentOpts['rule'],
onRuleChanged: jest.fn(),
};

Expand All @@ -75,7 +74,7 @@ describe('RuleStatusDropdown', () => {

test('renders status control as disabled when rule is disabled', () => {
const wrapper = mountWithIntl(
<RuleStatusDropdown {...{ ...props, item: { ...props.item, enabled: false } }} />
<RuleStatusDropdown {...{ ...props, rule: { ...props.rule, enabled: false } }} />
);
expect(wrapper.find('[data-test-subj="statusDropdown"]').first().props().title).toBe(
'Disabled'
Expand All @@ -87,7 +86,7 @@ describe('RuleStatusDropdown', () => {

const wrapper = mountWithIntl(
<RuleStatusDropdown
{...{ ...props, item: { ...props.item, snoozeEndTime: SNOOZE_END_TIME } }}
{...{ ...props, rule: { ...props.rule, snoozeEndTime: SNOOZE_END_TIME } }}
/>
);
expect(wrapper.find('[data-test-subj="statusDropdown"]').first().props().title).toBe('Snoozed');
Expand All @@ -98,7 +97,7 @@ describe('RuleStatusDropdown', () => {
jest.spyOn(global.Date, 'now').mockImplementation(() => new Date(NOW_STRING).valueOf());

const wrapper = mountWithIntl(
<RuleStatusDropdown {...{ ...props, item: { ...props.item, muteAll: true } }} />
<RuleStatusDropdown {...{ ...props, rule: { ...props.rule, muteAll: true } }} />
);
expect(wrapper.find('[data-test-subj="statusDropdown"]').first().props().title).toBe('Snoozed');
expect(wrapper.find('[data-test-subj="remainingSnoozeTime"]').first().text()).toBe(
Expand All @@ -109,7 +108,7 @@ describe('RuleStatusDropdown', () => {
test('renders status control as disabled when rule is snoozed but also disabled', () => {
const wrapper = mountWithIntl(
<RuleStatusDropdown
{...{ ...props, item: { ...props.item, enabled: false, snoozeEndTime: SNOOZE_END_TIME } }}
{...{ ...props, rule: { ...props.rule, enabled: false, snoozeEndTime: SNOOZE_END_TIME } }}
/>
);
expect(wrapper.find('[data-test-subj="statusDropdown"]').first().props().title).toBe(
Expand All @@ -122,7 +121,7 @@ describe('RuleStatusDropdown', () => {
<RuleStatusDropdown
{...{
...props,
item: { ...props.item, snoozeEndTime: SNOOZE_END_TIME },
rule: { ...props.rule, snoozeEndTime: SNOOZE_END_TIME },
}}
isEditable={false}
/>
Expand Down
Loading