Skip to content

Commit

Permalink
Fix checks
Browse files Browse the repository at this point in the history
  • Loading branch information
CoenWarmer committed Apr 18, 2023
1 parent 9f89a90 commit 9d731cb
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect, useRef, useState } from 'react';
import React, { useRef, useState } from 'react';
import { useHistory } from 'react-router-dom';
import {
EuiFlexGroup,
Expand All @@ -29,7 +29,6 @@ import {
SEARCH_BAR_URL_STORAGE_KEY,
TabId,
} from '../rule_details';
import { getDefaultAlertSummaryTimeRange } from '../../../utils/alert_summary_widget';
import { fromQuery, toQuery } from '../../../utils/url';
import { observabilityFeatureId } from '../../../../common';

Expand All @@ -40,6 +39,7 @@ interface RuleDetailTabsProps {
ruleId: string;
ruleType: RuleType<string, string> | undefined;
onChangeTab: (tabId: TabId) => void;
onChangeEsQuery: (bool: { bool: BoolQuery } | undefined) => void;
}

export function RuleDetailTabs({
Expand All @@ -49,6 +49,7 @@ export function RuleDetailTabs({
ruleId,
ruleType,
onChangeTab,
onChangeEsQuery,
}: RuleDetailTabsProps) {
const {
triggersActionsUi: {
Expand All @@ -64,13 +65,6 @@ export function RuleDetailTabs({
]);

const [esQuery, setEsQuery] = useState<{ bool: BoolQuery }>();
const [alertSummaryWidgetTimeRange, setAlertSummaryWidgetTimeRange] = useState(
getDefaultAlertSummaryTimeRange
);

useEffect(() => {
setAlertSummaryWidgetTimeRange(getDefaultAlertSummaryTimeRange());
}, [esQuery]);

const updateUrl = (nextQuery: { tabId: TabId }) => {
const newTabId = nextQuery.tabId;
Expand All @@ -88,11 +82,19 @@ export function RuleDetailTabs({
});
};

const onTabIdChange = (newTabId: TabId) => {
const handleTabIdChange = (newTabId: TabId) => {
onChangeTab(newTabId);
updateUrl({ tabId: newTabId });
};

const handleEsQueryChange = (newQuery: { bool: BoolQuery } | undefined) => {
setEsQuery(newQuery);

if (newQuery) {
onChangeEsQuery(newQuery);
}
};

const tabs: EuiTabbedContentTab[] = [
{
id: EXECUTION_TAB,
Expand All @@ -119,7 +121,7 @@ export function RuleDetailTabs({
<EuiSpacer size="m" />
<ObservabilityAlertSearchbarWithUrlSync
appName={RULE_DETAILS_ALERTS_SEARCH_BAR_ID}
onEsQueryChange={setEsQuery}
onEsQueryChange={handleEsQueryChange}
urlStorageKey={SEARCH_BAR_URL_STORAGE_KEY}
defaultSearchQueries={ruleQuery.current}
/>
Expand Down Expand Up @@ -150,8 +152,8 @@ export function RuleDetailTabs({
data-test-subj="rule-detail-tabs"
tabs={tabs}
selectedTab={tabs.find((tab) => tab.id === activeTab)}
onTabClick={(tab) => {
onTabIdChange(tab.id as TabId);
onTabClick={({ id }) => {
handleTabIdChange(id as TabId);
}}
/>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ import { useKibana } from '../../utils/kibana_react';
import { useBreadcrumbs } from '../../hooks/use_breadcrumbs';
import { usePluginContext } from '../../hooks/use_plugin_context';
import { useFetchRule } from '../../hooks/use_fetch_rule';
import { useGetRuleTypeDefinitionFromRuleType } from '../../hooks/use_get_rule_type_definition_from_rule_type';
import { DeleteConfirmationModal } from './components/delete_modal_confirmation';
import { CenterJustifiedSpinner } from '../../components/center_justified_spinner';
import { PageTitle } from './components/page_title';
import { NoRuleFoundPanel } from './components/no_rule_found_panel';
import { RuleDetailTabs } from './components/rule_detail_tabs';
import { HeaderActions } from './components/header_actions';
import { getHealthColor } from './helpers/get_health_color';
import { canEditRule } from './helpers/can_edit_rule';
import {
defaultTimeRange,
getDefaultAlertSummaryTimeRange,
Expand All @@ -32,8 +34,6 @@ import { paths } from '../../config/paths';
import { ALERT_STATUS_ALL } from '../../../common/constants';
import { ruleDetailsLocatorID } from '../../../common';
import type { AlertStatus } from '../../../common/typings';
import { useGetRuleTypeDefinitionFromRuleType } from '../../hooks/use_get_rule_type_definition_from_rule_type';
import { canEditRule } from './helpers/can_edit_rule';

export const EXECUTION_TAB = 'execution';
export const ALERTS_TAB = 'alerts';
Expand Down Expand Up @@ -140,10 +140,23 @@ export function RuleDetailsPage() {
tabsRef.current?.scrollIntoView({ behavior: 'smooth' });
};

const handleChangeTab = (newTab: TabId) => {
setActiveTab(newTab);
};

const handleEditRule = () => {
setEditRuleFlyoutVisible(true);
};

const handleCloseRuleFlyout = () => {
setEditRuleFlyoutVisible(false);
};

const handleDeleteRule = () => {
setRuleToDelete(rule?.id);
setEditRuleFlyoutVisible(false);
};

const handleIsDeletingRule = () => {
setIsRuleDeleting(true);
};
Expand All @@ -154,13 +167,8 @@ export function RuleDetailsPage() {
navigateToUrl(http.basePath.prepend(paths.observability.rules));
};

const handleDeleteRule = () => {
setRuleToDelete(rule?.id);
setEditRuleFlyoutVisible(false);
};

const handleChangeTab = (newTab: TabId) => {
setActiveTab(newTab);
const handleChangeEsQuery = () => {
setAlertSummaryWidgetTimeRange(getDefaultAlertSummaryTimeRange());
};

const featureIds = (
Expand Down Expand Up @@ -201,10 +209,10 @@ export function RuleDetailsPage() {
<EuiFlexGroup wrap gutterSize="m">
<EuiFlexItem style={{ minWidth: 350 }}>
<RuleStatusPanel
rule={rule}
isEditable={isRuleEditable}
requestRefresh={reloadRule}
healthColor={getHealthColor(rule.executionStatus.status)}
requestRefresh={reloadRule}
rule={rule}
statusMessage={
rule?.executionStatus.error?.reason === RuleExecutionStatusErrorReasons.License
? i18n.translate('xpack.observability.ruleDetails.ruleStatusLicenseError', {
Expand All @@ -216,6 +224,7 @@ export function RuleDetailsPage() {
}
/>
</EuiFlexItem>

<EuiFlexItem style={{ minWidth: 350 }}>
<AlertSummaryWidget
chartProps={chartProps}
Expand All @@ -225,11 +234,12 @@ export function RuleDetailsPage() {
filter={alertSummaryWidgetFilter.current}
/>
</EuiFlexItem>

<RuleDefinition
actionTypeRegistry={actionTypeRegistry}
rule={rule}
onEditRule={reloadRule}
ruleTypeRegistry={ruleTypeRegistry}
actionTypeRegistry={actionTypeRegistry}
onEditRule={reloadRule}
/>
</EuiFlexGroup>

Expand All @@ -245,17 +255,12 @@ export function RuleDetailsPage() {
ruleType={ruleTypeDefinition}
activeTab={activeTab}
onChangeTab={handleChangeTab}
onChangeEsQuery={handleChangeEsQuery}
/>
) : null}

{editRuleFlyoutVisible ? (
<EditRuleFlyout
initialRule={rule}
onClose={() => {
setEditRuleFlyoutVisible(false);
}}
onSave={reloadRule}
/>
<EditRuleFlyout initialRule={rule} onClose={handleCloseRuleFlyout} onSave={reloadRule} />
) : null}

{ruleToDelete ? (
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -25503,10 +25503,6 @@
"xpack.observability.overview.exploratoryView.missingReportDefinition": "{reportDefinition} manquante",
"xpack.observability.overview.exploratoryView.noDataAvailable": "Aucune donnée {dataType} disponible.",
"xpack.observability.ruleDetails.ruleLoadError": "Impossible de charger la règle. Raison : {message}",
"xpack.observability.rules.deleteSelectedIdsConfirmModal.deleteButtonLabel": "Supprimer {numIdsToDelete, plural, one {{singleTitle}} other {# {multipleTitle}}} ",
"xpack.observability.rules.deleteSelectedIdsConfirmModal.descriptionText": "Vous ne pouvez pas récupérer {numIdsToDelete, plural, one {un {singleTitle} supprimé} other {des {multipleTitle} supprimés}}.",
"xpack.observability.rules.deleteSelectedIdsErrorNotification.descriptionText": "Impossible de supprimer {numErrors, number} {numErrors, plural, one {{singleTitle}} other {{multipleTitle}}}",
"xpack.observability.rules.deleteSelectedIdsSuccessNotification.descriptionText": "{numSuccesses, number} {numSuccesses, plural, one {{singleTitle}} other {{multipleTitle}}} supprimé(s)",
"xpack.observability.slo.alerting.burnRate.reason": "Le taux d'avancement pour le (les) dernier(s) {longWindowDuration} est de {longWindowBurnRate} et pour le (les) dernier(s) {shortWindowDuration} est de {shortWindowBurnRate}. Alerter si supérieur à {burnRateThreshold} pour les deux fenêtres",
"xpack.observability.slo.rules.burnRate.errors.invalidThresholdValue": "Le seuil du taux d'avancement doit être compris entre 1 et {maxBurnRate}.",
"xpack.observability.slo.rules.errorBudgetExhaustion.text": "À ce niveau, le bilan d'erreurs de SLO sera épuisé après {formatedHours} heures.",
Expand Down Expand Up @@ -25929,7 +25925,6 @@
"xpack.observability.ruleDetails.ruleStatusUnknown": "Inconnu",
"xpack.observability.ruleDetails.ruleStatusWarning": "Avertissement",
"xpack.observability.rules.addRuleButtonLabel": "Créer une règle",
"xpack.observability.rules.deleteSelectedIdsConfirmModal.cancelButtonLabel": "Annuler",
"xpack.observability.rules.docsLinkText": "Documentation",
"xpack.observability.rulesLinkTitle": "Règles",
"xpack.observability.rulesTitle": "Règles",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -25911,7 +25911,6 @@
"xpack.observability.ruleDetails.ruleStatusUnknown": "不明",
"xpack.observability.ruleDetails.ruleStatusWarning": "警告",
"xpack.observability.rules.addRuleButtonLabel": "ルールを作成",
"xpack.observability.rules.deleteSelectedIdsConfirmModal.cancelButtonLabel": "キャンセル",
"xpack.observability.rules.docsLinkText": "ドキュメント",
"xpack.observability.rulesLinkTitle": "ルール",
"xpack.observability.rulesTitle": "ルール",
Expand Down
5 changes: 0 additions & 5 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -25501,10 +25501,6 @@
"xpack.observability.overview.exploratoryView.noDataAvailable": "没有可用的 {dataType} 数据。",
"xpack.observability.profilingElasticsearchPluginDescription": "{technicalPreviewLabel} 是否使用 Elasticsearch 分析器插件加载堆栈跟踪。",
"xpack.observability.ruleDetails.ruleLoadError": "无法加载规则。原因:{message}",
"xpack.observability.rules.deleteSelectedIdsConfirmModal.deleteButtonLabel": "删除{numIdsToDelete, plural, one {{singleTitle}} other {# 个{multipleTitle}}}",
"xpack.observability.rules.deleteSelectedIdsConfirmModal.descriptionText": "无法恢复{numIdsToDelete, plural, one {删除的{singleTitle}} other {删除的{multipleTitle}}}。",
"xpack.observability.rules.deleteSelectedIdsErrorNotification.descriptionText": "无法删除 {numErrors, number} 个{numErrors, plural, one {{singleTitle}} other {{multipleTitle}}}",
"xpack.observability.rules.deleteSelectedIdsSuccessNotification.descriptionText": "已删除 {numSuccesses, number} 个{numSuccesses, plural, one {{singleTitle}} other {{multipleTitle}}}",
"xpack.observability.slo.alerting.burnRate.reason": "过去 {longWindowDuration} 的消耗速度为 {longWindowBurnRate} 且过去 {shortWindowDuration} 为 {shortWindowBurnRate}。两个窗口超出 {burnRateThreshold} 时告警",
"xpack.observability.slo.rules.burnRate.errors.invalidThresholdValue": "消耗速度阈值必须介于 1 和 {maxBurnRate} 之间。",
"xpack.observability.slo.rules.errorBudgetExhaustion.text": "在此速度下,SLO 的错误预算将在 {formatedHours} 小时后耗尽。",
Expand Down Expand Up @@ -25927,7 +25923,6 @@
"xpack.observability.ruleDetails.ruleStatusUnknown": "未知",
"xpack.observability.ruleDetails.ruleStatusWarning": "警告",
"xpack.observability.rules.addRuleButtonLabel": "创建规则",
"xpack.observability.rules.deleteSelectedIdsConfirmModal.cancelButtonLabel": "取消",
"xpack.observability.rules.docsLinkText": "文档",
"xpack.observability.rulesLinkTitle": "规则",
"xpack.observability.rulesTitle": "规则",
Expand Down

0 comments on commit 9d731cb

Please sign in to comment.