Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import { useMetrics } from "queries/Metric";
import { usePresets } from "queries/Preset";
import { SourceFormValues } from "../SourceForm.types";

type PresetOption = {
label: string;
description?: string;
};


export const SourceFormStepMetrics = () => {
const { control, register, watch, formState: { errors }, clearErrors } = useFormContext<SourceFormValues>();
const metricsFields = useFieldArray({ control, name: "Metrics" });
Expand Down Expand Up @@ -35,10 +41,42 @@ export const SourceFormStepMetrics = () => {
const presets = usePresets();
const metrics = useMetrics();

const presetsOptions = useMemo(
() => presets.data ? Object.keys(presets.data).map((key) => ({ label: key })) : [],
[presets.data],
);

type PresetMeta = {
Description?: string;
};

const presetsOptions = useMemo<PresetOption[]>(() => {
const PRESET_PRIORITY = ["minimal", "basic", "full", "exhaustive"];

if (!presets.data) {
return [];
}

return Object.entries(presets.data)
.sort(([a], [b]) => {
const ia = PRESET_PRIORITY.indexOf(a);
const ib = PRESET_PRIORITY.indexOf(b);

if (ia === -1 && ib === -1) {
return a.localeCompare(b);
}
if (ia === -1) {
return 1;
}
if (ib === -1) {
return -1;
}
return ia - ib;
})
.map(([key, preset]) => {
const p = preset as PresetMeta;
return {
label: key,
description: p.Description ?? "",
};
});
}, [presets.data]);

const metricsOptions = useMemo(
() => metrics.data ? Object.keys(metrics.data).map((key) => ({ label: key })) : [],
Expand Down Expand Up @@ -83,6 +121,7 @@ export const SourceFormStepMetrics = () => {
loading={presets.isLoading}
error={hasError("PresetMetrics")}
/>

)}
/>
<FormHelperText>{getError("PresetMetrics")}</FormHelperText>
Expand Down Expand Up @@ -162,6 +201,7 @@ export const SourceFormStepMetrics = () => {
options={presetsOptions}
loading={presets.isLoading}
/>

)}
/>
</FormControl>
Expand Down
Loading