Skip to content

Commit 4aeaf44

Browse files
jdonelsonclaude
andcommitted
console: share MetricCard between critical path and freshness
Moves MetricCard to components/ and renders the freshness statboxes with it. An optional background lets the statboxes keep their grey fill, now from the theme's tertiary surface. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 431f8b2 commit 4aeaf44

3 files changed

Lines changed: 50 additions & 37 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright Materialize, Inc. and contributors. All rights reserved.
2+
//
3+
// Use of this software is governed by the Business Source License
4+
// included in the LICENSE file.
5+
//
6+
// As of the Change Date specified in that file, in accordance with
7+
// the Business Source License, use of this software will be governed
8+
// by the Apache License, Version 2.0.
9+
10+
import { Card, Text, useTheme, VStack } from "@chakra-ui/react";
11+
import React from "react";
12+
13+
import { MaterializeTheme } from "~/theme";
14+
15+
export interface MetricCardProps {
16+
label: string;
17+
children: React.ReactNode;
18+
/** Defaults to the card's theme surface. */
19+
background?: string;
20+
}
21+
22+
/** A labelled tile: the label above whatever value it holds. */
23+
export const MetricCard = ({
24+
label,
25+
children,
26+
background,
27+
}: MetricCardProps) => {
28+
const { colors } = useTheme<MaterializeTheme>();
29+
return (
30+
<Card
31+
px={3}
32+
py={2}
33+
borderWidth="1px"
34+
borderColor={colors.border.primary}
35+
borderRadius="md"
36+
background={background}
37+
>
38+
<VStack align="stretch" spacing={2}>
39+
<Text textStyle="text-small" color={colors.foreground.secondary}>
40+
{label}
41+
</Text>
42+
{children}
43+
</VStack>
44+
</Card>
45+
);
46+
};

‎console/src/platform/freshness/FreshnessStatboxes.tsx‎

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Box, Grid, Skeleton, Text, useTheme } from "@chakra-ui/react";
1111
import React from "react";
1212

1313
import { NULL_LAG_TEXT } from "~/api/materialize/freshness/lagHistory";
14+
import { MetricCard } from "~/components/MetricCard";
1415
import { MaterializeTheme } from "~/theme";
1516
import { formatDurationExact } from "~/utils/format";
1617

@@ -54,16 +55,7 @@ const StatCard = ({
5455
const unreadable = value === UNREADABLE;
5556

5657
return (
57-
<Box
58-
borderWidth="1px"
59-
borderColor={colors.border.primary}
60-
borderRadius="lg"
61-
background="chakra-subtle-bg"
62-
padding="4"
63-
>
64-
<Text textStyle="text-small-heavy" color={colors.foreground.secondary}>
65-
{spec.label}
66-
</Text>
58+
<MetricCard label={spec.label} background={colors.background.tertiary}>
6759
{isLoading ? (
6860
<Skeleton height="6" width="16" marginY="1" />
6961
) : (
@@ -75,7 +67,7 @@ const StatCard = ({
7567
: formatDurationExact(value)}
7668
</Text>
7769
)}
78-
</Box>
70+
</MetricCard>
7971
);
8072
};
8173

‎console/src/platform/maintained-objects/CriticalPathClusterMetrics.tsx‎

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import React from "react";
2121
import { Link as RouterLink } from "react-router-dom";
2222

2323
import { Bucket } from "~/api/materialize/cluster/replicaUtilizationHistory";
24+
import { MetricCard } from "~/components/MetricCard";
2425
import TextLink from "~/components/TextLink";
2526
import {
2627
calculateMemDiskUtilizationStatus,
@@ -42,32 +43,6 @@ import { useJourneyLinkState } from "./useJourneyLinkState";
4243

4344
type Cluster = NonNullable<RenderableNode["cluster"]>;
4445

45-
const MetricCard = ({
46-
label,
47-
children,
48-
}: {
49-
label: string;
50-
children: React.ReactNode;
51-
}) => {
52-
const { colors } = useTheme<MaterializeTheme>();
53-
return (
54-
<Card
55-
px={3}
56-
py={2}
57-
borderWidth="1px"
58-
borderColor={colors.border.primary}
59-
borderRadius="md"
60-
>
61-
<VStack align="stretch" spacing={2}>
62-
<Text textStyle="text-small" color={colors.foreground.secondary}>
63-
{label}
64-
</Text>
65-
{children}
66-
</VStack>
67-
</Card>
68-
);
69-
};
70-
7146
const MetricBarCard = ({
7247
label,
7348
fraction,

0 commit comments

Comments
 (0)