Skip to content

Commit d9cf937

Browse files
gggritsocmanallen
authored andcommitted
feat(dashboards): Add Big Number Widget threshold hover (#79240)
Didn't want to lose this feature from the current implementation.
1 parent 9b3b1c0 commit d9cf937

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

static/app/views/dashboards/utils.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import {
6666
WidgetType,
6767
} from 'sentry/views/dashboards/types';
6868

69-
import ThresholdsHoverWrapper from './widgetBuilder/buildSteps/thresholdsStep/thresholdsHoverWrapper';
69+
import {ThresholdsHoverWrapper} from './widgetBuilder/buildSteps/thresholdsStep/thresholdsHoverWrapper';
7070
import type {ThresholdsConfig} from './widgetBuilder/buildSteps/thresholdsStep/thresholdsStep';
7171
import {ThresholdMaxKeys} from './widgetBuilder/buildSteps/thresholdsStep/thresholdsStep';
7272

@@ -188,7 +188,7 @@ export function getColoredWidgetIndicator(
188188
}
189189

190190
return (
191-
<ThresholdsHoverWrapper thresholds={thresholds} tableData={tableData}>
191+
<ThresholdsHoverWrapper thresholds={thresholds} type={dataType}>
192192
<CircleIndicator color={color} size={12} />
193193
</ThresholdsHoverWrapper>
194194
);

static/app/views/dashboards/widgetBuilder/buildSteps/thresholdsStep/thresholdsHoverWrapper.tsx

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,23 @@ import CircleIndicator from 'sentry/components/circleIndicator';
55
import {Hovercard} from 'sentry/components/hovercard';
66
import {t} from 'sentry/locale';
77
import {space} from 'sentry/styles/space';
8-
import type {TableDataWithTitle} from 'sentry/utils/discover/discoverQuery';
98
import theme from 'sentry/utils/theme';
109

1110
import type {ThresholdsConfig} from './thresholdsStep';
1211

1312
type Props = {
1413
children: React.ReactNode;
15-
tableData: TableDataWithTitle[];
1614
thresholds: ThresholdsConfig;
15+
type?: string;
1716
};
1817

19-
function ThresholdsHoverWrapper({children, thresholds, tableData}: Props) {
18+
export function ThresholdsHoverWrapper({children, thresholds, type}: Props) {
2019
const {
2120
unit,
2221
max_values: {max1, max2},
2322
} = thresholds;
24-
const tableMeta = {...tableData[0].meta};
25-
const fields = Object.keys(tableMeta);
26-
const field = fields[0];
27-
const dataType = tableMeta[field];
2823
const formattedUnit =
29-
unit && (dataType === 'duration' ? `${unit}s` : `/${unit.split('/')[1]}`);
24+
unit && (type === 'duration' ? `${unit}s` : `/${unit.split('/')[1]}`);
3025
const title = unit ? t(`Thresholds in %s`, formattedUnit) : t('Thresholds');
3126

3227
const notSetMsg = t('Not set');
@@ -87,5 +82,3 @@ const ContextTitle = styled('h6')`
8782
const StyledIndicator = styled(CircleIndicator)`
8883
margin-right: ${space(1)};
8984
`;
90-
91-
export default ThresholdsHoverWrapper;

static/app/views/dashboards/widgets/bigNumberWidget/bigNumberWidget.spec.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ describe('BigNumberWidget', () => {
218218
});
219219

220220
describe('Thresholds', () => {
221-
it('Evaluates the current value against a threshold', () => {
221+
it('Evaluates the current value against a threshold', async () => {
222222
render(
223223
<BigNumberWidget
224224
data={[
@@ -245,6 +245,9 @@ describe('BigNumberWidget', () => {
245245
);
246246

247247
expect(screen.getByRole('status')).toHaveAttribute('aria-label', 'meh');
248+
249+
await userEvent.hover(screen.getByRole('status'));
250+
expect(await screen.findByText('Thresholds in /second')).toBeInTheDocument();
248251
});
249252

250253
it('Normalizes the units', () => {

static/app/views/dashboards/widgets/bigNumberWidget/thresholdsIndicator.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import styled from '@emotion/styled';
44
import type {Polarity} from 'sentry/components/percentChange';
55

66
import {normalizeUnit} from '../../utils';
7+
import {ThresholdsHoverWrapper} from '../../widgetBuilder/buildSteps/thresholdsStep/thresholdsHoverWrapper';
78
import type {Thresholds} from '../common/types';
89

910
interface ThresholdsIndicatorProps {
@@ -39,7 +40,11 @@ export function ThresholdsIndicator({
3940

4041
const colorName = COLOR_NAME_FOR_STATE[state];
4142

42-
return <Circle role="status" aria-label={state} color={theme[colorName]} />;
43+
return (
44+
<ThresholdsHoverWrapper thresholds={thresholds} type={type}>
45+
<Circle role="status" aria-label={state} color={theme[colorName]} />
46+
</ThresholdsHoverWrapper>
47+
);
4348
}
4449

4550
const Circle = styled('div')<{color: string}>`

0 commit comments

Comments
 (0)