From 7ff21523bc78caf285aad9b2a3c529bdaef90e12 Mon Sep 17 00:00:00 2001 From: Maciej Bodek Date: Mon, 2 Dec 2024 17:29:25 +0100 Subject: [PATCH] Default timespan to 1h --- .../src/scenes/Editor/Metrics/index.tsx | 21 ++++++++++--------- .../src/scenes/Editor/Metrics/metric.tsx | 5 ----- .../src/scenes/Editor/Metrics/utils.ts | 18 +++++++++------- .../web-console/src/scenes/Schema/index.tsx | 2 +- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/packages/web-console/src/scenes/Editor/Metrics/index.tsx b/packages/web-console/src/scenes/Editor/Metrics/index.tsx index d75a8f049..4c03bbb0a 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/index.tsx +++ b/packages/web-console/src/scenes/Editor/Metrics/index.tsx @@ -77,8 +77,7 @@ const formatDurationLabel = (duration: MetricDuration) => `Last ${duration}` export const Metrics = () => { const { activeBuffer, updateBuffer, buffers } = useEditor() const [metricDuration, setMetricDuration] = useState( - (activeBuffer?.metricsViewState?.metricDuration as MetricDuration) ?? - MetricDuration.SEVEN_DAYS, + MetricDuration.ONE_HOUR, ) const [dialogOpen, setDialogOpen] = useState(false) const [metrics, setMetrics] = useState([]) @@ -128,15 +127,17 @@ export const Metrics = () => { } useEffect(() => { - const metrics = buffer?.metricsViewState?.metrics - const metricDuration = buffer?.metricsViewState?.metricDuration - if (metrics) { - setMetrics(metrics) + if (buffer) { + const metrics = buffer?.metricsViewState?.metrics + const metricDuration = buffer?.metricsViewState?.metricDuration + if (metrics) { + setMetrics(metrics) + } + if (metricDuration) { + setMetricDuration(metricDuration) + } } - if (metricDuration) { - setMetricDuration(metricDuration) - } - }, [buffers, activeBuffer]) + }, [buffer]) useEffect(() => { if ( diff --git a/packages/web-console/src/scenes/Editor/Metrics/metric.tsx b/packages/web-console/src/scenes/Editor/Metrics/metric.tsx index d1b4002ce..ad07daa65 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/metric.tsx +++ b/packages/web-console/src/scenes/Editor/Metrics/metric.tsx @@ -50,11 +50,6 @@ const ActionButton = styled(Button)` width: 3rem; ` -const sqlValueToFixed = (value: string, decimals: number = 2) => { - const parsed = parseFloat(value) - return Number(parsed.toFixed(decimals)) as unknown as number -} - export const Metric = ({ metric, metricDuration, diff --git a/packages/web-console/src/scenes/Editor/Metrics/utils.ts b/packages/web-console/src/scenes/Editor/Metrics/utils.ts index 774cf8680..37a042a37 100644 --- a/packages/web-console/src/scenes/Editor/Metrics/utils.ts +++ b/packages/web-console/src/scenes/Editor/Metrics/utils.ts @@ -24,6 +24,7 @@ export enum MetricDuration { } export enum SampleBy { + ONE_SECOND = "1s", ONE_MINUTE = "1m", FIFTEEN_MINUTES = "15m", ONE_HOUR = "1h", @@ -40,13 +41,13 @@ export const durationInMinutes: Record = { } export const mappedSampleBy: Record = { - [MetricDuration.ONE_HOUR]: SampleBy.ONE_MINUTE, - [MetricDuration.THREE_HOURS]: SampleBy.ONE_MINUTE, - [MetricDuration.SIX_HOURS]: SampleBy.ONE_MINUTE, - [MetricDuration.TWELVE_HOURS]: SampleBy.FIFTEEN_MINUTES, - [MetricDuration.TWENTY_FOUR_HOURS]: SampleBy.FIFTEEN_MINUTES, - [MetricDuration.THREE_DAYS]: SampleBy.ONE_HOUR, - [MetricDuration.SEVEN_DAYS]: SampleBy.ONE_HOUR, + [MetricDuration.ONE_HOUR]: SampleBy.ONE_SECOND, + [MetricDuration.THREE_HOURS]: SampleBy.ONE_SECOND, + [MetricDuration.SIX_HOURS]: SampleBy.ONE_SECOND, + [MetricDuration.TWELVE_HOURS]: SampleBy.ONE_SECOND, + [MetricDuration.TWENTY_FOUR_HOURS]: SampleBy.ONE_MINUTE, + [MetricDuration.THREE_DAYS]: SampleBy.ONE_MINUTE, + [MetricDuration.SEVEN_DAYS]: SampleBy.ONE_MINUTE, } export type RowsApplied = { @@ -73,6 +74,9 @@ export const minutesToDays = (durationInMinutes: number) => export const minutesToHours = (durationInMinutes: number) => durationInMinutes / 60 +export const minutesToSeconds = (durationInMinutes: number) => + durationInMinutes * 60 + export const xAxisFormat = { [MetricDuration.ONE_HOUR]: (rawValue: number) => utcToLocal(rawValue, "HH:mm"), diff --git a/packages/web-console/src/scenes/Schema/index.tsx b/packages/web-console/src/scenes/Schema/index.tsx index 499b46475..d40c7d318 100644 --- a/packages/web-console/src/scenes/Schema/index.tsx +++ b/packages/web-console/src/scenes/Schema/index.tsx @@ -469,7 +469,7 @@ const Schema = ({ addBuffer({ metricsViewState: { metrics: [], - metricDuration: MetricDuration.SEVEN_DAYS, + metricDuration: MetricDuration.ONE_HOUR, }, }) }}