Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cloud Posture] Dashboard Redesign - data counter cards #144565

Merged
merged 17 commits into from
Nov 9, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export const CompactFormattedNumber = ({
abbreviateAbove?: number;
}) => {
if (number <= abbreviateAbove) {
return <span>{number.toLocaleString('en-US')}</span>;
return <span>{number.toLocaleString()}</span>;
}

return (
<EuiToolTip content={number.toLocaleString('en-US')}>
<EuiToolTip content={number.toLocaleString()}>
<span>
{number.toLocaleString('en-US', {
{number.toLocaleString(undefined, {
notation: 'compact',
maximumFractionDigits: 1,
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,43 @@

import React from 'react';
import { css } from '@emotion/react';
import { EuiCard, EuiIcon, EuiStat, useEuiTheme } from '@elastic/eui';
import type { EuiStatProps, EuiCardProps } from '@elastic/eui';
import { EuiCard, EuiIcon, EuiText, EuiTitle, useEuiTheme } from '@elastic/eui';
import type { EuiTextProps, EuiCardProps } from '@elastic/eui';

export type CspCounterCardProps = Pick<EuiCardProps, 'onClick' | 'id'> &
Pick<EuiStatProps, 'title' | 'description' | 'titleColor' | 'isLoading'>;
export type CspCounterCardProps = Pick<EuiCardProps, 'onClick' | 'id' | 'title' | 'description'> & {
descriptionColor?: EuiTextProps['color'];
};

export const CspCounterCard = ({ counter }: { counter: CspCounterCardProps }) => {
export const CspCounterCard = (counter: CspCounterCardProps) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider de-structuring props in the arguments: ({ title, onClick, id, description, descriptionColor })

const { euiTheme } = useEuiTheme();

return (
<EuiCard
title=""
title={
<EuiTitle size="xxxs">
<h6>{counter.title}</h6>
</EuiTitle>
}
hasBorder
onClick={counter.onClick}
paddingSize="m"
textAlign="left"
layout="vertical"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the default and can be omitted as we don't really care about the layout since we don't use an icon, we only care about the text alignment

css={css`
position: relative;

.euiCard__title {
display: none;
}

:hover .euiIcon {
color: ${euiTheme.colors.primary};
transition: ${euiTheme.animation.normal};
}
`}
data-test-subj={counter.id}
>
<EuiStat
descriptionElement="h5"
titleSize="s"
isLoading={counter.isLoading}
description={counter.description}
title={counter.title || 0}
titleColor={counter.titleColor}
css={css`
display: flex;
flex-direction: column;
gap: ${euiTheme.size.m};
`}
/>
<EuiText color={counter.descriptionColor}>
<EuiTitle size="xs">
<h3>{counter.description}</h3>
</EuiTitle>
</EuiText>
{counter.onClick && (
<EuiIcon
type="link"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import React from 'react';
import { coreMock } from '@kbn/core/public/mocks';
import { render } from '@testing-library/react';
import { expectIdsInDoc } from '../../../test/utils';
import { DASHBOARD_COUNTER_CARDS } from '../test_subjects';
Expand All @@ -16,28 +15,9 @@ import { TestProvider } from '../../../test/test_provider';
import { screen } from '@testing-library/react';

describe('<CloudSummarySection />', () => {
Copy link
Contributor

@ari-aviran ari-aviran Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd expect tests here to verify the rest of the functionality of the section (risks table, score chart, etc.) If you consider this out of scope please open a task

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah i'll add those tests here on every new component task, its already listed in the tasks

beforeEach(() => {
jest.resetAllMocks();
});

const renderCloudSummarySection = (alterMockData = {}) => {
const mockCore = coreMock.createStart();

render(
<TestProvider
core={{
...mockCore,
application: {
...mockCore.application,
capabilities: {
...mockCore.application.capabilities,
// This is required so that the `noDataConfig` view will show the action button
navLinks: { integrations: true },
},
},
}}
>
{/* <ComplianceDashboard />*/}
<TestProvider>
<CloudSummarySection complianceData={{ ...mockDashboardData, ...alterMockData }} />
</TestProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,31 +67,33 @@ export const CloudSummarySection = ({
() => [
{
id: DASHBOARD_COUNTER_CARDS.CLUSTERS_EVALUATED,
title: <CompactFormattedNumber number={complianceData.clusters.length} />,
description: i18n.translate(
title: i18n.translate(
'xpack.csp.dashboard.summarySection.counterCard.clustersEvaluatedDescription',
{ defaultMessage: 'Clusters Evaluated' }
),
description: <CompactFormattedNumber number={complianceData.clusters.length} />,
},
{
id: DASHBOARD_COUNTER_CARDS.RESOURCES_EVALUATED,
title: <CompactFormattedNumber number={complianceData.stats.resourcesEvaluated || 0} />,
description: i18n.translate(
title: i18n.translate(
'xpack.csp.dashboard.summarySection.counterCard.resourcesEvaluatedDescription',
{ defaultMessage: 'Resources Evaluated' }
),
description: (
<CompactFormattedNumber number={complianceData.stats.resourcesEvaluated || 0} />
),
onClick: () => {
navToFindingsByResource();
},
},
{
id: DASHBOARD_COUNTER_CARDS.FAILING_FINDINGS,
title: <CompactFormattedNumber number={complianceData.stats.totalFailed} />,
description: i18n.translate(
title: i18n.translate(
'xpack.csp.dashboard.summarySection.counterCard.failingFindingsDescription',
{ defaultMessage: 'Failing Findings' }
),
titleColor: complianceData.stats.totalFailed > 0 ? 'danger' : 'text',
description: <CompactFormattedNumber number={complianceData.stats.totalFailed} />,
descriptionColor: complianceData.stats.totalFailed > 0 ? 'danger' : 'text',
onClick: () => {
navToFindings({ 'result.evaluation': RULE_FAILED });
},
Expand All @@ -112,7 +114,7 @@ export const CloudSummarySection = ({
<EuiFlexGroup direction="column">
{counters.map((counter) => (
<EuiFlexItem key={counter.id}>
<CspCounterCard counter={counter} />
<CspCounterCard {...counter} />
</EuiFlexItem>
))}
</EuiFlexGroup>
Expand Down