Skip to content

Commit

Permalink
Default timespan to 1h
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Dec 2, 2024
1 parent bc507c8 commit 7ff2152
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
21 changes: 11 additions & 10 deletions packages/web-console/src/scenes/Editor/Metrics/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ const formatDurationLabel = (duration: MetricDuration) => `Last ${duration}`
export const Metrics = () => {
const { activeBuffer, updateBuffer, buffers } = useEditor()
const [metricDuration, setMetricDuration] = useState<MetricDuration>(
(activeBuffer?.metricsViewState?.metricDuration as MetricDuration) ??
MetricDuration.SEVEN_DAYS,
MetricDuration.ONE_HOUR,
)
const [dialogOpen, setDialogOpen] = useState(false)
const [metrics, setMetrics] = useState<Metric[]>([])
Expand Down Expand Up @@ -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 (
Expand Down
5 changes: 0 additions & 5 deletions packages/web-console/src/scenes/Editor/Metrics/metric.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 11 additions & 7 deletions packages/web-console/src/scenes/Editor/Metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export enum MetricDuration {
}

export enum SampleBy {
ONE_SECOND = "1s",
ONE_MINUTE = "1m",
FIFTEEN_MINUTES = "15m",
ONE_HOUR = "1h",
Expand All @@ -40,13 +41,13 @@ export const durationInMinutes: Record<MetricDuration, number> = {
}

export const mappedSampleBy: Record<MetricDuration, SampleBy> = {
[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 = {
Expand All @@ -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"),
Expand Down
2 changes: 1 addition & 1 deletion packages/web-console/src/scenes/Schema/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ const Schema = ({
addBuffer({
metricsViewState: {
metrics: [],
metricDuration: MetricDuration.SEVEN_DAYS,
metricDuration: MetricDuration.ONE_HOUR,
},
})
}}
Expand Down

0 comments on commit 7ff2152

Please sign in to comment.