Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix localization number separators (#64300)

lbrdnkcebbfb235f92
diff --git a/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.tsx b/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.tsx
index 572ed34c395..90178a1c4f8 100644
--- a/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.tsx
+++ b/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.tsx
@@ -158,7 +158,7 @@ export function FormattingWidget() {
{ label: "100 000,00", value: ", " },
{ label: "100.000,00", value: ",." },
{ label: "100000.00", value: "." },
- { label: "100'000.00", value: ".'" },
+ { label: "100’000.00", value: ".’" },
]}
onChange={(newValue) =>
handleChange({
diff --git a/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.unit.spec.tsx
index 67f1c381db4..31755249a27 100644
--- a/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.unit.spec.tsx
+++ b/frontend/src/metabase/admin/settings/components/widgets/FormattingWidget.unit.spec.tsx
@@ -164,4 +164,21 @@ describe("FormattingWidget", () => {
expect(toasts).toHaveLength(6);
});
});
+
+ it("should provide expected number separators (#61854)", async () => {
+ await setup();
+
+ const seperatorStyleInput = await screen.findByLabelText("Separator style");
+ await userEvent.click(seperatorStyleInput);
+
+ const [dropdown] = screen.getAllByRole("listbox");
+ const children = within(dropdown).getAllByRole("option");
+ expect(children.length).toBe(5);
+
+ expect(within(dropdown).getByText("100,000.00")).toBeInTheDocument();
+ expect(within(dropdown).getByText("100 000,00")).toBeInTheDocument();
+ expect(within(dropdown).getByText("100.000,00")).toBeInTheDocument();
+ expect(within(dropdown).getByText("100000.00")).toBeInTheDocument();
+ expect(within(dropdown).getByText("100’000.00")).toBeInTheDocument();
+ });
});
diff --git a/src/metabase/appearance/settings.clj b/src/metabase/appearance/settings.clj
index 5dd5a8e21eb..7e5476d96e9 100644
--- a/src/metabase/appearance/settings.clj
+++ b/src/metabase/appearance/settings.clj
@@ -341,6 +341,23 @@ See [fonts](../configuring-metabase/fonts.md).")
:audit :getter
:feature :whitelabel)
+(def avaialable-number-separators
+ "Number separators that are available to use in uploads csv parsing. Values match what is implemented
+ `metabase.upload.types` namespace, specifically e.g. [[metabase.upload.types/int-regex]]."
+ #{"."
+ ".,"
+ ",."
+ ", "
+ ".’"})
+
+(defn- validate-custom-formatting!
+ [new-value]
+ (when-some [separators (some-> new-value :type/Number :number_separators)]
+ (when-not (avaialable-number-separators separators)
+ (throw (ex-info (tru "Invalid number separators.")
+ {:separators separators
+ :available-separators avaialable-number-separators})))))
+
(defsetting custom-formatting
(deferred-tru "Object keyed by type, containing formatting settings")
:encryption :no
@@ -348,7 +365,10 @@ See [fonts](../configuring-metabase/fonts.md).")
:export? true
:default {}
:visibility :public
- :audit :getter)
+ :audit :getter
+ :setter (fn [new-value]
+ (validate-custom-formatting! new-value)
+ (setting/set-value-of-type! :json :custom-formatting new-value)))
(defsetting show-homepage-data
(deferred-tru
diff --git a/test/metabase/appearance/settings_test.clj b/test/metabase/appearance/settings_test.clj
index 8bf59f4d860..eb578b1f460 100644
--- a/test/metabase/appearance/settings_test.clj
+++ b/test/metabase/appearance/settings_test.clj
@@ -178,3 +178,15 @@
(is (thrown-with-msg? clojure.lang.ExceptionInfo
#"Loading message set to an unsupported value"
(appearance.settings/loading-message! :unsupported-value))))))
+
+(deftest custom-formatting-number-separators-test
+ (testing "Only valid values can be set as number separators (#61854)"
+ (let [violating-separators ".'"]
+ (is (thrown-with-msg?
+ Exception #"Invalid number separators."
+ (appearance.settings/custom-formatting!
+ #:type{:Temporal {:date_style "MMMM D, YYYY"
+ :time_style "h:mm A"
+ :date_abbreviate false}
+ :Number {:number_separators violating-separators}
+ :Currency {:currency "USD" :currency_style "symbol"}}))))))