Skip to content

Commit

Permalink
Cap date range at 7 days
Browse files Browse the repository at this point in the history
  • Loading branch information
insmac committed Jan 15, 2025
1 parent b806a45 commit 8cbec45
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 14 additions & 12 deletions packages/web-console/src/scenes/Editor/Metrics/date-time-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
durationToHumanReadable,
durationTokenToDate,
isDateToken,
MAX_DATE_RANGE,
} from "./utils"
import { DateRange } from "./types"
import { Box, Button, Popover } from "@questdb/react-components"
Expand Down Expand Up @@ -197,6 +198,7 @@ export const DateTimePicker = ({
"string.fromIsAfterTo": "From date must be before To date",
"string.sameValues": "From and To dates cannot be the same",
"any.custom": "One of the values is invalid",
"string.maxDateRange": "Date range cannot exceed 7 days",
}

const schema = Joi.object({
Expand All @@ -207,19 +209,19 @@ export const DateTimePicker = ({
const timeValue = new Date(dateValue).getTime()
const timeNow = new Date().getTime()
try {
const timeTo = new Date(
durationTokenToDate(helpers.state.ancestors[0].dateTo),
).getTime()
if (dateValue === "Invalid date") {
return helpers.error("string.invalidDate")
} else if (
timeValue >=
new Date(
durationTokenToDate(helpers.state.ancestors[0].dateTo),
).getTime()
) {
} else if (timeValue >= timeTo) {
return helpers.error("string.fromIsAfterTo")
} else if (timeValue > timeNow) {
return helpers.error("string.dateInFuture")
} else if (timeValue === timeNow) {
return helpers.error("string.sameValues")
} else if (timeTo - timeValue > MAX_DATE_RANGE * 1000) {
return helpers.error("string.maxDateRange")
}
return value
} catch (e) {
Expand All @@ -233,19 +235,19 @@ export const DateTimePicker = ({
const dateValue = durationTokenToDate(value)
const timeValue = new Date(dateValue).getTime()
const timeNow = new Date().getTime()
const timeFrom = new Date(
durationTokenToDate(helpers.state.ancestors[0].dateFrom),
).getTime()
if (dateValue === "Invalid date") {
return helpers.error("string.invalidDate")
} else if (
timeValue <=
new Date(
durationTokenToDate(helpers.state.ancestors[0].dateFrom),
).getTime()
) {
} else if (timeValue <= timeFrom) {
return helpers.error("string.toIsBeforeFrom")
} else if (timeValue > timeNow) {
return helpers.error("string.dateInFuture")
} else if (timeValue === timeNow) {
return helpers.error("string.sameValues")
} else if (timeValue - timeFrom > MAX_DATE_RANGE * 1000) {
return helpers.error("string.maxDateRange")
}
return value
})
Expand Down
2 changes: 2 additions & 0 deletions packages/web-console/src/scenes/Editor/Metrics/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import type { Duration } from "./types"

export const DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss"

export const MAX_DATE_RANGE = 7 * 24 * 60 * 60

export enum MetricType {
COMMIT_RATE = "Commit rate",
WRITE_THROUGHPUT = "Write throughput",
Expand Down

0 comments on commit 8cbec45

Please sign in to comment.