Skip to content

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

Disable git pull button when there are no changes to pull (#67968)

Anderson95af300c1585
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
index fe7731b42d6..5ec1a1ed83c 100644
--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
@@ -313,7 +313,7 @@ describe("Remote Sync", () => {
name: "You have unsynced changes. What do you want to do?",
});
cy.findByLabelText(
- "Push changes to the current branch, " + NEW_BRANCH,
+ `Push changes to the current branch, ${NEW_BRANCH}`,
);
cy.findByLabelText("Create a new branch and push changes there");
@@ -338,6 +338,12 @@ describe("Remote Sync", () => {
cy.visit("/collection/root");
+ // Ensure that remote is ahead of us so that the pull button is enabled
+ H.updateRemoteQuestion((doc) => {
+ doc.description = "Sloan for Frontend Emperor";
+ return doc;
+ });
+
// Make a change in metabase
H.moveCollectionItemToSyncedCollection("Orders");
@@ -345,10 +351,10 @@ describe("Remote Sync", () => {
H.getPullOption().click();
});
- it("push changes", () => {
+ it("can force push changes", () => {
cy.findByRole("dialog", { name: /unsynced changes/ }).within(() => {
- cy.findByRole("radio", { name: /Push changes/ }).click();
- cy.button("Push changes").click();
+ cy.findByRole("radio", { name: /Force push to main/ }).click();
+ cy.button(/Push changes/).click();
});
H.waitForTask({ taskName: "export" });
@@ -360,12 +366,12 @@ describe("Remote Sync", () => {
});
});
- it("new branch", () => {
+ it("can stash changes to a new branch", () => {
const NEW_BRANCH = `new-branch-${Date.now()}`;
cy.findByRole("dialog", { name: /unsynced changes/ }).within(() => {
cy.findByRole("radio", { name: /new branch/ }).click();
cy.findByPlaceholderText("your-branch-name").type(NEW_BRANCH);
- cy.button("Push changes").click();
+ cy.button(/Push changes/).click();
});
H.waitForTask({ taskName: "export" });
@@ -386,7 +392,7 @@ describe("Remote Sync", () => {
});
});
- it("delete changes", () => {
+ it("can delete/discard changes", () => {
cy.findByRole("dialog", { name: /unsynced changes/ }).within(() => {
cy.findByRole("radio", { name: /Delete/ }).click();
cy.button("Delete unsynced changes").click();
@@ -400,23 +406,6 @@ describe("Remote Sync", () => {
cy.findByText(REMOTE_QUESTION_NAME).should("exist");
});
});
-
- it("upstream changes", () => {
- // Make a change outside metabase
- H.updateRemoteQuestion((doc) => {
- doc.name = "Sloan for Frontend Emperor";
- return doc;
- });
-
- cy.findByRole("dialog", { name: /unsynced changes/ }).within(() => {
- cy.findByRole("radio", { name: /Push/ }).click();
- cy.button("Push changes").click();
- });
-
- cy.findByRole("list", { name: /undo-list/i }).findByText(
- /Cannot export changes/,
- );
- });
});
});
diff --git a/enterprise/frontend/src/metabase-enterprise/api/remote-sync.ts b/enterprise/frontend/src/metabase-enterprise/api/remote-sync.ts
index 2cb38dd3f81..0616c5f59a1 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/remote-sync.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/remote-sync.ts
@@ -3,6 +3,7 @@ import type {
ExportChangesRequest,
ExportChangesResponse,
GetBranchesResponse,
+ HasRemoteChangesResponse,
ImportFromBranchRequest,
ImportFromBranchResponse,
RemoteSyncChangesResponse,
@@ -78,6 +79,13 @@ export const remoteSyncApi = EnterpriseApi.injectEndpoints({
}),
providesTags: () => [tag("collection-is-dirty")],
}),
+ getHasRemoteChanges: builder.query<HasRemoteChangesResponse, void>({
+ query: () => ({
+ url: `/api/ee/remote-sync/has-remote-changes`,
+ method: "GET",
+ }),
+ providesTags: () => [tag("remote-sync-has-remote-changes")],
+ }),
updateRemoteSyncSettings: builder.mutation<
UpdateRemoteSyncConfigurationResponse,
RemoteSyncConfigurationSettings
@@ -138,6 +146,7 @@ export const remoteSyncApi = EnterpriseApi.injectEndpoints({
export const {
useGetRemoteSyncChangesQuery,
useGetRemoteSyncHasChangesQuery,
+ useGetHasRemoteChangesQuery,
useUpdateRemoteSyncSettingsMutation,
useExportChangesMutation,
useGetBranchesQuery,
diff --git a/enterprise/frontend/src/metabase-enterprise/api/tags.ts b/enterprise/frontend/src/metabase-enterprise/api/tags.ts
index 45b1434d3ba..5b71c65482e 100644
--- a/enterprise/frontend/src/metabase-enterprise/api/tags.ts
+++ b/enterprise/frontend/src/metabase-enterprise/api/tags.ts
@@ -50,6 +50,7 @@ export const ENTERPRISE_TAG_TYPES = [
"collection-is-dirty",
"remote-sync-branches",
"remote-sync-current-task",
+ "remote-sync-has-remote-changes",
"python-transform-library",
"support-access-grant",
"support-access-grant-current",
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.tsx
index 1ca6a2e021e..ad49ab9de56 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
@@ -5,7 +5,10 @@ import { t } from "ttag";
import { useToast } from "metabase/common/hooks";
import { Button, Combobox, Icon, Loader, Text, useCombobox } from "metabase/ui";
-import { useImportChangesMutation } from "metabase-enterprise/api";
+import {
+ useGetHasRemoteChangesQuery,
+ useImportChangesMutation,
+} from "metabase-enterprise/api";
import { trackBranchSwitched, trackPullChanges } from "../../analytics";
import { useGitSyncVisible } from "../../hooks/use-git-sync-visible";
@@ -41,8 +44,19 @@ export const GitSyncControls = () => {
const { isDirty, refetch: refetchDirty } = useRemoteSyncDirtyState();
+ const { data: hasRemoteChangesData, isLoading: isFetchingRemoteChanges } =
+ useGetHasRemoteChangesQuery(undefined, {
+ refetchOnMountOrArgChange: 10, // only refetch if the cache is more than 10 seconds stale
+ skip: !combobox.dropdownOpened,
+ });
+ const { has_changes: hasRemoteChanges } = hasRemoteChangesData || {};
+
const isSwitchingBranch = !!nextBranch;
- const isLoading = isSyncTaskRunning || isSwitchingBranch || isImporting;
+ const isLoading =
+ isSyncTaskRunning ||
+ isSwitchingBranch ||
+ isImporting ||
+ isFetchingRemoteChanges;
const changeBranch = useCallback(
async (branch: string | null, isNewBranch?: boolean) => {
@@ -188,6 +202,7 @@ export const GitSyncControls = () => {
{dropdownView === "options" ? (
<GitSyncOptionsDropdown
+ isPullDisabled={!hasRemoteChanges}
isPushDisabled={!isDirty || isLoading}
onPullClick={handlePullClick}
onPushClick={handlePushClick}
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.tsx
index 81d83a6b674..41c06bbe544 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
@@ -15,6 +15,7 @@ import {
const setup = ({
isAdmin = true,
remoteSyncEnabled = true,
+ hasRemoteChanges = true,
currentBranch = "main",
syncType = "read-write",
dirty = [],
@@ -22,12 +23,13 @@ const setup = ({
}: {
isAdmin?: boolean;
remoteSyncEnabled?: boolean;
+ hasRemoteChanges?: boolean;
currentBranch?: string | null;
syncType?: "read-only" | "read-write";
dirty?: ReturnType<typeof createMockDirtyEntity>[];
branches?: string[];
} = {}) => {
- setupRemoteSyncEndpoints({ branches, dirty });
+ setupRemoteSyncEndpoints({ branches, dirty, hasRemoteChanges });
setupCollectionEndpoints();
setupSessionEndpoints({ remoteSyncEnabled, currentBranch, syncType });
@@ -41,7 +43,7 @@ const setup = ({
});
};
-const getOption = (name: RegExp) => screen.getByRole("option", { name });
+const findOption = (name: RegExp) => screen.findByRole("option", { name });
const getBranchButton = (name: RegExp) => screen.getByRole("button", { name });
const queryBranchButton = (name: RegExp) =>
screen.queryByRole("button", { name });
@@ -120,9 +122,9 @@ describe("GitSyncControls", () => {
await userEvent.click(getBranchButton(/main/));
- expect(getOption(/Push changes/)).toBeInTheDocument();
- expect(getOption(/Pull changes/)).toBeInTheDocument();
- expect(getOption(/Switch branch/)).toBeInTheDocument();
+ expect(await findOption(/Push changes/)).toBeInTheDocument();
+ expect(await findOption(/Pull changes/)).toBeInTheDocument();
+ expect(await findOption(/Switch branch/)).toBeInTheDocument();
});
});
@@ -135,7 +137,7 @@ describe("GitSyncControls", () => {
});
await userEvent.click(getBranchButton(/main/));
- expect(getOption(/Push changes/)).toBeEnabled();
+ expect(await findOption(/Push changes/)).toBeEnabled();
});
it("should be disabled and show proper tooltip when there are no changes", async () => {
@@ -145,12 +147,12 @@ describe("GitSyncControls", () => {
expect(getBranchButton(/main/)).toBeInTheDocument();
});
await userEvent.click(getBranchButton(/main/));
- expect(getOption(/Push changes/)).toHaveAttribute(
+ expect(await findOption(/Push changes/)).toHaveAttribute(
"data-combobox-disabled",
"true",
);
- await userEvent.hover(getOption(/Push changes/));
+ await userEvent.hover(await findOption(/Push changes/));
expect(
await screen.findByRole("tooltip", { name: "No changes to push" }),
).toBeInTheDocument();
@@ -163,7 +165,7 @@ describe("GitSyncControls", () => {
expect(getBranchButton(/main/)).toBeInTheDocument();
});
await userEvent.click(getBranchButton(/main/));
- await userEvent.click(getOption(/Push changes/));
+ await userEvent.click(await findOption(/Push changes/));
await waitFor(() => {
expect(screen.getByRole("dialog")).toBeInTheDocument();
@@ -179,7 +181,7 @@ describe("GitSyncControls", () => {
expect(getBranchButton(/main/)).toBeInTheDocument();
});
await userEvent.click(getBranchButton(/main/));
- await userEvent.click(getOption(/Pull changes/));
+ await userEvent.click(await findOption(/Pull changes/));
await waitFor(() => {
expect(
@@ -187,6 +189,32 @@ describe("GitSyncControls", () => {
).toBe(true);
});
});
+
+ it("is enabled when there are changes to pull", async () => {
+ setup({ hasRemoteChanges: true });
+
+ await waitFor(() => {
+ expect(getBranchButton(/main/)).toBeInTheDocument();
+ });
+ await userEvent.click(getBranchButton(/main/));
+ expect(await findOption(/Pull changes/)).not.toHaveAttribute(
+ "data-combobox-disabled",
+ "true",
+ );
+ });
+
+ it("is disabled when there are no changes to pull", async () => {
+ setup({ hasRemoteChanges: false });
+
+ await waitFor(() => {
+ expect(getBranchButton(/main/)).toBeInTheDocument();
+ });
+ await userEvent.click(getBranchButton(/main/));
+ expect(await findOption(/Pull changes/)).toHaveAttribute(
+ "data-combobox-disabled",
+ "true",
+ );
+ });
});
describe("switch branch option", () => {
@@ -197,7 +225,7 @@ describe("GitSyncControls", () => {
expect(getBranchButton(/main/)).toBeInTheDocument();
});
await userEvent.click(getBranchButton(/main/));
- await userEvent.click(getOption(/Switch branch/));
+ await userEvent.click(await findOption(/Switch branch/));
await waitFor(() => {
expect(
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.tsx
index 15650574fd1..aebf506f7e2 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
@@ -3,6 +3,7 @@ import { t } from "ttag";
import { Combobox, Group, Icon, Text, Tooltip } from "metabase/ui";
export interface GitSyncOptionsDropdownProps {
+ isPullDisabled: boolean;
isPushDisabled: boolean;
onPullClick: VoidFunction;
onPushClick: VoidFunction;
@@ -10,10 +11,11 @@ export interface GitSyncOptionsDropdownProps {
}
export const GitSyncOptionsDropdown = ({
+ isPullDisabled,
+ isPushDisabled,
onPullClick,
onPushClick,
onSwitchBranchClick,
- isPushDisabled,
}: GitSyncOptionsDropdownProps) => {
return (
<Combobox.Dropdown p={0}>
@@ -34,12 +36,21 @@ export const GitSyncOptionsDropdown = ({
</Combobox.Option>
</Tooltip>
- <Combobox.Option onClick={onPullClick} py="sm" value="pull">
- <Group gap="md" wrap="nowrap">
- <Icon name="arrow_down" size={12} />
- <Text>{t`Pull changes`}</Text>
- </Group>
- </Combobox.Option>
+ <Tooltip
+ label={isPullDisabled ? t`No changes to pull` : t`Pull from remote`}
+ >
+ <Combobox.Option
+ disabled={isPullDisabled}
+ onClick={onPullClick}
+ py="sm"
+ value="pull"
+ >
+ <Group gap="md" wrap="nowrap">
+ <Icon name="arrow_down" size={12} />
+ <Text>{t`Pull changes`}</Text>
+ </Group>
+ </Combobox.Option>
+ </Tooltip>
<Combobox.Option
onClick={onSwitchBranchClick}
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx
index 7c57c72d2c8..fe75f11a2c2 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/OutOfSyncOptions.tsx
@@ -24,30 +24,29 @@ export const OutOfSyncOptions = (props: BranchSwitchOptionsProps) => {
value: "new-branch",
label: t`Create a new branch and push changes there`,
};
+ const pushOption: OutOfSyncOption = {
+ value: "push",
+ label: c("{0} is the current GitHub branch name")
+ .t`Push changes to the current branch, ${currentBranch}`,
+ };
+ const forcePushOption: OutOfSyncOption = {
+ value: "force-push",
+ label: c("{0} is the current GitHub branch name")
+ .t`Force push to ${currentBranch} (this will overwrite the remote branch)`,
+ };
+ const discardOption: OutOfSyncOption = {
+ value: "discard",
+ label: t`Delete unsynced changes (can’t be undone)`,
+ };
- if (variant === "push") {
- return [
- newBranchOption,
- {
- value: "push",
- label: c("{0} is the current GitHub branch name")
- .t`Force push to ${currentBranch} (this will overwrite the remote branch)`,
- },
- ];
+ switch (variant) {
+ case "push":
+ return [newBranchOption, forcePushOption];
+ case "switch-branch":
+ return [pushOption, newBranchOption, discardOption];
+ default: // pull
+ return [forcePushOption, newBranchOption, discardOption];
}
-
- return [
- {
- value: "push",
- label: c("{0} is the current GitHub branch name")
- .t`Push changes to the current branch, ${currentBranch}`,
- },
- newBranchOption,
- {
- value: "discard",
- label: t`Delete unsynced changes (can’t be undone)`,
- },
- ];
}, [currentBranch, variant]);
return (
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx
index 81b634412c3..bb86cae712d 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/SyncConflictModal.tsx
@@ -40,15 +40,14 @@ export const SyncConflictModal = (props: UnsyncedWarningModalProps) => {
useStashToNewBranchAction(existingBranches);
const { discardChangesAndImport, isImporting } =
useDiscardChangesAndImportAction();
- const isForcingPush = variant === "push" && optionValue === "push";
const handleContinueButtonClick = async () => {
if (!optionValue) {
return;
}
- if (optionValue === "push") {
- await pushChanges(currentBranch, variant === "push", onClose);
+ if (optionValue === "push" || optionValue === "force-push") {
+ await pushChanges(currentBranch, optionValue === "force-push", onClose);
}
if (optionValue === "new-branch") {
@@ -114,12 +113,14 @@ export const SyncConflictModal = (props: UnsyncedWarningModalProps) => {
<Button
color={optionValue === "discard" ? "error" : "brand"}
disabled={isButtonDisabled}
- leftSection={isForcingPush ? <Icon name="warning" /> : undefined}
+ leftSection={
+ optionValue === "force-push" ? <Icon name="warning" /> : undefined
+ }
loading={isProcessing}
onClick={handleContinueButtonClick}
variant="filled"
title={
- isForcingPush
+ optionValue === "force-push"
? t`Force push will replace the remote version with your changes`
: undefined
}
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.ts
index bc104e84fcb..a11e839884f 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/SyncConflictModal/utils.ts
@@ -1,11 +1,12 @@
import { t } from "ttag";
-export type OptionValue = "push" | "new-branch" | "discard";
+export type OptionValue = "push" | "force-push" | "new-branch" | "discard";
export type SyncConflictVariant = "push" | "pull" | "switch-branch";
export const getContinueButtonText = (optionValue?: OptionValue) => {
switch (optionValue) {
case "push":
+ case "force-push":
case "new-branch":
return t`Push changes`;
case "discard":
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/constants.ts b/enterprise/frontend/src/metabase-enterprise/remote_sync/constants.ts
index 3a05269556f..42e1c8cd332 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/constants.ts
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/constants.ts
@@ -27,4 +27,5 @@ export const REMOTE_SYNC_INVALIDATION_TAGS = [
tag("collection-dirty-entities"),
tag("collection-is-dirty"),
tag("remote-sync-current-task"),
+ tag("remote-sync-has-remote-changes"),
];
diff --git a/frontend/src/metabase-types/api/remote-sync.ts b/frontend/src/metabase-types/api/remote-sync.ts
index 85631645f2a..4b05ef7e58a 100644
--- a/frontend/src/metabase-types/api/remote-sync.ts
+++ b/frontend/src/metabase-types/api/remote-sync.ts
@@ -44,6 +44,10 @@ export type RemoteSyncHasChangesResponse = {
is_dirty: boolean;
};
+export type HasRemoteChangesResponse = {
+ has_changes: boolean;
+};
+
export type ExportChangesRequest = {
message?: string;
branch?: string;
diff --git a/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css b/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css
index 40816ae7317..28485366123 100644
--- a/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css
+++ b/frontend/src/metabase/ui/components/overlays/Modal/Modal.module.css
@@ -6,9 +6,9 @@
font-size: var(--mantine-font-size-xl);
font-weight: var(--mantine-heading-font-weight);
line-height: var(--mantine-line-height-md);
- overflow: hidden;
- text-overflow: ellipsis;
- white-space: nowrap;
+ flex: 1 1 auto;
+ min-width: 0;
+ overflow-wrap: break-word;
}
.overlay {
diff --git a/frontend/test/__support__/server-mocks/remote-sync.ts b/frontend/test/__support__/server-mocks/remote-sync.ts
index c22c15cf736..e57b32e75ee 100644
--- a/frontend/test/__support__/server-mocks/remote-sync.ts
+++ b/frontend/test/__support__/server-mocks/remote-sync.ts
@@ -57,10 +57,12 @@ export const setupRemoteSyncEndpoints = ({
branches = ["main", "develop"],
dirty = [],
changedCollections = {},
+ hasRemoteChanges = false,
}: {
branches?: string[];
dirty?: RemoteSyncEntity[];
changedCollections?: Record<number, boolean>;
+ hasRemoteChanges?: boolean;
} = {}) => {
setupRemoteSyncBranchesEndpoint(branches);
setupRemoteSyncDirtyEndpoint({ dirty, changedCollections });
@@ -68,4 +70,7 @@ export const setupRemoteSyncEndpoints = ({
fetchMock.post("path:/api/ee/remote-sync/import", {});
fetchMock.post("path:/api/ee/remote-sync/create-branch", {});
fetchMock.put("path:/api/ee/remote-sync/settings", { success: true });
+ fetchMock.get("path:/api/ee/remote-sync/has-remote-changes", {
+ has_changes: hasRemoteChanges,
+ });
};