Skip to content

Commit

Permalink
[Dataset Quality] Show dataset quality in details page
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedhamed-ahmed committed Nov 13, 2024
1 parent 714f41e commit 432bf23
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ export const getDatasetQualityTableColumns = ({
field: 'degradedDocs.percentage',
sortable: true,
render: (_, dataStreamStat: DataStreamStat) => (
<DatasetQualityIndicator isLoading={loadingDegradedStats} dataStreamStat={dataStreamStat} />
<DatasetQualityIndicator
isLoading={loadingDegradedStats}
quality={dataStreamStat.quality}
/>
),
width: '140px',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
overviewPanelTitleResources,
} from '../../../../../common/translations';
import { useOverviewSummaryPanel } from '../../../../hooks/use_overview_summary_panel';
import { DatasetQualityIndicator } from '../../../quality_indicator';

// Allow for lazy loading
// eslint-disable-next-line import/no-default-export
Expand All @@ -31,6 +32,7 @@ export default function Summary() {
totalServicesCount,
totalHostsCount,
totalDegradedDocsCount,
quality,
} = useOverviewSummaryPanel();
return (
<EuiFlexGroup gutterSize="m">
Expand Down Expand Up @@ -59,7 +61,16 @@ export default function Summary() {
isLoading={isSummaryPanelLoading}
/>
</Panel>
<Panel title={overviewPanelTitleDatasetQuality}>
<Panel
title={overviewPanelTitleDatasetQuality}
secondaryTitle={
<DatasetQualityIndicator
isLoading={isSummaryPanelLoading}
quality={quality}
textSize="xs"
/>
}
>
<PanelIndicator
label={overviewPanelDatasetQualityIndicatorDegradedDocs}
value={totalDegradedDocsCount}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import { EuiSkeletonRectangle, EuiFlexGroup } from '@elastic/eui';
import React from 'react';
import { capitalize } from 'lodash';
import { i18n } from '@kbn/i18n';
import { QualityIndicators } from '../../../common/types';
import { QualityIndicator } from '.';
import { DataStreamStat } from '../../../common/data_streams_stats/data_stream_stat';

export const DatasetQualityIndicator = ({
isLoading,
dataStreamStat,
quality,
textSize = 's',
}: {
isLoading: boolean;
dataStreamStat: DataStreamStat;
quality: QualityIndicators;
textSize?: 'xs' | 's' | 'm';
}) => {
const { quality } = dataStreamStat;

const translatedQuality = i18n.translate('xpack.datasetQuality.datasetQualityIdicator', {
defaultMessage: '{quality}',
values: { quality: capitalize(quality) },
Expand All @@ -29,7 +29,12 @@ export const DatasetQualityIndicator = ({
return (
<EuiSkeletonRectangle width="50px" height="20px" borderRadius="m" isLoading={isLoading}>
<EuiFlexGroup alignItems="center" gutterSize="s">
<QualityIndicator quality={quality} description={translatedQuality} isColoredDescription />
<QualityIndicator
textSize={textSize}
quality={quality}
description={translatedQuality}
isColoredDescription
/>
</EuiFlexGroup>
</EuiSkeletonRectangle>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@

import { EuiHealth, EuiText } from '@elastic/eui';
import React, { ReactNode } from 'react';
import { QualityIndicators, InfoIndicators } from '../../../common/types';
import type { QualityIndicators, InfoIndicators } from '../../../common/types';

export function QualityIndicator({
quality,
description,
isColoredDescription,
textSize = 's',
}: {
quality: QualityIndicators;
description: string | ReactNode;
isColoredDescription?: boolean;
textSize?: 'xs' | 's' | 'm';
}) {
const qualityColors: Record<QualityIndicators, InfoIndicators> = {
poor: 'danger',
Expand All @@ -25,8 +27,8 @@ export function QualityIndicator({
};

return (
<EuiHealth color={qualityColors[quality]}>
<EuiText size="s" color={isColoredDescription ? qualityColors[quality] : 'white'}>
<EuiHealth color={qualityColors[quality]} textSize={textSize}>
<EuiText size="relative" color={isColoredDescription ? qualityColors[quality] : 'white'}>
{description}
</EuiText>
</EuiHealth>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { useSelector } from '@xstate/react';
import { formatNumber } from '@elastic/eui';
import { mapPercentageToQuality } from '../../common/utils';
import { BYTE_NUMBER_FORMAT, MAX_HOSTS_METRIC_VALUE, NUMBER_FORMAT } from '../../common/constants';
import { useDatasetQualityDetailsContext } from '../components/dataset_quality_details/context';

Expand Down Expand Up @@ -54,6 +55,13 @@ export const useOverviewSummaryPanel = () => {
NUMBER_FORMAT
);

const degradedPercentage =
Number(totalDocsCount) > 0
? (Number(totalDegradedDocsCount) / Number(totalDocsCount)) * 100
: 0;

const quality = mapPercentageToQuality(degradedPercentage);

return {
totalDocsCount,
sizeInBytes,
Expand All @@ -62,6 +70,7 @@ export const useOverviewSummaryPanel = () => {
totalHostsCount,
isSummaryPanelLoading,
totalDegradedDocsCount,
quality,
};
};

Expand Down

0 comments on commit 432bf23

Please sign in to comment.