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
show error message on remote sync pull changes or branches error (#71668)
Nick Fitzpatrick3b4897a34142
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.tsxindex dae6d045702..78dd1f9a565 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.tsx@@ -39,8 +39,11 @@ export const BranchDropdown = ({}: BranchDropdownProps) => {const [sendToast] = useToast();const [searchValue, setSearchValue] = useState("");- const { data: branchesData, isLoading: branchesLoading } =- useGetBranchesQuery();+ const {+ data: branchesData,+ isLoading: branchesLoading,+ isError: branchesError,+ } = useGetBranchesQuery();const [createBranch, { isLoading: isCreating }] = useCreateBranchMutation();const branches = useMemo(() => branchesData?.items || [], [branchesData]);@@ -118,6 +121,12 @@ export const BranchDropdown = ({<Flex justify="center" align="center" p="xl"><Loader size="sm" /></Flex>+ ) : branchesError ? (+ <Box p="md">+ <Text size="sm" c="error" ta="center">+ {t`Failed to load branches — check your authentication token`}+ </Text>+ </Box>) : (<>{filteredBranches.length === 0 && !showCreateOption ? (diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.unit.spec.tsxindex a858b20eee8..500d137f8c6 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.unit.spec.tsx@@ -67,6 +67,26 @@ describe("BranchDropdown", () => {jest.clearAllMocks();});+ describe("error handling", () => {+ it("should show error message when branches fail to load", async () => {+ const onChange = jest.fn();+ fetchMock.get("path:/api/ee/remote-sync/branches", {+ status: 401,+ body: { message: "Unauthorized" },+ });++ renderWithProviders(+ <WrapperComponent value="main" onChange={onChange} />,+ );++ expect(+ await screen.findByText(+ "Failed to load branches — check your authentication token",+ ),+ ).toBeInTheDocument();+ });+ });+describe("rendering", () => {it("should render search input", async () => {setup();diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsxindex ec16717d0da..785bd1559bb 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.tsx@@ -47,6 +47,7 @@ export const GitSyncControls = () => {const {currentData: hasRemoteChangesData,isFetching: isFetchingRemoteChanges,+ isError: hasRemoteChangesError,} = useGetHasRemoteChangesQuery(undefined, {refetchOnMountOrArgChange: 10, // only refetch if the cache is more than 10 seconds staleskip: !combobox.dropdownOpened,@@ -201,6 +202,7 @@ export const GitSyncControls = () => {{dropdownView === "options" ? (<GitSyncOptionsDropdownisPullDisabled={!hasRemoteChanges}+ isPullError={hasRemoteChangesError}isLoadingPull={isFetchingRemoteChanges}isPushDisabled={!isDirty || isLoading}onPullClick={handlePullClick}diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.unit.spec.tsxindex 196ab2c2e85..4147c5aedfe 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.unit.spec.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.unit.spec.tsx@@ -17,6 +17,7 @@ const setup = ({remoteSyncEnabled = true,hasRemoteChanges = true,hasRemoteChangesDelay = 0,+ hasRemoteChangesError = false,currentBranch = "main",syncType = "read-write",dirty = [],@@ -26,6 +27,7 @@ const setup = ({remoteSyncEnabled?: boolean;hasRemoteChanges?: boolean;hasRemoteChangesDelay?: number;+ hasRemoteChangesError?: boolean;currentBranch?: string | null;syncType?: "read-only" | "read-write";dirty?: ReturnType<typeof createMockDirtyEntity>[];@@ -36,6 +38,7 @@ const setup = ({dirty,hasRemoteChanges,hasRemoteChangesDelay,+ hasRemoteChangesError,});setupCollectionEndpoints();setupSessionEndpoints({ remoteSyncEnabled, currentBranch, syncType });@@ -247,6 +250,20 @@ describe("GitSyncControls", () => {});});+ describe("pull error handling", () => {+ it("shows error message when remote changes check fails", async () => {+ setup({ hasRemoteChangesError: true });++ await userEvent.click(await screen.findByTestId("git-sync-controls"));++ expect(+ await screen.findByText(+ "Failed to check for changes — check your authentication token",+ ),+ ).toBeInTheDocument();+ });+ });+describe("switch branch option", () => {it("should show branch dropdown when switch branch is clicked", async () => {setup({ branches: ["main", "develop", "feature-1"] });diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsxindex c310843604d..0c03583cdbf 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsx@@ -1,9 +1,10 @@import { t } from "ttag";-import { Combobox, Group, Icon, Loader, Text, Tooltip } from "metabase/ui";+import { Box, Combobox, Group, Icon, Loader, Text, Tooltip } from "metabase/ui";export interface GitSyncOptionsDropdownProps {isPullDisabled: boolean;+ isPullError: boolean;isLoadingPull: boolean;isPushDisabled: boolean;onPullClick: VoidFunction;@@ -13,12 +14,25 @@ export interface GitSyncOptionsDropdownProps {export const GitSyncOptionsDropdown = ({isPullDisabled,+ isPullError,isLoadingPull,isPushDisabled,onPullClick,onPushClick,onSwitchBranchClick,}: GitSyncOptionsDropdownProps) => {+ if (isPullError) {+ return (+ <Combobox.Dropdown p={0}>+ <Box p="md">+ <Text size="sm" c="error" ta="center">+ {t`Failed to check for changes — check your authentication token`}+ </Text>+ </Box>+ </Combobox.Dropdown>+ );+ }+return (<Combobox.Dropdown p={0}><Combobox.Options>diff --git a/frontend/test/__support__/server-mocks/remote-sync.ts b/frontend/test/__support__/server-mocks/remote-sync.tsindex fa4bdccc546..888f34e8f28 100644--- a/frontend/test/__support__/server-mocks/remote-sync.ts+++ b/frontend/test/__support__/server-mocks/remote-sync.ts@@ -128,6 +128,7 @@ export const setupRemoteSyncEndpoints = ({changedCollections = {},hasRemoteChanges = false,hasRemoteChangesDelay = 0,+ hasRemoteChangesError = false,settingsResponse = { success: true },}: {branches?: string[];@@ -135,6 +136,7 @@ export const setupRemoteSyncEndpoints = ({changedCollections?: Record<number, boolean>;hasRemoteChanges?: boolean;hasRemoteChangesDelay?: number;+ hasRemoteChangesError?: boolean;settingsResponse?: Partial<RemoteSyncSettingsResponse> & {error?: { status: number; message: string };};@@ -147,9 +149,11 @@ export const setupRemoteSyncEndpoints = ({fetchMock.post("path:/api/ee/remote-sync/create-branch", {});fetchMock.get("path:/api/ee/remote-sync/has-remote-changes",- {- has_changes: hasRemoteChanges,- },+ hasRemoteChangesError+ ? 401+ : {+ has_changes: hasRemoteChanges,+ },{delay: hasRemoteChangesDelay,},