Skip to content

Commit

Permalink
Simplify conditional checks and move instance selector above
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelemme committed Dec 2, 2024
1 parent 5165c30 commit 6d04e55
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function AutoRefreshButton({ disabled, isAutoRefreshing, onClick }: Props
data-test-subj="autoRefreshButton"
disabled={disabled}
iconSide="left"
iconType="play"
iconType="refresh"
onClick={onClick}
>
{i18n.translate('xpack.slo.slosPage.autoRefreshButtonLabel', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@ import { SloDeleteModal } from '../../../components/slo/delete_confirmation_moda
import { SloResetConfirmationModal } from '../../../components/slo/reset_confirmation_modal/slo_reset_confirmation_modal';
import { useCloneSlo } from '../../../hooks/use_clone_slo';
import { useFetchRulesForSlo } from '../../../hooks/use_fetch_rules_for_slo';
import { useKibana } from '../../../hooks/use_kibana';
import { usePermissions } from '../../../hooks/use_permissions';
import { useResetSlo } from '../../../hooks/use_reset_slo';
import { useKibana } from '../../../hooks/use_kibana';
import { convertSliApmParamsToApmAppDeeplinkUrl } from '../../../utils/slo/convert_sli_apm_params_to_apm_app_deeplink_url';
import { isApmIndicatorType } from '../../../utils/slo/indicator';
import { EditBurnRateRuleFlyout } from '../../slos/components/common/edit_burn_rate_rule_flyout';
import { useGetQueryParams } from '../hooks/use_get_query_params';
import { useSloActions } from '../hooks/use_slo_actions';

export interface Props {
slo?: SLOWithSummaryResponse;
isLoading: boolean;
slo: SLOWithSummaryResponse;
}

export function HeaderControl({ isLoading, slo }: Props) {
export function HeaderControl({ slo }: Props) {
const {
application: { navigateToUrl, capabilities },
http: { basePath },
Expand All @@ -58,10 +57,10 @@ export function HeaderControl({ isLoading, slo }: Props) {
const { mutateAsync: resetSlo, isLoading: isResetLoading } = useResetSlo();

const { data: rulesBySlo, refetchRules } = useFetchRulesForSlo({
sloIds: slo ? [slo.id] : undefined,
sloIds: [slo.id],
});

const rules = slo ? rulesBySlo?.[slo?.id] ?? [] : [];
const rules = rulesBySlo?.[slo.id] ?? [];

const handleActionsClick = () => setIsPopoverOpen((value) => !value);
const closePopover = () => setIsPopoverOpen(false);
Expand Down Expand Up @@ -92,10 +91,6 @@ export function HeaderControl({ isLoading, slo }: Props) {
});

const handleNavigateToApm = () => {
if (!slo) {
return undefined;
}

const url = convertSliApmParamsToApmAppDeeplinkUrl(slo);
if (url) {
navigateToUrl(basePath.prepend(url));
Expand All @@ -105,10 +100,8 @@ export function HeaderControl({ isLoading, slo }: Props) {
const navigateToClone = useCloneSlo();

const handleClone = async () => {
if (slo) {
setIsPopoverOpen(false);
navigateToClone(slo);
}
setIsPopoverOpen(false);
navigateToClone(slo);
};

const handleDelete = () => {
Expand Down Expand Up @@ -140,11 +133,9 @@ export function HeaderControl({ isLoading, slo }: Props) {
};

const handleResetConfirm = async () => {
if (slo) {
await resetSlo({ id: slo.id, name: slo.name });
removeResetQueryParam();
setResetConfirmationModalOpen(false);
}
await resetSlo({ id: slo.id, name: slo.name });
removeResetQueryParam();
setResetConfirmationModalOpen(false);
};

const handleResetCancel = () => {
Expand Down Expand Up @@ -182,8 +173,6 @@ export function HeaderControl({ isLoading, slo }: Props) {
iconType="arrowDown"
iconSize="s"
onClick={handleActionsClick}
isLoading={isLoading}
disabled={isLoading}
>
{i18n.translate('xpack.slo.sloDetails.headerControl.actions', {
defaultMessage: 'Actions',
Expand Down Expand Up @@ -315,7 +304,7 @@ export function HeaderControl({ isLoading, slo }: Props) {
refetchRules={refetchRules}
/>

{slo && isRuleFlyoutVisible ? (
{isRuleFlyoutVisible ? (
<AddRuleFlyout
consumer={sloFeatureId}
ruleTypeId={SLO_BURN_RATE_RULE_TYPE_ID}
Expand All @@ -326,11 +315,11 @@ export function HeaderControl({ isLoading, slo }: Props) {
/>
) : null}

{slo && isDeleteConfirmationModalOpen ? (
{isDeleteConfirmationModalOpen ? (
<SloDeleteModal slo={slo} onCancel={handleDeleteCancel} onSuccess={handleDeleteConfirm} />
) : null}

{slo && isResetConfirmationModalOpen ? (
{isResetConfirmationModalOpen ? (
<SloResetConfirmationModal
slo={slo}
onCancel={handleResetCancel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export interface Props {

export function HeaderTitle({ isLoading, slo }: Props) {
if (isLoading || !slo) {
return <EuiSkeletonText lines={1} data-test-subj="loadingTitle" />;
return <EuiSkeletonText lines={2} data-test-subj="loadingTitle" />;
}

return (
<EuiFlexGroup direction="column" gutterSize="s">
<EuiFlexGroup direction="column" gutterSize="m">
<SLOGroupings slo={slo} />
<EuiFlexGroup
direction="row"
gutterSize="s"
Expand Down Expand Up @@ -59,7 +60,6 @@ export function HeaderTitle({ isLoading, slo }: Props) {
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
<SLOGroupings slo={slo} />
</EuiFlexGroup>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* 2.0.
*/

import { i18n } from '@kbn/i18n';
import { EuiNotificationBadge, EuiToolTip } from '@elastic/eui';
import React from 'react';
import { i18n } from '@kbn/i18n';
import { ALL_VALUE, SLOWithSummaryResponse } from '@kbn/slo-schema';
import React from 'react';
import { paths } from '../../../../common/locators/paths';
import { useKibana } from '../../../hooks/use_kibana';
import { useFetchActiveAlerts } from '../../../hooks/use_fetch_active_alerts';
import { useKibana } from '../../../hooks/use_kibana';
import {
ALERTS_TAB_ID,
HISTORY_TAB_ID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import { HeaderMenu } from '../../components/header_menu/header_menu';
import { AutoRefreshButton } from '../../components/slo/auto_refresh_button';
import { useAutoRefreshStorage } from '../../components/slo/auto_refresh_button/hooks/use_auto_refresh_storage';
import { useFetchSloDetails } from '../../hooks/use_fetch_slo_details';
import { useKibana } from '../../hooks/use_kibana';
import { useLicense } from '../../hooks/use_license';
import { usePermissions } from '../../hooks/use_permissions';
import { usePluginContext } from '../../hooks/use_plugin_context';
import { useKibana } from '../../hooks/use_kibana';
import PageNotFound from '../404';
import { HeaderControl } from './components/header_control';
import { HeaderTitle } from './components/header_title';
Expand Down Expand Up @@ -125,21 +125,23 @@ export function SloDetailsPage() {
pageHeader={{
pageTitle: slo?.name ?? <EuiSkeletonText lines={1} />,
children: <HeaderTitle isLoading={isPerformingAction} slo={slo} />,
rightSideItems: [
<HeaderControl isLoading={isPerformingAction} slo={slo} />,
<AutoRefreshButton
disabled={isPerformingAction}
isAutoRefreshing={isAutoRefreshing}
onClick={handleToggleAutoRefresh}
/>,
],
rightSideItems: !isLoading
? [
<HeaderControl slo={slo!} />,
<AutoRefreshButton
isAutoRefreshing={isAutoRefreshing}
onClick={handleToggleAutoRefresh}
/>,
]
: undefined,
tabs,
}}
data-test-subj="sloDetailsPage"
>
<HeaderMenu />
{isLoading && <EuiLoadingSpinner data-test-subj="sloDetailsLoading" />}
{!isLoading && (
{isLoading ? (
<EuiLoadingSpinner data-test-subj="sloDetailsLoading" />
) : (
<SloDetails slo={slo!} isAutoRefreshing={isAutoRefreshing} selectedTabId={selectedTabId} />
)}
</ObservabilityPageTemplate>
Expand Down

0 comments on commit 6d04e55

Please sign in to comment.