Skip to content

Commit

Permalink
[Actionable Observability] Add license modal to rules table (elastic#…
Browse files Browse the repository at this point in the history
…131232)

* Add fix license link

* fix localization

* fix CI error

* fix more translation issues

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
2 people authored and Esteban Beltran committed May 4, 2022
1 parent bd18048 commit 775d9fd
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@
* 2.0.
*/

import React from 'react';
import { EuiHealth, EuiToolTip, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import React, { useState } from 'react';
import { EuiHealth, EuiToolTip, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty } from '@elastic/eui';
import { RuleExecutionStatusErrorReasons } from '@kbn/alerting-plugin/common';
import { FormattedMessage } from '@kbn/i18n-react';
import { ManageLicenseModal } from './manage_license_model';
import { getHealthColor, rulesStatusesTranslationsMapping } from '../config';
import { RULE_STATUS_LICENSE_ERROR } from '../translations';
import { ExecutionStatusProps } from '../types';
import { useKibana } from '../../../utils/kibana_react';

export function ExecutionStatus({ executionStatus }: ExecutionStatusProps) {
export function ExecutionStatus({ executionStatus, item, licenseType }: ExecutionStatusProps) {
const { http } = useKibana().services;
const [manageLicenseModalOpts, setManageLicenseModalOpts] = useState<{
licenseType: string;
ruleTypeId: string;
} | null>(null);
const healthColor = getHealthColor(executionStatus.status);
const tooltipMessage =
executionStatus.status === 'error' ? `Error: ${executionStatus?.error?.message}` : null;
Expand All @@ -38,6 +46,36 @@ export function ExecutionStatus({ executionStatus }: ExecutionStatusProps) {
return (
<EuiFlexGroup gutterSize="none">
<EuiFlexItem>{healthWithTooltip}</EuiFlexItem>
{isLicenseError && (
<EuiFlexItem grow={false}>
<EuiButtonEmpty
size="xs"
data-test-subj="ruleStatus-error-license-fix"
onClick={() =>
setManageLicenseModalOpts({
licenseType,
ruleTypeId: item.ruleTypeId,
})
}
>
<FormattedMessage
id="xpack.observability.rules.rulesTable.fixLicenseLink"
defaultMessage="Fix"
/>
</EuiButtonEmpty>
</EuiFlexItem>
)}
{manageLicenseModalOpts && (
<ManageLicenseModal
licenseType={manageLicenseModalOpts.licenseType}
ruleTypeId={manageLicenseModalOpts.ruleTypeId}
onConfirm={() => {
window.open(`${http.basePath.get()}/app/management/stack/license_management`, '_blank');
setManageLicenseModalOpts(null);
}}
onCancel={() => setManageLicenseModalOpts(null)}
/>
)}
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiConfirmModal } from '@elastic/eui';
import { capitalize } from 'lodash';

interface Props {
licenseType: string;
ruleTypeId: string;
onConfirm: () => void;
onCancel: () => void;
}

export function ManageLicenseModal({ licenseType, ruleTypeId, onConfirm, onCancel }: Props) {
const licenseRequired = capitalize(licenseType);
return (
<EuiConfirmModal
title={i18n.translate('xpack.observability.rules.manageLicense.manageLicenseTitle', {
defaultMessage: '{licenseRequired} license required',
values: { licenseRequired },
})}
onCancel={onCancel}
onConfirm={onConfirm}
confirmButtonText={i18n.translate(
'xpack.observability.rules.manageLicense.manageLicenseConfirmButtonText',
{
defaultMessage: 'Manage license',
}
)}
cancelButtonText={i18n.translate(
'xpack.observability.rules.manageLicense.manageLicenseCancelButtonText',
{
defaultMessage: 'Cancel',
}
)}
defaultFocusedButton="confirm"
data-test-subj="manageLicenseModal"
>
<p>
<FormattedMessage
id="xpack.observability.rules.manageLicense.manageLicenseMessage"
defaultMessage="Rule type {ruleTypeId} is disabled because it requires a {licenseRequired} license. Continue to License Management to view upgrade options."
values={{ ruleTypeId, licenseRequired }}
/>
</p>
</EuiConfirmModal>
);
}
6 changes: 5 additions & 1 deletion x-pack/plugins/observability/public/pages/rules/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,11 @@ function RulesPage() {
width: '120px',
'data-test-subj': 'rulesTableCell-status',
render: (_executionStatus: RuleExecutionStatus, item: RuleTableItem) => (
<ExecutionStatus executionStatus={item.executionStatus} />
<ExecutionStatus
executionStatus={item.executionStatus}
item={item}
licenseType={ruleTypeIndex.get(item.ruleTypeId)?.minimumLicenseRequired!}
/>
),
},
{
Expand Down
2 changes: 2 additions & 0 deletions x-pack/plugins/observability/public/pages/rules/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export interface StatusFilterProps {

export interface ExecutionStatusProps {
executionStatus: RuleExecutionStatus;
item: RuleTableItem;
licenseType: string;
}

export interface LastRunProps {
Expand Down

0 comments on commit 775d9fd

Please sign in to comment.