From 31c44401544f8b723103d3397e9bd69e464bf8e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Bombeck?= Date: Thu, 12 Nov 2026 12:58:37 +0100 Subject: [PATCH] refactor(custom-metrics): read a refused save in one helper Matching the name clash by its code grew the form component past its size baseline. The refusal's sentence now comes from a helper beside it. --- .../custom-metrics/custom-metric-form.tsx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/components/custom-metrics/custom-metric-form.tsx b/src/components/custom-metrics/custom-metric-form.tsx index 664fdd911..bec187da1 100644 --- a/src/components/custom-metrics/custom-metric-form.tsx +++ b/src/components/custom-metrics/custom-metric-form.tsx @@ -60,6 +60,17 @@ interface CustomMetricFormProps { footerSlot?: HTMLElement | null; } +/** + * The sentence for a refused save. A name clash is read by its code: a 409 + * can also be the first save still running under the same key. + */ +function saveRefusal(err: unknown, t: (key: string) => string): string { + return err instanceof ApiError && + err.meta?.errorCode === "customMetric.name_taken" + ? t("customMetrics.form.nameTaken") + : localizedApiError(err, t, "customMetrics.form.saveError"); +} + /** * v1.25.5 — define or edit a custom metric. * @@ -132,13 +143,7 @@ export function CustomMetricForm({ ); onSuccess?.(saved); } catch (err) { - // By its code: a 409 can also be the first save still running. - setError( - err instanceof ApiError && - err.meta?.errorCode === "customMetric.name_taken" - ? t("customMetrics.form.nameTaken") - : localizedApiError(err, t, "customMetrics.form.saveError"), - ); + setError(saveRefusal(err, t)); } finally { setSubmitting(false); }