Skip to content

Commit cbb6796

Browse files
fix: limit grain options in visual metrics (#8680)
* fix: limit grain options in visual metrics * feedback
1 parent e5dfdca commit cbb6796

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

web-common/src/features/workspaces/VisualMetrics.svelte

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,18 @@
1414
import { TIMESTAMPS } from "@rilldata/web-common/lib/duckdb-data-types";
1515
import { eventBus } from "@rilldata/web-common/lib/event-bus/event-bus";
1616
import { queryClient } from "@rilldata/web-common/lib/svelte-query/globalQueryClient";
17-
import { TIME_GRAIN } from "@rilldata/web-common/lib/time/config";
1817
import {
1918
createConnectorServiceOLAPListTables,
2019
createQueryServiceTableColumns,
2120
createRuntimeServiceAnalyzeConnectors,
2221
createRuntimeServiceGetInstance,
22+
} from "@rilldata/web-common/runtime-client";
23+
24+
import {
25+
V1TimeGrain,
2326
type MetricsViewSpecDimension,
2427
type V1Resource,
25-
} from "@rilldata/web-common/runtime-client";
28+
} from "@rilldata/web-common/runtime-client/gen/index.schemas";
2629
import { runtime } from "@rilldata/web-common/runtime-client/runtime-store";
2730
import { PlusIcon } from "lucide-svelte";
2831
import { tick } from "svelte";
@@ -48,6 +51,11 @@
4851
YAMLDimension,
4952
YAMLMeasure,
5053
} from "../visual-metrics-editing/lib";
54+
import {
55+
getAllowedGrainsFromOrder,
56+
getGrainOrder,
57+
V1TimeGrainToDateTimeUnit,
58+
} from "@rilldata/web-common/lib/time/new-grains";
5159
5260
const store = connectorExplorerStore.duplicateStore(
5361
(connector, database, schema, table) => {
@@ -207,6 +215,22 @@
207215
.filter(({ type }) => type && TIMESTAMPS.has(type))
208216
.map(({ name }) => ({ value: name ?? "", label: name ?? "" }));
209217
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+
210234
/** display the main error (the first in this array) at the bottom */
211235
$: mainError = errors?.at(0);
212236
@@ -637,10 +661,7 @@
637661
full
638662
truncate
639663
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}
644665
placeholder="Select time grain"
645666
label="Smallest time grain"
646667
hint="The smallest time unit by which your charts and tables can be bucketed"

0 commit comments

Comments
 (0)