The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
uxw-1935: mark settings as set by env var (#64569)
John Swanson392a3ebc4897
diff --git a/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.tsx b/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.tsxindex 76e3dc72ae5..2fd8211442b 100644--- a/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.tsx+++ b/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.tsx@@ -6,10 +6,13 @@ import { Stack } from "metabase/ui";import { trackTrackingPermissionChanged } from "../../analytics";import { SettingHeader } from "../SettingHeader";-import { BasicAdminSettingInput } from "./AdminSettingInput";+import {+ BasicAdminSettingInput,+ SetByEnvVarWrapper,+} from "./AdminSettingInput";export function AnonymousTrackingInput() {- const { value, updateSetting, description } = useAdminSetting(+ const { value, updateSetting, description, settingDetails } = useAdminSetting("anon-tracking-enabled",);@@ -34,12 +37,17 @@ export function AnonymousTrackingInput() {title={t`Anonymous tracking`}description={description}/>- <BasicAdminSettingInput- name="anon-tracking-enabled"- inputType="boolean"- value={value}- onChange={(newValue) => handleChange(Boolean(newValue))}- />+ <SetByEnvVarWrapper+ settingKey="anon-tracking-enabled"+ settingDetails={settingDetails}+ >+ <BasicAdminSettingInput+ name="anon-tracking-enabled"+ inputType="boolean"+ value={value}+ onChange={(newValue) => handleChange(Boolean(newValue))}+ />+ </SetByEnvVarWrapper></Stack>);}diff --git a/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.unit.spec.tsxindex 6d4c01e4378..e705f7ea808 100644--- a/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.unit.spec.tsx+++ b/frontend/src/metabase/admin/settings/components/widgets/AnonymousTrackingInput.unit.spec.tsx@@ -19,7 +19,13 @@ import { AnonymousTrackingInput } from "./AnonymousTrackingInput";const trackingFN = jest.spyOn(analytics, "trackTrackingPermissionChanged");-const setup = ({ value }: { value: boolean }) => {+const setup = ({+ value,+ isEnvSetting,+}: {+ value: boolean;+ isEnvSetting?: boolean;+}) => {const settings = createMockSettings({"anon-tracking-enabled": value,});@@ -31,6 +37,8 @@ const setup = ({ value }: { value: boolean }) => {key: "anon-tracking-enabled",description: "Enable the collection of anonymous usage data",value: false,+ is_env_setting: isEnvSetting,+ env_name: isEnvSetting ? "MB_ANON_TRACKING_ENABLED" : undefined,}),]);@@ -75,4 +83,27 @@ describe("AnonymousTrackingInput", () => {expect(await screen.findByRole("switch")).toBeChecked();});++ it("should show environment variable message when anonymous tracking is set via env var", async () => {+ setup({ value: true, isEnvSetting: true });+ expect(+ await screen.findByText(/This has been set by the/),+ ).toBeInTheDocument();+ expect(+ await screen.findByText("MB_ANON_TRACKING_ENABLED"),+ ).toBeInTheDocument();+ });++ it("should not show the switch when anonymous tracking is set via env var", async () => {+ setup({ value: true, isEnvSetting: true });+ await screen.findByText(/This has been set by the/);++ expect(screen.queryByRole("switch")).not.toBeInTheDocument();+ });++ it("should show the switch when anonymous tracking is not set via env var", async () => {+ setup({ value: true, isEnvSetting: false });++ expect(await screen.findByRole("switch")).toBeInTheDocument();+ });});diff --git a/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.tsx b/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.tsxindex 75718ccc1ab..a1efadb015a 100644--- a/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.tsx+++ b/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.tsx@@ -9,8 +9,10 @@ import { Box, Text } from "metabase/ui";import { SettingHeader } from "../SettingHeader";+import { SetByEnvVarWrapper } from "./AdminSettingInput";+export function SiteUrlWidget() {- const { value, updateSetting, description, isLoading } =+ const { value, updateSetting, description, isLoading, settingDetails } =useAdminSetting("site-url");const isHosted = useHasTokenFeature("hosting");const [errorMessage, setErrorMessage] = useState("");@@ -46,18 +48,20 @@ export function SiteUrlWidget() {</>}/>- <InputWithSelectPrefix- value={value || ""}- onChange={(newValue: string) => handleChange(newValue)}- prefixes={["https://", "http://"]}- defaultPrefix="http://"- placeholder={"http://example.com"}- />- {errorMessage && (- <Text size="sm" color="danger" mt="sm">- {errorMessage}- </Text>- )}+ <SetByEnvVarWrapper settingKey="site-url" settingDetails={settingDetails}>+ <InputWithSelectPrefix+ value={value || ""}+ onChange={(newValue: string) => handleChange(newValue)}+ prefixes={["https://", "http://"]}+ defaultPrefix="http://"+ placeholder={"http://example.com"}+ />+ {errorMessage && (+ <Text size="sm" color="danger" mt="sm">+ {errorMessage}+ </Text>+ )}+ </SetByEnvVarWrapper></Box>);}diff --git a/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.unit.spec.tsx b/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.unit.spec.tsxindex 5d4f334adef..c5dfc13478f 100644--- a/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.unit.spec.tsx+++ b/frontend/src/metabase/admin/settings/components/widgets/SiteUrlWidget.unit.spec.tsx@@ -18,7 +18,7 @@ import { createMockSettingsState } from "metabase-types/store/mocks";import { SiteUrlWidget } from "./SiteUrlWidget";-const setup = (props: { isHosted?: boolean }) => {+const setup = (props: { isHosted?: boolean; isEnvSetting?: boolean }) => {const siteUrlWidgetSettings = {"site-url": "http://mysite.biz","token-features": createMockTokenFeatures({@@ -32,7 +32,13 @@ const setup = (props: { isHosted?: boolean }) => {setupUpdateSettingEndpoint();setupSettingsEndpoints(Object.entries(settings).map(([key, value]) =>- createMockSettingDefinition({ key: key as SettingKey, value }),+ createMockSettingDefinition({+ key: key as SettingKey,+ value,+ is_env_setting: props.isEnvSetting && key === "site-url",+ env_name:+ props.isEnvSetting && key === "site-url" ? "MB_SITE_URL" : undefined,+ }),),);@@ -124,4 +130,33 @@ describe("siteUrlWidget", () => {setup({ isHosted: true });expect(screen.queryByText("Site url")).not.toBeInTheDocument();});++ it("should show environment variable message when site URL is set via env var", async () => {+ setup({ isEnvSetting: true });+ expect(+ await screen.findByText(/This has been set by the/),+ ).toBeInTheDocument();+ expect(await screen.findByText("MB_SITE_URL")).toBeInTheDocument();+ });++ it("should not show the input when site URL is set via env var", async () => {+ setup({ isEnvSetting: true });+ await screen.findByText(/This has been set by the/);++ expect(+ screen.queryByRole("textbox", { name: "input-prefix" }),+ ).not.toBeInTheDocument();+ expect(+ screen.queryByPlaceholderText("http://example.com"),+ ).not.toBeInTheDocument();+ });++ it("should show the input when site URL is not set via env var", async () => {+ setup({ isEnvSetting: false });++ expect(+ await screen.findByRole("textbox", { name: "input-prefix" }),+ ).toBeInTheDocument();+ expect(await screen.findByDisplayValue("mysite.biz")).toBeInTheDocument();+ });});