|
14 | 14 | import { TIMESTAMPS } from "@rilldata/web-common/lib/duckdb-data-types"; |
15 | 15 | import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus"; |
16 | 16 | import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient"; |
17 | | - import { TIME_GRAIN } from "@rilldata/web-common/lib/time/config"; |
18 | 17 | import { |
19 | 18 | createConnectorServiceOLAPListTables, |
20 | 19 | createQueryServiceTableColumns, |
21 | 20 | createRuntimeServiceAnalyzeConnectors, |
22 | 21 | createRuntimeServiceGetInstance, |
| 22 | + } from "@rilldata/web-common/runtime-client"; |
| 23 | +
|
| 24 | + import { |
| 25 | + V1TimeGrain, |
23 | 26 | type MetricsViewSpecDimension, |
24 | 27 | type V1Resource, |
25 | | - } from "@rilldata/web-common/runtime-client"; |
| 28 | + } from "@rilldata/web-common/runtime-client/gen/index.schemas"; |
26 | 29 | import { runtime } from "@rilldata/web-common/runtime-client/runtime-store"; |
27 | 30 | import { PlusIcon } from "lucide-svelte"; |
28 | 31 | import { tick } from "svelte"; |
|
48 | 51 | YAMLDimension, |
49 | 52 | YAMLMeasure, |
50 | 53 | } from "../visual-metrics-editing/lib"; |
| 54 | + import { |
| 55 | + getAllowedGrainsFromOrder, |
| 56 | + getGrainOrder, |
| 57 | + V1TimeGrainToDateTimeUnit, |
| 58 | + } from "@rilldata/web-common/lib/time/new-grains"; |
51 | 59 |
|
52 | 60 | const store = connectorExplorerStore.duplicateStore( |
53 | 61 | (connector, database, schema, table) => { |
|
207 | 215 | .filter(({ type }) => type && TIMESTAMPS.has(type)) |
208 | 216 | .map(({ name }) => ({ value: name ?? "", label: name ?? "" })); |
209 | 217 |
|
| 218 | + $: typeOfSelectedTimeDimension = columns.find( |
| 219 | + ({ name }) => name === timeDimension, |
| 220 | + )?.type; |
| 221 | +
|
| 222 | + $: availableGrainOptions = getAllowedGrainsFromOrder( |
| 223 | + typeOfSelectedTimeDimension === "DATE" |
| 224 | + ? getGrainOrder(V1TimeGrain.TIME_GRAIN_DAY) |
| 225 | + : getGrainOrder(V1TimeGrain.TIME_GRAIN_MINUTE), |
| 226 | + ).map((grain) => { |
| 227 | + const label = V1TimeGrainToDateTimeUnit[grain]; |
| 228 | + return { |
| 229 | + value: label, |
| 230 | + label: label.charAt(0).toUpperCase() + label.slice(1), |
| 231 | + }; |
| 232 | + }); |
| 233 | +
|
210 | 234 | /** display the main error (the first in this array) at the bottom */ |
211 | 235 | $: mainError = errors?.at(0); |
212 | 236 |
|
|
637 | 661 | full |
638 | 662 | truncate |
639 | 663 | value={smallestTimeGrain} |
640 | | - options={Object.entries(TIME_GRAIN).map(([_, { label }]) => ({ |
641 | | - value: label, |
642 | | - label: label.charAt(0).toUpperCase() + label.slice(1), |
643 | | - }))} |
| 664 | + options={availableGrainOptions} |
644 | 665 | placeholder="Select time grain" |
645 | 666 | label="Smallest time grain" |
646 | 667 | hint="The smallest time unit by which your charts and tables can be bucketed" |
|
0 commit comments