Skip to content

Commit dcfca43

Browse files
authored
feat: add Queries activities banner (#2549)
1 parent a4792fd commit dcfca43

File tree

15 files changed

+696
-10
lines changed

15 files changed

+696
-10
lines changed

src/components/MetricChart/MetricChart.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
display: flex;
33
flex-direction: column;
44

5-
padding: 16px 16px 8px;
5+
padding: var(--g-spacing-4) var(--g-spacing-4) var(--g-spacing-2);
66

77
border: 1px solid var(--g-color-line-generic);
88
border-radius: 8px;
99

10-
&__title {
11-
margin-bottom: 10px;
10+
&_noBorder {
11+
padding: 0;
12+
13+
border: none;
1214
}
1315

1416
&__chart {

src/components/MetricChart/MetricChart.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ const emptyChartData: PreparedMetricsData = {timeline: [], metrics: []};
103103
interface DiagnosticsChartProps {
104104
database: string;
105105

106-
title?: string;
107106
metrics: MetricDescription[];
108107
timeFrame?: TimeFrame;
109108

@@ -122,11 +121,19 @@ interface DiagnosticsChartProps {
122121
* Pass isChartVisible prop to ensure proper chart render
123122
*/
124123
isChartVisible?: boolean;
124+
125+
/** Remove border from chart */
126+
noBorder?: boolean;
127+
128+
/** Make chart take full width of container */
129+
fullWidth?: boolean;
130+
131+
/** Render custom toolbar content to the right of chart title */
132+
renderChartToolbar?: () => React.ReactNode;
125133
}
126134

127135
export const MetricChart = ({
128136
database,
129-
title,
130137
metrics,
131138
timeFrame = '1h',
132139
autorefresh,
@@ -135,7 +142,14 @@ export const MetricChart = ({
135142
chartOptions,
136143
onChartDataStatusChange,
137144
isChartVisible,
145+
noBorder,
146+
fullWidth,
147+
renderChartToolbar,
138148
}: DiagnosticsChartProps) => {
149+
// Use a reasonable default for maxDataPoints when fullWidth is true
150+
const effectiveWidth = fullWidth ? 600 : width;
151+
const maxDataPoints = effectiveWidth / 2;
152+
139153
const {currentData, error, isFetching, status} = chartApi.useGetChartDataQuery(
140154
// maxDataPoints param is calculated based on width
141155
// should be width > maxDataPoints to prevent points that cannot be selected
@@ -144,7 +158,7 @@ export const MetricChart = ({
144158
database,
145159
metrics,
146160
timeFrame,
147-
maxDataPoints: width / 2,
161+
maxDataPoints,
148162
},
149163
{pollingInterval: autorefresh},
150164
);
@@ -176,13 +190,13 @@ export const MetricChart = ({
176190

177191
return (
178192
<div
179-
className={b(null)}
193+
className={b({noBorder})}
180194
style={{
181195
height,
182-
width,
196+
width: fullWidth ? '100%' : width,
183197
}}
184198
>
185-
<div className={b('title')}>{title}</div>
199+
{renderChartToolbar?.()}
186200
{renderContent()}
187201
</div>
188202
);
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
@use '../../styles/mixins.scss';
2+
3+
.queries-activity-bar {
4+
$b: &;
5+
6+
margin-bottom: var(--diagnostics-section-title-margin);
7+
8+
border: 1px solid transparent;
9+
border-radius: var(--g-border-radius-m);
10+
11+
// Collapsed state (default)
12+
background-color: var(--g-color-base-float);
13+
14+
&_expanded {
15+
border: 1px solid var(--g-color-base-generic);
16+
border-radius: var(--g-border-radius-m);
17+
background-color: transparent;
18+
}
19+
20+
&__disclosure {
21+
width: 100%;
22+
}
23+
24+
&__header {
25+
display: flex;
26+
justify-content: space-between;
27+
align-items: center;
28+
gap: var(--g-spacing-3);
29+
30+
padding: var(--g-spacing-3) var(--g-spacing-4);
31+
32+
cursor: pointer;
33+
34+
border-radius: var(--g-border-radius-m);
35+
36+
transition: background-color 0.15s ease;
37+
38+
&:hover {
39+
background-color: var(--g-color-base-simple-hover);
40+
}
41+
42+
// When expanded, only round top corners
43+
#{$b}_expanded &:hover {
44+
background-color: transparent;
45+
}
46+
}
47+
48+
&__content-wrapper {
49+
display: flex;
50+
flex-grow: 1;
51+
align-items: center;
52+
gap: var(--g-spacing-2);
53+
}
54+
55+
&__metrics {
56+
display: flex;
57+
align-items: center;
58+
gap: var(--g-spacing-1);
59+
}
60+
61+
&__content {
62+
display: flex;
63+
flex-direction: column;
64+
gap: var(--g-spacing-4);
65+
}
66+
67+
&__stats {
68+
display: flex;
69+
flex-wrap: wrap;
70+
align-items: center;
71+
gap: var(--g-spacing-1);
72+
73+
padding: 0 var(--g-spacing-4);
74+
}
75+
76+
&__open-queries-button {
77+
margin-left: 4px;
78+
}
79+
80+
&__charts {
81+
display: flex;
82+
gap: var(--g-spacing-4);
83+
84+
padding: 0 var(--g-spacing-4);
85+
padding-top: var(--g-spacing-4);
86+
87+
@media (max-width: 1200px) {
88+
flex-direction: column;
89+
}
90+
}
91+
92+
&__chart-container {
93+
display: flex;
94+
flex: 1;
95+
flex-direction: column;
96+
gap: var(--g-spacing-3);
97+
}
98+
99+
&__toolbar {
100+
margin-bottom: 10px;
101+
}
102+
103+
// Focus states for accessibility
104+
&__header:focus-visible,
105+
&__open-queries-button:focus-visible {
106+
outline: 2px solid var(--g-color-line-focus);
107+
outline-offset: 2px;
108+
}
109+
}

0 commit comments

Comments
 (0)