Skip to content

Commit

Permalink
[8.15] [SLO] Overview embeddable chart use proper theme !! (#198299) (#…
Browse files Browse the repository at this point in the history
…198404)

# Backport

This will backport the following commits from `main` to `8.15`:
- [[SLO] Overview embeddable chart use proper theme !!
(#198299)](#198299)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-30T16:25:58Z","message":"[SLO]
Overview embeddable chart use proper theme !! (#198299)\n\n##
Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/198298\r\n\r\nOverview
embeddable chart use proper theme !!\r\n\r\n### After\r\n<img
width=\"1728\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/9fa22277-31ba-41f0-b08a-1ed4d801daff\">\r\n\r\n\r\n###
Before\r\n\r\n<img width=\"1728\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/98102df8-6881-4672-9791-9e85f9201c6a\">","sha":"56825f19f5570cbd9fff336fa096c18ec23830dd","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:prev-major","ci:project-deploy-observability","Team:obs-ux-management"],"title":"[SLO]
Overview embeddable chart use proper theme
!!","number":198299,"url":"https://github.com/elastic/kibana/pull/198299","mergeCommit":{"message":"[SLO]
Overview embeddable chart use proper theme !! (#198299)\n\n##
Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/198298\r\n\r\nOverview
embeddable chart use proper theme !!\r\n\r\n### After\r\n<img
width=\"1728\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/9fa22277-31ba-41f0-b08a-1ed4d801daff\">\r\n\r\n\r\n###
Before\r\n\r\n<img width=\"1728\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/98102df8-6881-4672-9791-9e85f9201c6a\">","sha":"56825f19f5570cbd9fff336fa096c18ec23830dd"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198299","number":198299,"mergeCommit":{"message":"[SLO]
Overview embeddable chart use proper theme !! (#198299)\n\n##
Summary\r\n\r\nFixes
https://github.com/elastic/kibana/issues/198298\r\n\r\nOverview
embeddable chart use proper theme !!\r\n\r\n### After\r\n<img
width=\"1728\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/9fa22277-31ba-41f0-b08a-1ed4d801daff\">\r\n\r\n\r\n###
Before\r\n\r\n<img width=\"1728\"
alt=\"image\"\r\nsrc=\"https://github.com/user-attachments/assets/98102df8-6881-4672-9791-9e85f9201c6a\">","sha":"56825f19f5570cbd9fff336fa096c18ec23830dd"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <[email protected]>
  • Loading branch information
kibanamachine and shahzad31 authored Oct 30, 2024
1 parent 16d90d2 commit 3219dc8
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import React from 'react';
import { ALL_VALUE, HistoricalSummaryResponse, SLOWithSummaryResponse } from '@kbn/slo-schema';
import {
Chart,
DARK_THEME,
isMetricElementEvent,
Metric,
MetricTrendShape,
Expand Down Expand Up @@ -73,12 +72,18 @@ const getSloChartData = ({
};
};

const ROW_HEIGHT = 220;
const ITEMS_PER_ROW = 4;

export function SloCardChartList({ sloId }: { sloId: string }) {
const {
http: { basePath },
uiSettings,
charts,
} = useKibana().services;

const baseTheme = charts.theme.useChartsBaseTheme();

const [selectedSlo, setSelectedSlo] = React.useState<SLOWithSummaryResponse | null>(null);

const kqlQuery = `slo.id:"${sloId}"`;
Expand All @@ -89,6 +94,7 @@ export function SloCardChartList({ sloId }: { sloId: string }) {

const { data: activeAlertsBySlo } = useFetchActiveAlerts({
sloIdsAndInstanceIds: [[sloId, ALL_VALUE]],
rangeFrom: 'now-24h',
});

const { data: rulesBySlo } = useFetchRulesForSlo({
Expand Down Expand Up @@ -151,16 +157,24 @@ export function SloCardChartList({ sloId }: { sloId: string }) {
);
}

const height = sloList?.results
? ROW_HEIGHT * Math.ceil(sloList.results.length / ITEMS_PER_ROW)
: ROW_HEIGHT;

return (
<>
<div data-shared-item="" style={{ width: '100%' }}>
<Chart>
<div data-shared-item="" style={{ width: '100%', overflow: 'auto' }}>
<Chart
size={{
height,
}}
>
<Settings
baseTheme={DARK_THEME}
baseTheme={baseTheme}
onElementClick={([d]) => {
if (isMetricElementEvent(d)) {
const { columnIndex, rowIndex } = d;
const slo = sloList?.results[rowIndex * 4 + columnIndex];
const slo = sloList?.results[rowIndex * ITEMS_PER_ROW + columnIndex];
setSelectedSlo(slo ?? null);
}
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type SloIdAndInstanceId = [string, string];
interface Params {
sloIdsAndInstanceIds: SloIdAndInstanceId[];
shouldRefetch?: boolean;
rangeFrom?: string;
}

export interface UseFetchActiveAlerts {
Expand All @@ -46,6 +47,7 @@ const EMPTY_ACTIVE_ALERTS_MAP = new ActiveAlerts();
export function useFetchActiveAlerts({
sloIdsAndInstanceIds = [],
shouldRefetch = false,
rangeFrom = 'now-5m/m',
}: Params): UseFetchActiveAlerts {
const { http } = useKibana().services;

Expand All @@ -63,7 +65,7 @@ export function useFetchActiveAlerts({
{
range: {
'@timestamp': {
gte: 'now-5m/m',
gte: rangeFrom,
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SLOWithSummaryResponse } from '@kbn/slo-schema';
import { Rule } from '@kbn/triggers-actions-ui-plugin/public';
import React, { useCallback } from 'react';
import styled from 'styled-components';
import { SloIndicatorTypeBadge } from '../badges/slo_indicator_type_badge';
import { SloActiveAlertsBadge } from '../../../../components/slo/slo_status_badge/slo_active_alerts_badge';
import { BurnRateRuleParams } from '../../../../typings';
import { useUrlSearchState } from '../../hooks/use_url_search_state';
Expand Down Expand Up @@ -45,6 +46,11 @@ export function SloCardItemBadges({ slo, activeAlerts, rules, handleCreateRule }
[onStateChange]
);

const isRemote = !!slo.remote;

// in this case, there is more space to display tags
const numberOfTagsToDisplay = !isRemote || (rules ?? []).length > 0 ? 2 : 1;

return (
<Container
onClick={(evt) => {
Expand All @@ -57,13 +63,14 @@ export function SloCardItemBadges({ slo, activeAlerts, rules, handleCreateRule }
) : (
<>
<SloActiveAlertsBadge slo={slo} activeAlerts={activeAlerts} viewMode="compact" />
<SloIndicatorTypeBadge slo={slo} color="default" />
<SLOCardItemInstanceBadge slo={slo} />
<SloRulesBadge rules={rules} onClick={handleCreateRule} isRemote={!!slo.remote} />
<SloTimeWindowBadge slo={slo} color="default" />
<SloRemoteBadge slo={slo} />
<SloTagsList
tags={slo.tags}
numberOfTagsToDisplay={1}
numberOfTagsToDisplay={numberOfTagsToDisplay}
color="default"
ignoreEmpty
onClick={onTagClick}
Expand Down

0 comments on commit 3219dc8

Please sign in to comment.