use range instead of dates across the web

This commit is contained in:
Carl-Gerhard Lindesvärd
2023-10-28 21:58:17 +02:00
parent c8c86d8c23
commit c5823dc4cb
11 changed files with 156 additions and 96 deletions

View File

@@ -19,15 +19,26 @@ export const intervals = {
month: "Month",
};
export const alphabetIds = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"] as const;
export const alphabetIds = [
"A",
"B",
"C",
"D",
"E",
"F",
"G",
"H",
"I",
"J",
] as const;
export const timeRanges = {
'today': 'Today',
1: '24 hours',
7: '7 days',
14: '14 days',
30: '30 days',
90: '3 months',
180: '6 months',
365: '1 year',
}
export const timeRanges = [
{ range: 0, title: "Today" },
{ range: 1, title: "24 hours" },
{ range: 7, title: "7 days" },
{ range: 14, title: "14 days" },
{ range: 30, title: "30 days" },
{ range: 90, title: "3 months" },
{ range: 180, title: "6 months" },
{ range: 365, title: "1 year" },
] as const

View File

@@ -15,10 +15,4 @@ export function toDots(
[`${path}${key}`]: value,
};
}, {});
}
export function entries<K extends string | number | symbol, V>(
obj: Record<K, V>,
): [K, V][] {
return Object.entries(obj) as [K, V][];
}
}

View File

@@ -1,9 +1,9 @@
import { z } from "zod";
import { operators, chartTypes, intervals } from "./constants";
function objectToZodEnums<K extends string> ( obj: Record<K, any> ): [ K, ...K[] ] {
const [ firstKey, ...otherKeys ] = Object.keys( obj ) as K[]
return [ firstKey!, ...otherKeys ]
function objectToZodEnums<K extends string>(obj: Record<K, any>): [K, ...K[]] {
const [firstKey, ...otherKeys] = Object.keys(obj) as K[];
return [firstKey!, ...otherKeys];
}
export const zChartEvent = z.object({
@@ -15,13 +15,7 @@ export const zChartEvent = z.object({
id: z.string(),
name: z.string(),
operator: z.enum(objectToZodEnums(operators)),
value: z.array(
z
.string()
.or(z.number())
.or(z.boolean())
.or(z.null())
),
value: z.array(z.string().or(z.number()).or(z.boolean()).or(z.null())),
}),
),
});
@@ -39,10 +33,22 @@ export const zTimeInterval = z.enum(objectToZodEnums(intervals));
export const zChartInput = z.object({
name: z.string(),
startDate: z.string(),
endDate: z.string(),
chartType: zChartType,
interval: zTimeInterval,
events: zChartEvents,
breakdowns: zChartBreakdowns,
range: z
.literal(0)
.or(z.literal(1))
.or(z.literal(7))
.or(z.literal(14))
.or(z.literal(30))
.or(z.literal(90))
.or(z.literal(180))
.or(z.literal(365)),
});
export const zChartInputWithDates = zChartInput.extend({
startDate: z.string().nullish(),
endDate: z.string().nullable(),
});