Skip to content

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

Update Remote Sync branch picker to match new designs (#67620)

Andersona5afeea12d55
diff --git a/e2e/support/helpers/e2e-remote-sync-helpers.ts b/e2e/support/helpers/e2e-remote-sync-helpers.ts
index 239f22d2b04..21437ce306e 100644
--- a/e2e/support/helpers/e2e-remote-sync-helpers.ts
+++ b/e2e/support/helpers/e2e-remote-sync-helpers.ts
@@ -1,4 +1,3 @@
-import type { MatcherOptions } from "@testing-library/cypress";
import yaml from "js-yaml";
import type { Collection } from "metabase-types/api";
@@ -125,7 +124,7 @@ export const updateRemoteQuestion = (
const fullPath = `${LOCAL_GIT_PATH}/${questionFilePath}`;
cy.readFile(fullPath).then((str) => {
- const doc = yaml.load(str);
+ const doc = yaml.load(str) as Record<string, unknown>;
assertionsFn?.(doc);
@@ -167,15 +166,28 @@ export const goToSyncedCollection = (opts?: Partial<Cypress.ClickOptions>) =>
// Git sync controls are now in the app bar, not the sidebar
export const getGitSyncControls = () => cy.findByTestId("git-sync-controls");
-export const getPullButton = () =>
- getGitSyncControls().findByTestId("git-pull-button");
+const ensureGitSyncMenuOpen = () => {
+ getGitSyncControls().then(($btn) => {
+ if ($btn.attr("data-expanded") !== "true") {
+ cy.wrap($btn).click();
+ }
+ });
+};
-export const getPushButton = () =>
- getGitSyncControls().findByTestId("git-push-button");
+export const getPullOption = () => {
+ ensureGitSyncMenuOpen();
+ return popover().findByRole("option", { name: /Pull changes/ });
+};
-// Branch picker is now in the app bar (git-sync-controls), not the sidebar
-export const branchPicker = (opts?: Partial<MatcherOptions>) =>
- getGitSyncControls().findByTestId("branch-picker-button", opts);
+export const getPushOption = () => {
+ ensureGitSyncMenuOpen();
+ return popover().findByRole("option", { name: /Push changes/ });
+};
+
+export const getSwitchBranchOption = () => {
+ ensureGitSyncMenuOpen();
+ return popover().findByRole("option", { name: /Switch branch/ });
+};
// Enable tenants feature for testing
export const enableTenants = () => {
@@ -202,10 +214,10 @@ export const waitForTask = (
throw Error(`Too many retries waiting for ${taskName}`);
}
cy.wait("@currentTask").then(({ response }) => {
- const { body } = response;
- if (body.sync_task_type !== taskName) {
+ const { body } = response || {};
+ if (body?.sync_task_type !== taskName) {
waitForTask({ taskName });
- } else if (body.status !== "successful") {
+ } else if (body?.status !== "successful") {
waitForTask({ taskName }, retries + 1);
}
});
diff --git a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
index 7a5fe8e3e50..fe7731b42d6 100644
--- a/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
+++ b/e2e/test/scenarios/admin/remote-sync.cy.spec.ts
@@ -51,7 +51,7 @@ describe("Remote Sync", () => {
H.collectionTable().findByText(REMOTE_QUESTION_NAME).should("exist");
- H.getPushButton().click();
+ H.getPushOption().click();
H.modal()
.button(/Push changes/)
@@ -78,7 +78,7 @@ describe("Remote Sync", () => {
},
);
- H.getPullButton().click();
+ H.getPullOption().click();
H.waitForTask({ taskName: "import" });
H.expectUnstructuredSnowplowEvent({
@@ -149,7 +149,7 @@ describe("Remote Sync", () => {
return doc;
});
- H.getPushButton().click();
+ H.getPushOption().click();
// Attempt to push changes
cy.findByRole("dialog", { name: "Push to Git" })
@@ -166,7 +166,7 @@ describe("Remote Sync", () => {
H.waitForTask({ taskName: "export" });
// Ensure that we are on the newly created branch
- H.branchPicker().should("contain.text", NEW_BRANCH);
+ H.getGitSyncControls().should("contain.text", NEW_BRANCH);
H.goToSyncedCollection();
H.collectionTable().within(() => {
@@ -176,7 +176,7 @@ describe("Remote Sync", () => {
cy.findByText("Remote Sync Test Question");
});
- H.branchPicker().click();
+ H.getSwitchBranchOption().click();
H.popover().findByRole("option", { name: "main" }).click();
H.waitForTask({ taskName: "import" });
@@ -196,7 +196,7 @@ describe("Remote Sync", () => {
const createNewBranch = (newBranchName: string) => {
branchCount++;
- H.branchPicker().click();
+ H.getSwitchBranchOption().click();
H.popover()
.findByPlaceholderText("Find or create a branch...")
.type(newBranchName);
@@ -212,11 +212,11 @@ describe("Remote Sync", () => {
branchCount,
);
- H.branchPicker().should("contain.text", newBranchName);
+ H.getGitSyncControls().should("contain.text", newBranchName);
};
const switchToExistingBranch = (branch: string) => {
- H.branchPicker().click();
+ H.getSwitchBranchOption().click();
H.popover()
.findByPlaceholderText("Find or create a branch...")
.type(branch);
@@ -224,7 +224,7 @@ describe("Remote Sync", () => {
};
const pushUpdates = () => {
- H.getPushButton().click();
+ H.getPushOption().click();
H.modal()
.button(/Push changes/)
@@ -232,7 +232,7 @@ describe("Remote Sync", () => {
H.waitForTask({ taskName: "export" });
// Push button should be disabled when local changes are synced
- H.getPushButton().should("be.disabled");
+ H.getPushOption().should("have.attr", "data-combobox-disabled", "true");
};
it("should allow you to create new branches and switch between them", () => {
@@ -305,7 +305,7 @@ describe("Remote Sync", () => {
switchToExistingBranch("main");
// Check that we haven't switched to main
- H.branchPicker().should("not.contain.text", "main");
+ H.getGitSyncControls().should("not.contain.text", "main");
H.modal().should("exist");
H.modal().within(() => {
@@ -325,7 +325,7 @@ describe("Remote Sync", () => {
});
// Now we switched to main
- H.branchPicker().should("contain.text", "main");
+ H.getGitSyncControls().should("contain.text", "main");
});
});
@@ -342,7 +342,7 @@ describe("Remote Sync", () => {
H.moveCollectionItemToSyncedCollection("Orders");
H.goToSyncedCollection();
- H.getPullButton().click();
+ H.getPullOption().click();
});
it("push changes", () => {
@@ -353,7 +353,7 @@ describe("Remote Sync", () => {
H.waitForTask({ taskName: "export" });
- H.branchPicker().should("contain.text", "main");
+ H.getGitSyncControls().should("contain.text", "main");
H.collectionTable().within(() => {
cy.findByText("Orders").should("exist");
cy.findByText(REMOTE_QUESTION_NAME).should("exist");
@@ -370,13 +370,13 @@ describe("Remote Sync", () => {
H.waitForTask({ taskName: "export" });
- H.branchPicker().should("contain.text", NEW_BRANCH);
+ H.getGitSyncControls().should("contain.text", NEW_BRANCH);
H.collectionTable().within(() => {
cy.findByText("Orders").should("exist");
cy.findByText(REMOTE_QUESTION_NAME).should("exist");
});
- H.branchPicker().click();
+ H.getSwitchBranchOption().click();
H.popover().findByRole("option", { name: "main" }).click();
H.waitForTask({ taskName: "import" });
@@ -394,7 +394,7 @@ describe("Remote Sync", () => {
H.waitForTask({ taskName: "import" });
- H.branchPicker().should("contain.text", "main");
+ H.getGitSyncControls().should("contain.text", "main");
H.collectionTable().within(() => {
cy.findByText("Orders").should("not.exist");
cy.findByText(REMOTE_QUESTION_NAME).should("exist");
@@ -452,7 +452,7 @@ describe("Remote Sync", () => {
cy.findByTestId("exit-admin").click();
// Branch picker is now in the app bar
- H.branchPicker().should("contain.text", "main");
+ H.getGitSyncControls().should("contain.text", "main");
// Synced collection appears in regular collections list (no separate heading)
H.navigationSidebar().within(() => {
@@ -810,7 +810,7 @@ describe("Remote Sync", () => {
H.getSyncStatusIndicators().should("have.length.greaterThan", 0);
// Push changes
- H.getPushButton().click();
+ H.getPushOption().click();
H.modal()
.button(/Push changes/)
.click();
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
index 2c9fcb21ed9..9f3f0cc1d92 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/app/pages/DataStudioLayout/DataStudioLayout.tsx
@@ -19,6 +19,7 @@ import {
Center,
FixedSizeIcon,
Flex,
+ Group,
type IconName,
Loader,
Stack,
@@ -93,9 +94,6 @@ function DataStudioNav({ isNavbarOpened, onNavbarToggle }: DataStudioNavProps) {
isNavbarOpened={isNavbarOpened}
onNavbarToggle={onNavbarToggle}
/>
- {isNavbarOpened && (
- <PLUGIN_REMOTE_SYNC.GitSyncAppBarControls fullWidth />
- )}
<DataStudioTab
label={t`Library`}
icon="repository"
@@ -244,22 +242,29 @@ function DataStudioNavbarToggle({
}: DataStudioNavbarToggleProps) {
return (
<Flex justify="space-between" mb={2}>
- <UnstyledButton
- className={cx(S.toggle, {
- [S.hoverButton]: !isNavbarOpened,
- [S.disablePointer]: isNavbarOpened,
- })}
- p="0.5rem"
- bdrs="md"
- onClick={() => !isNavbarOpened && onNavbarToggle(true)}
- >
- <img src={DataStudioLogo} className={cx(S.hideOnHover, S.logo)} />
- <FixedSizeIcon
- name="sidebar_open"
- className={S.showOnHover}
- c="text-secondary"
- />
- </UnstyledButton>
+ <Group gap="sm">
+ <UnstyledButton
+ className={cx(S.toggle, {
+ [S.hoverButton]: !isNavbarOpened,
+ [S.disablePointer]: isNavbarOpened,
+ })}
+ p="0.5rem"
+ bdrs="md"
+ onClick={() => !isNavbarOpened && onNavbarToggle(true)}
+ >
+ <img
+ alt="Data Studio Logo"
+ className={cx(S.hideOnHover, S.logo)}
+ src={DataStudioLogo}
+ />
+ <FixedSizeIcon
+ name="sidebar_open"
+ className={S.showOnHover}
+ c="text-secondary"
+ />
+ </UnstyledButton>
+ {isNavbarOpened && <PLUGIN_REMOTE_SYNC.GitSyncAppBarControls />}
+ </Group>
{isNavbarOpened && (
<UnstyledButton
className={S.toggle}
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.tsx
new file mode 100644
index 00000000000..aab583b2f7b
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.tsx
@@ -0,0 +1,186 @@
+import { useEffect, useMemo, useState } from "react";
+import { t } from "ttag";
+
+import { useToast } from "metabase/common/hooks";
+import {
+ Box,
+ Combobox,
+ type ComboboxStore,
+ Divider,
+ Flex,
+ Group,
+ Icon,
+ Loader,
+ ScrollArea,
+ Text,
+ TextInput,
+} from "metabase/ui";
+import {
+ useCreateBranchMutation,
+ useGetBranchesQuery,
+} from "metabase-enterprise/api";
+
+import { trackBranchCreated } from "../../analytics";
+
+export interface BranchDropdownProps {
+ allowCreate?: boolean;
+ baseBranch?: string;
+ combobox: ComboboxStore;
+ onChange: (branch: string, isNewBranch?: boolean) => void;
+ value: string;
+}
+
+export const BranchDropdown = ({
+ value,
+ onChange,
+ baseBranch = "main",
+ allowCreate = true,
+ combobox,
+}: BranchDropdownProps) => {
+ const [sendToast] = useToast();
+ const [searchValue, setSearchValue] = useState("");
+ const { data: branchesData, isLoading: branchesLoading } =
+ useGetBranchesQuery();
+ const [createBranch, { isLoading: isCreating }] = useCreateBranchMutation();
+
+ const branches = useMemo(() => branchesData?.items || [], [branchesData]);
+
+ const filteredBranches = useMemo(() => {
+ const availableBranches = branches.filter((branch) => branch !== value);
+
+ if (!searchValue) {
+ return availableBranches;
+ }
+ const search = searchValue.toLowerCase();
+ return availableBranches
+ .filter((branch) => branch.toLowerCase().includes(search))
+ .slice(0, 5);
+ }, [branches, searchValue, value]);
+
+ const exactMatch = branches.some(
+ (branch) => branch.toLowerCase() === searchValue.toLowerCase(),
+ );
+
+ const showCreateOption =
+ allowCreate && searchValue && !exactMatch && !isCreating;
+
+ const handleBranchSelect = (branch: string, isNewBranch = false) => {
+ onChange(branch, isNewBranch);
+ setSearchValue("");
+ combobox.closeDropdown();
+ };
+
+ const handleCreateBranch = async () => {
+ combobox.closeDropdown();
+ const branchName = searchValue;
+ setSearchValue("");
+
+ try {
+ await createBranch({
+ name: branchName,
+ }).unwrap();
+
+ trackBranchCreated({
+ triggeredFrom: "branch-picker",
+ });
+
+ onChange(branchName, true);
+ } catch {
+ sendToast({
+ message: t`Failed to create branch`,
+ icon: "warning",
+ });
+ }
+ };
+
+ useEffect(() => {
+ if (!combobox.dropdownOpened) {
+ setSearchValue("");
+ }
+ }, [combobox.dropdownOpened]);
+
+ return (
+ <Combobox.Dropdown p={0}>
+ <Box p="sm">
+ <TextInput
+ autoFocus
+ leftSection={<Icon name="search" size={16} />}
+ onChange={(e) => setSearchValue(e.currentTarget.value)}
+ placeholder={t`Find or create a branch...`}
+ value={searchValue}
+ />
+ </Box>
+
+ <Divider />
+
+ <ScrollArea.Autosize mah={320} type="hover">
+ {branchesLoading || isCreating ? (
+ <Flex justify="center" align="center" p="xl">
+ <Loader size="sm" />
+ </Flex>
+ ) : (
+ <>
+ {filteredBranches.length === 0 && !showCreateOption ? (
+ <Box p="md">
+ <Text size="sm" c="text-light" ta="center">
+ {searchValue
+ ? t`No branches found`
+ : t`No branches available`}
+ </Text>
+ </Box>
+ ) : (
+ <>
+ {filteredBranches.length > 0 && (
+ <>
+ <Combobox.Options>
+ <Box px="sm" py="sm">
+ <Text size="xs" c="text-light" tt="uppercase" fw="bold">
+ {t`Branches`}
+ </Text>
+ </Box>
+ {filteredBranches.map((branch) => (
+ <Combobox.Option
+ key={branch}
+ value={branch}
+ onClick={() => handleBranchSelect(branch)}
+ data-testid={`branch-item-${branch}`}
+ py="sm"
+ >
+ <Group gap="xs" wrap="nowrap">
+ <Text>{branch}</Text>
+ </Group>
+ </Combobox.Option>
+ ))}
+ </Combobox.Options>
+ {showCreateOption && <Divider />}
+ </>
+ )}
+
+ {showCreateOption && (
+ <Box p="sm">
+ <Combobox.Option
+ py="sm"
+ value="__create__"
+ onClick={handleCreateBranch}
+ data-testid="create-branch-button"
+ >
+ <Group gap="xs" wrap="nowrap">
+ <Icon name="add" size={16} />
+ <Box>
+ <Text lh="md">{t`Create branch "${searchValue}"`}</Text>
+ <Text size="xs" c="text-light">
+ {t`from ${baseBranch || value}`}
+ </Text>
+ </Box>
+ </Group>
+ </Combobox.Option>
+ </Box>
+ )}
+ </>
+ )}
+ </>
+ )}
+ </ScrollArea.Autosize>
+ </Combobox.Dropdown>
+ );
+};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchPicker.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.unit.spec.tsx
similarity index 69%
rename from enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchPicker.unit.spec.tsx
rename to enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.unit.spec.tsx
index b74c56126bf..5c60a8c2afd 100644
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchPicker.unit.spec.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchDropdown.unit.spec.tsx
@@ -2,17 +2,35 @@ import userEvent from "@testing-library/user-event";
import fetchMock from "fetch-mock";
import { renderWithProviders, screen, waitFor } from "__support__/ui";
-
-import { BranchPicker } from "./BranchPicker";
-
-const defaultProps = {
- value: "main",
- onChange: jest.fn(),
- disabled: false,
- isLoading: false,
- baseBranch: "main",
- allowCreate: true,
-};
+import { Combobox, useCombobox } from "metabase/ui";
+
+import { BranchDropdown } from "./BranchDropdown";
+
+function WrapperComponent({
+ value,
+ onChange,
+ baseBranch = "main",
+ allowCreate = true,
+}: {
+ value: string;
+ onChange: (branch: string, isNewBranch?: boolean) => void;
+ baseBranch?: string;
+ allowCreate?: boolean;
+}) {
+ const combobox = useCombobox({ opened: true });
+
+ return (
+ <Combobox store={combobox} withinPortal={false}>
+ <BranchDropdown
+ value={value}
+ onChange={onChange}
+ baseBranch={baseBranch}
+ allowCreate={allowCreate}
+ combobox={combobox}
+ />
+ </Combobox>
+ );
+}
const setupEndpoints = () => {
fetchMock.get("path:/api/ee/remote-sync/branches", {
@@ -21,57 +39,39 @@ const setupEndpoints = () => {
fetchMock.post("path:/api/ee/remote-sync/create-branch", {});
};
-const setup = (props: Partial<typeof defaultProps> = {}) => {
+const setup = (
+ props: Partial<{
+ value: string;
+ baseBranch: string;
+ allowCreate: boolean;
+ }> = {},
+) => {
const onChange = jest.fn();
- const mergedProps = { ...defaultProps, onChange, ...props };
+ const mergedProps = {
+ value: "main",
+ baseBranch: "main",
+ allowCreate: true,
+ ...props,
+ };
setupEndpoints();
- renderWithProviders(<BranchPicker {...mergedProps} />);
+ renderWithProviders(
+ <WrapperComponent {...mergedProps} onChange={onChange} />,
+ );
return { onChange };
};
-describe("BranchPicker", () => {
+describe("BranchDropdown", () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe("rendering", () => {
- it("should render button with current branch name", () => {
- setup({ value: "main" });
-
- expect(screen.getByTestId("branch-picker-button")).toBeInTheDocument();
- expect(screen.getByText("main")).toBeInTheDocument();
- });
-
- it("should render with different branch name", () => {
- setup({ value: "feature-branch" });
-
- expect(screen.getByText("feature-branch")).toBeInTheDocument();
- });
- });
-
- describe("disabled state", () => {
- it("should disable button when disabled prop is true", () => {
- setup({ disabled: true });
-
- expect(screen.getByTestId("branch-picker-button")).toBeDisabled();
- });
-
- it("should disable button when isLoading is true", () => {
- setup({ isLoading: true });
-
- expect(screen.getByTestId("branch-picker-button")).toBeDisabled();
- });
- });
-
- describe("dropdown behavior", () => {
- it("should open dropdown when button is clicked", async () => {
+ it("should render search input", async () => {
setup();
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
expect(
screen.getByPlaceholderText("Find or create a branch..."),
@@ -82,22 +82,18 @@ describe("BranchPicker", () => {
it("should show available branches in dropdown", async () => {
setup({ value: "main" });
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
- // Other branches should be visible
expect(screen.getByTestId("branch-item-develop")).toBeInTheDocument();
});
- // Current branch (main) should not be in the list
expect(screen.queryByTestId("branch-item-main")).not.toBeInTheDocument();
expect(screen.getByTestId("branch-item-feature-1")).toBeInTheDocument();
});
+ });
+ describe("search filtering", () => {
it("should filter branches based on search input", async () => {
setup({ value: "main" });
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
expect(screen.getByTestId("branch-item-develop")).toBeInTheDocument();
});
@@ -114,14 +110,46 @@ describe("BranchPicker", () => {
screen.queryByTestId("branch-item-develop"),
).not.toBeInTheDocument();
});
+
+ it("should show create option when search has no results and allowCreate is true", async () => {
+ setup({ value: "main", allowCreate: true });
+
+ await waitFor(() => {
+ expect(screen.getByTestId("branch-item-develop")).toBeInTheDocument();
+ });
+
+ await userEvent.type(
+ screen.getByPlaceholderText("Find or create a branch..."),
+ "nonexistent",
+ );
+
+ await waitFor(() => {
+ expect(screen.getByTestId("create-branch-button")).toBeInTheDocument();
+ });
+ });
+
+ it("should show no branches message when search has no results and allowCreate is false", async () => {
+ setup({ value: "main", allowCreate: false });
+
+ await waitFor(() => {
+ expect(screen.getByTestId("branch-item-develop")).toBeInTheDocument();
+ });
+
+ await userEvent.type(
+ screen.getByPlaceholderText("Find or create a branch..."),
+ "nonexistent",
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText("No branches found")).toBeInTheDocument();
+ });
+ });
});
describe("branch selection", () => {
it("should call onChange with branch name when branch is selected", async () => {
const { onChange } = setup({ value: "main" });
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
expect(screen.getByTestId("branch-item-develop")).toBeInTheDocument();
});
@@ -136,8 +164,6 @@ describe("BranchPicker", () => {
it("should show create option when search does not match existing branches", async () => {
setup({ value: "main" });
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
expect(
screen.getByPlaceholderText("Find or create a branch..."),
@@ -160,8 +186,6 @@ describe("BranchPicker", () => {
it("should not show create option when allowCreate is false", async () => {
setup({ value: "main", allowCreate: false });
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
expect(
screen.getByPlaceholderText("Find or create a branch..."),
@@ -183,8 +207,6 @@ describe("BranchPicker", () => {
it("should not show create option when search matches existing branch", async () => {
setup({ value: "main" });
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
expect(
screen.getByPlaceholderText("Find or create a branch..."),
@@ -206,8 +228,6 @@ describe("BranchPicker", () => {
it("should call createBranch mutation and onChange when create option is clicked", async () => {
const { onChange } = setup({ value: "main" });
- await userEvent.click(screen.getByTestId("branch-picker-button"));
-
await waitFor(() => {
expect(
screen.getByPlaceholderText("Find or create a branch..."),
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchPicker.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchPicker.tsx
deleted file mode 100644
index 394dc3ead14..00000000000
--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/BranchPicker.tsx
+++ /dev/null
@@ -1,239 +0,0 @@
-import { useEffect, useMemo, useState } from "react";
-import { t } from "ttag";
-
-import { useToast } from "metabase/common/hooks";
-import {
- Box,
- Button,
- Combobox,
- Divider,
- Flex,
- Group,
- Icon,
- Loader,
- ScrollArea,
- Text,
- TextInput,
- useCombobox,
-} from "metabase/ui";
-import {
- useCreateBranchMutation,
- useGetBranchesQuery,
-} from "metabase-enterprise/api";
-
-import { trackBranchCreated } from "../../analytics";
-
-export interface BranchPickerProps {
- value: string;
- onChange: (branch: string, isNewBranch?: boolean) => void;
- disabled?: boolean;
- isLoading?: boolean;
- baseBranch?: string;
- allowCreate?: boolean;
-}
-
-export const BranchPicker = ({
- value,
- onChange,
- disabled = false,
- isLoading = false,
- baseBranch = "main",
- allowCreate = true,
-}: BranchPickerProps) => {
- const [sendToast] = useToast();
- const combobox = useCombobox();
- const [searchValue, setSearchValue] = useState("");
- const { data: branchesData, isLoading: branchesLoading } =
- useGetBranchesQuery();
- const [createBranch, { isLoading: isCreating }] = useCreateBranchMutation();
-
- const branches = useMemo(() => branchesData?.items || [], [branchesData]);
-
- const filteredBranches = useMemo(() => {
- const availableBranches = branches.filter((branch) => branch !== value);
-
- if (!searchValue) {
- return availableBranches;
- }
- const search = searchValue.toLowerCase();
- return availableBranches
- .filter((branch) => branch.toLowerCase().includes(search))
- .slice(0, 5);
- }, [branches, searchValue, value]);
-
- const exactMatch = branches.some(
- (branch) => branch.toLowerCase() === searchValue.toLowerCase(),
- );
-
- const showCreateOption =
- allowCreate && searchValue && !exactMatch && !isCreating;
-
- const handleBranchSelect = (branch: string, isNewBranch = false) => {
- onChange(branch, isNewBranch);
- setSearchValue("");
- combobox.closeDropdown();
- };
-
- const handleCreateBranch = async () => {
- combobox.closeDropdown();
- const branchName = searchValue;
- setSearchValue("");
-
- try {
- await createBranch({
- name: branchName,
- }).unwrap();
-
- trackBranchCreated({
- triggeredFrom: "branch-picker",
- });
-
- onChange(branchName, true);
- } catch (error) {
- sendToast({
- message: t`Failed to create branch`,
- icon: "warning",
- });
- }
- };
-
- useEffect(() => {
- if (!combobox.dropdownOpened) {
- setSearchValue("");
- }
- }, [combobox.dropdownOpened]);
-
- return (
- <Combobox
- store={combobox}
- withinPortal
- width={280}
- position="bottom-start"
- disabled={disabled || isLoading || isCreating}
- >
- <Combobox.Target>
- <Button
- px="0.5rem"
- py="1rem"
- size="compact-sm"
- variant="default"
- justify="left"
- flex={1}
- disabled={disabled || isLoading || isCreating}
- onClick={() => combobox.toggleDropdown()}
- leftSection={<Icon name="git_branch" c="text-medium" size={14} />}
- rightSection={
- isLoading || isCreating ? (
- <Loader size="xs" />
- ) : (
- <Icon
- name="chevrondown"
- c="text-medium"
- size={12}
- style={{
- transform: combobox.dropdownOpened
- ? "rotate(180deg)"
- : "rotate(0deg)",
- transition: "transform 200ms ease",
- }}
- />
- )
- }
- data-testid="branch-picker-button"
- >
- <Text fw="bold" c="text-medium" size="sm" lh="md" truncate>
- {value}
- </Text>
- </Button>
- </Combobox.Target>
-
- <Combobox.Dropdown p={0}>
- <Box p="sm">
- <TextInput
- placeholder={t`Find or create a branch...`}
- value={searchValue}
- onChange={(e) => setSearchValue(e.currentTarget.value)}
- leftSection={<Icon name="search" size={16} />}
- data-autofocus
- />
- </Box>
-
- <Divider />
-
- <ScrollArea.Autosize mah={320} type="hover">
- {branchesLoading || isCreating ? (
- <Flex justify="center" align="center" p="xl">
- <Loader size="sm" />
- </Flex>
- ) : (
- <>
- {filteredBranches.length === 0 && !showCreateOption ? (
- <Box p="md">
- <Text size="sm" c="text-light" ta="center">
- {searchValue
- ? t`No branches found`
- : t`No branches available`}
- </Text>
- </Box>
- ) : (
- <>
- {filteredBranches.length > 0 && (
- <>
- <Combobox.Options>
- <Box px="sm" py="sm">
- <Text
- size="xs"
- c="text-light"
- tt="uppercase"
- fw="bold"
- >
- {t`Branches`}
- </Text>
- </Box>
- {filteredBranches.map((branch) => (
- <Combobox.Option
- key={branch}
- value={branch}
- onClick={() => handleBranchSelect(branch)}
- data-testid={`branch-item-${branch}`}
- py="sm"
- >
- <Group gap="xs" wrap="nowrap">
- <Text>{branch}</Text>
- </Group>
- </Combobox.Option>
- ))}
- </Combobox.Options>
- {showCreateOption && <Divider />}
- </>
- )}
-
- {showCreateOption && (
- <Box p="sm">
- <Combobox.Option
- py="sm"
- value="__create__"
- onClick={handleCreateBranch}
- data-testid="create-branch-button"
- >
- <Group gap="xs" wrap="nowrap">
- <Icon name="add" size={16} />
- <Box>
- <Text lh="md">{t`Create branch "${searchValue}"`}</Text>
- <Text size="xs" c="text-light">
- {t`from ${baseBranch || value}`}
- </Text>
- </Box>
- </Group>
- </Combobox.Option>
- </Box>
- )}
- </>
- )}
- </>
- )}
- </ScrollArea.Autosize>
- </Combobox.Dropdown>
- </Combobox>
- );
-};
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.module.css b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.module.css
new file mode 100644
index 00000000000..c67132bb2ec
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncControls.module.css
@@ -0,0 +1,7 @@
+.chevronIcon {
+ transition: transform 200ms ease;
+
+ &.opened {
+ transform: rotate(180deg);
+ }
+}
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 dd8e4eba5bb..06dddb79547 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
@@ -1,8 +1,10 @@
+import { useDisclosure } from "@mantine/hooks";
+import cx from "classnames";
import { useCallback, useState } from "react";
import { t } from "ttag";
import { useToast } from "metabase/common/hooks";
-import { Button, Icon, Loader, Tooltip } from "metabase/ui";
+import { Button, Combobox, Icon, Loader, Text, useCombobox } from "metabase/ui";
import { useImportChangesMutation } from "metabase-enterprise/api";
import { trackBranchSwitched, trackPullChanges } from "../../analytics";
@@ -16,15 +18,13 @@ import {
type SyncConflictVariant,
} from "../SyncConflictModal";
-import { BranchPicker } from "./BranchPicker";
+import { BranchDropdown } from "./BranchDropdown";
+import S from "./GitSyncControls.module.css";
+import { GitSyncOptionsDropdown } from "./GitSyncOptionsDropdown";
-interface GitSyncControlsProps {
- fullWidth?: boolean;
-}
+type DropdownView = "options" | "branch";
-export const GitSyncControls = ({
- fullWidth = false,
-}: GitSyncControlsProps) => {
+export const GitSyncControls = () => {
const { isVisible, currentBranch } = useGitSyncVisible();
const [importChanges, { isLoading: isImporting }] =
@@ -34,8 +34,10 @@ export const GitSyncControls = ({
const { isRunning: isSyncTaskRunning } = useSyncStatus();
const [nextBranch, setNextBranch] = useState<string | null>(null);
- const [showPushModal, setShowPushModal] = useState(false);
+ const [showPushModal, { toggle: togglePushModal }] = useDisclosure(false);
const [sendToast] = useToast();
+ const [dropdownView, setDropdownView] = useState<DropdownView>("options");
+ const combobox = useCombobox();
const { isDirty, refetch: refetchDirty } = useRemoteSyncDirtyState();
@@ -92,6 +94,11 @@ export const GitSyncControls = ({
[currentBranch, changeBranch, refetchDirty, sendToast],
);
+ const handlePushClick = useCallback(() => {
+ togglePushModal();
+ combobox.closeDropdown();
+ }, [combobox, togglePushModal]);
+
const handlePullClick = useCallback(async () => {
if (!currentBranch) {
return;
@@ -104,11 +111,6 @@ export const GitSyncControls = ({
triggeredFrom: "app-bar",
force: false,
});
-
- sendToast({
- message: t`Your branch is now up to date with remote`,
- icon: "check",
- });
} catch (error) {
const { hasConflict, errorMessage } = parseSyncError(error as SyncError);
@@ -122,78 +124,87 @@ export const GitSyncControls = ({
icon: "warning",
});
}
- }, [currentBranch, importChanges, sendToast]);
-
- const handlePushClick = useCallback(() => {
- setShowPushModal(true);
- }, []);
- const handleClosePushModal = useCallback(() => {
- setShowPushModal(false);
- }, []);
+ combobox.closeDropdown();
+ }, [combobox, currentBranch, importChanges, sendToast]);
const handleCloseSyncConflictModal = useCallback(() => {
setSyncConflictVariant(undefined);
setNextBranch(null);
}, []);
+ const handleSwitchBranchClick = useCallback(() => {
+ setDropdownView("branch");
+ }, []);
+
if (!isVisible || !currentBranch) {
return null;
}
return (
<>
- <Button.Group
- data-testid="git-sync-controls"
- mr={fullWidth ? undefined : "2rem"}
- w={fullWidth ? "100%" : "13.5rem"}
+ <Combobox
+ disabled={isLoading}
+ position="bottom-start"
+ store={combobox}
+ width={280}
+ withinPortal
>
- <BranchPicker
- isLoading={isLoading}
- value={currentBranch}
- onChange={handleBranchSelect}
- baseBranch={currentBranch}
- />
-
- <Tooltip label={t`Pull from Git`}>
+ <Combobox.Target>
<Button
- variant="default"
+ p="sm"
size="compact-sm"
- px="0.5rem"
- py="1rem"
- onClick={handlePullClick}
+ bd="none"
+ mr="lg"
disabled={isLoading}
- aria-label={t`Pull from Git`}
- data-testid="git-pull-button"
- leftSection={
- isImporting ? (
+ onClick={() => {
+ setDropdownView("options");
+ combobox.toggleDropdown();
+ }}
+ leftSection={<Icon name="git_branch" c="text-medium" size={14} />}
+ rightSection={
+ isLoading ? (
<Loader size="xs" />
) : (
- <Icon name="arrow_down" size={16} />
+ <Icon
+ name="chevrondown"
+ c="text-medium"
+ size={8}
+ className={cx(S.chevronIcon, {
+ [S.opened]: combobox.dropdownOpened,
+ })}
+ />
)
}
+ data-testid="git-sync-controls"
+ >
+ <Text fw="bold" c="text-medium" size="sm" lh="md" truncate>
+ {currentBranch}
+ </Text>
+ </Button>
+ </Combobox.Target>
+
+ {dropdownView === "options" ? (
+ <GitSyncOptionsDropdown
+ isPushDisabled={!isDirty || isLoading}
+ onPullClick={handlePullClick}
+ onPushClick={handlePushClick}
+ onSwitchBranchClick={handleSwitchBranchClick}
/>
- </Tooltip>
-
- <Tooltip label={isDirty ? t`Push to Git` : t`No changes to push`}>
- <Button
- variant="default"
- size="compact-sm"
- px="0.5rem"
- py="1rem"
- onClick={handlePushClick}
- disabled={isLoading || !isDirty}
- aria-label={t`Push to Git`}
- data-testid="git-push-button"
- leftSection={<Icon name="arrow_up" size={16} />}
+ ) : (
+ <BranchDropdown
+ baseBranch={currentBranch}
+ combobox={combobox}
+ onChange={handleBranchSelect}
+ value={currentBranch}
/>
- </Tooltip>
- </Button.Group>
+ )}
+ </Combobox>
{showPushModal && (
<PushChangesModal
- onClose={handleClosePushModal}
currentBranch={currentBranch}
+ onClose={togglePushModal}
/>
)}
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 aa0e65b37d2..81d83a6b674 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
@@ -19,7 +19,6 @@ const setup = ({
syncType = "read-write",
dirty = [],
branches = ["main", "develop"],
- fullWidth = false,
}: {
isAdmin?: boolean;
remoteSyncEnabled?: boolean;
@@ -27,13 +26,12 @@ const setup = ({
syncType?: "read-only" | "read-write";
dirty?: ReturnType<typeof createMockDirtyEntity>[];
branches?: string[];
- fullWidth?: boolean;
} = {}) => {
setupRemoteSyncEndpoints({ branches, dirty });
setupCollectionEndpoints();
setupSessionEndpoints({ remoteSyncEnabled, currentBranch, syncType });
- return renderWithProviders(<GitSyncControls fullWidth={fullWidth} />, {
+ return renderWithProviders(<GitSyncControls />, {
storeInitialState: createRemoteSyncStoreState({
isAdmin,
remoteSyncEnabled,
@@ -43,6 +41,11 @@ const setup = ({
});
};
+const getOption = (name: RegExp) => screen.getByRole("option", { name });
+const getBranchButton = (name: RegExp) => screen.getByRole("button", { name });
+const queryBranchButton = (name: RegExp) =>
+ screen.queryByRole("button", { name });
+
describe("GitSyncControls", () => {
beforeEach(() => {
jest.clearAllMocks();
@@ -54,9 +57,7 @@ describe("GitSyncControls", () => {
// Wait a tick to ensure component has rendered
await waitFor(() => {
- expect(
- screen.queryByTestId("git-sync-controls"),
- ).not.toBeInTheDocument();
+ expect(queryBranchButton(/main/)).not.toBeInTheDocument();
});
});
@@ -64,9 +65,7 @@ describe("GitSyncControls", () => {
setup({ isAdmin: false });
await waitFor(() => {
- expect(
- screen.queryByTestId("git-sync-controls"),
- ).not.toBeInTheDocument();
+ expect(queryBranchButton(/main/)).not.toBeInTheDocument();
});
});
@@ -74,9 +73,7 @@ describe("GitSyncControls", () => {
setup({ currentBranch: null });
await waitFor(() => {
- expect(
- screen.queryByTestId("git-sync-controls"),
- ).not.toBeInTheDocument();
+ expect(queryBranchButton(/main/)).not.toBeInTheDocument();
});
});
@@ -84,9 +81,7 @@ describe("GitSyncControls", () => {
setup({ syncType: "read-only" });
await waitFor(() => {
- expect(
- screen.queryByTestId("git-sync-controls"),
- ).not.toBeInTheDocument();
+ expect(queryBranchButton(/main/)).not.toBeInTheDocument();
});
});
@@ -94,184 +89,121 @@ describe("GitSyncControls", () => {
setup();
await waitFor(() => {
- expect(screen.getByTestId("git-sync-controls")).toBeInTheDocument();
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
});
});
- describe("branch picker integration", () => {
+ describe("git sync button", () => {
it("should display current branch name", async () => {
setup({ currentBranch: "main" });
-
await waitFor(() => {
- expect(screen.getByTestId("branch-picker-button")).toBeInTheDocument();
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
- expect(screen.getByText("main")).toBeInTheDocument();
});
it("should display different branch name", async () => {
setup({ currentBranch: "develop" });
-
await waitFor(() => {
- expect(screen.getByText("develop")).toBeInTheDocument();
+ expect(getBranchButton(/develop/)).toBeInTheDocument();
});
- });
- });
- describe("pull button", () => {
- it("should render pull button", async () => {
- setup();
-
- await waitFor(() => {
- expect(screen.getByTestId("git-pull-button")).toBeInTheDocument();
- });
+ expect(queryBranchButton(/main/)).not.toBeInTheDocument();
});
- it("should have correct aria-label", async () => {
+ it("should open dropdown when clicked", async () => {
setup();
await waitFor(() => {
- expect(screen.getByLabelText("Pull from Git")).toBeInTheDocument();
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
- });
- it("should call import mutation when clicked", async () => {
- setup();
+ await userEvent.click(getBranchButton(/main/));
- await waitFor(() => {
- expect(screen.getByTestId("git-pull-button")).toBeInTheDocument();
- });
-
- await userEvent.click(screen.getByTestId("git-pull-button"));
-
- await waitFor(() => {
- expect(
- fetchMock.callHistory.done("path:/api/ee/remote-sync/import"),
- ).toBe(true);
- });
+ expect(getOption(/Push changes/)).toBeInTheDocument();
+ expect(getOption(/Pull changes/)).toBeInTheDocument();
+ expect(getOption(/Switch branch/)).toBeInTheDocument();
});
});
- describe("push button", () => {
- it("should render push button", async () => {
- setup();
+ describe("push option", () => {
+ it("should be enabled when there are changes", async () => {
+ setup({ dirty: [createMockDirtyEntity()] });
await waitFor(() => {
- expect(screen.getByTestId("git-push-button")).toBeInTheDocument();
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
- });
-
- it("should have correct aria-label", async () => {
- setup();
+ await userEvent.click(getBranchButton(/main/));
- await waitFor(() => {
- expect(screen.getByLabelText("Push to Git")).toBeInTheDocument();
- });
+ expect(getOption(/Push changes/)).toBeEnabled();
});
- it("should be disabled when there are no changes", async () => {
+ it("should be disabled and show proper tooltip when there are no changes", async () => {
setup({ dirty: [] });
await waitFor(() => {
- expect(screen.getByTestId("git-push-button")).toBeDisabled();
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
- });
+ await userEvent.click(getBranchButton(/main/));
+ expect(getOption(/Push changes/)).toHaveAttribute(
+ "data-combobox-disabled",
+ "true",
+ );
- it("should be enabled when there are changes", async () => {
- setup({
- dirty: [createMockDirtyEntity()],
- });
-
- await waitFor(() => {
- expect(screen.getByTestId("git-push-button")).toBeEnabled();
- });
+ await userEvent.hover(getOption(/Push changes/));
+ expect(
+ await screen.findByRole("tooltip", { name: "No changes to push" }),
+ ).toBeInTheDocument();
});
it("should open push modal when clicked with changes", async () => {
- setup({
- dirty: [createMockDirtyEntity()],
- });
+ setup({ dirty: [createMockDirtyEntity()] });
await waitFor(() => {
- expect(screen.getByTestId("git-push-button")).toBeEnabled();
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
-
- await userEvent.click(screen.getByTestId("git-push-button"));
+ await userEvent.click(getBranchButton(/main/));
+ await userEvent.click(getOption(/Push changes/));
await waitFor(() => {
- // The PushChangesModal should be rendered
expect(screen.getByRole("dialog")).toBeInTheDocument();
});
});
});
- describe("pill structure", () => {
- it("should render all three sections (branch picker, pull, push)", async () => {
+ describe("pull option", () => {
+ it("should call import mutation when clicked", async () => {
setup();
await waitFor(() => {
- expect(screen.getByTestId("git-sync-controls")).toBeInTheDocument();
- });
- expect(screen.getByTestId("branch-picker-button")).toBeInTheDocument();
- expect(screen.getByTestId("git-pull-button")).toBeInTheDocument();
- expect(screen.getByTestId("git-push-button")).toBeInTheDocument();
- });
- });
-
- describe("dirty state detection", () => {
- it("should detect dirty state with updated entity", async () => {
- setup({
- dirty: [createMockDirtyEntity({ sync_status: "update" })],
- });
-
- await waitFor(() => {
- expect(screen.getByTestId("git-push-button")).toBeEnabled();
- });
- });
-
- it("should detect dirty state with created entity", async () => {
- setup({
- dirty: [createMockDirtyEntity({ sync_status: "create" })],
- });
-
- await waitFor(() => {
- expect(screen.getByTestId("git-push-button")).toBeEnabled();
- });
- });
-
- it("should detect dirty state with deleted entity", async () => {
- setup({
- dirty: [createMockDirtyEntity({ sync_status: "delete" })],
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
+ await userEvent.click(getBranchButton(/main/));
+ await userEvent.click(getOption(/Pull changes/));
await waitFor(() => {
- expect(screen.getByTestId("git-push-button")).toBeEnabled();
+ expect(
+ fetchMock.callHistory.done("path:/api/ee/remote-sync/import"),
+ ).toBe(true);
});
});
});
- describe("fullWidth prop", () => {
- it("should render with default styling when fullWidth is false", async () => {
- setup({ fullWidth: false });
+ describe("switch branch option", () => {
+ it("should show branch dropdown when switch branch is clicked", async () => {
+ setup({ branches: ["main", "develop", "feature-1"] });
await waitFor(() => {
- expect(screen.getByTestId("git-sync-controls")).toBeInTheDocument();
+ expect(getBranchButton(/main/)).toBeInTheDocument();
});
-
- const controls = screen.getByTestId("git-sync-controls");
- expect(controls).toHaveStyle({ width: "13.5rem" });
- });
-
- it("should render with full width when fullWidth is true", async () => {
- setup({ fullWidth: true });
+ await userEvent.click(getBranchButton(/main/));
+ await userEvent.click(getOption(/Switch branch/));
await waitFor(() => {
- expect(screen.getByTestId("git-sync-controls")).toBeInTheDocument();
+ expect(
+ screen.getByPlaceholderText("Find or create a branch..."),
+ ).toBeInTheDocument();
});
-
- const controls = screen.getByTestId("git-sync-controls");
- expect(controls).toHaveStyle({ width: "100%" });
- expect(controls).not.toHaveStyle({ maxWidth: "13.5rem" });
});
});
});
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
new file mode 100644
index 00000000000..15650574fd1
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/GitSyncControls/GitSyncOptionsDropdown.tsx
@@ -0,0 +1,57 @@
+import { t } from "ttag";
+
+import { Combobox, Group, Icon, Text, Tooltip } from "metabase/ui";
+
+export interface GitSyncOptionsDropdownProps {
+ isPushDisabled: boolean;
+ onPullClick: VoidFunction;
+ onPushClick: VoidFunction;
+ onSwitchBranchClick: VoidFunction;
+}
+
+export const GitSyncOptionsDropdown = ({
+ onPullClick,
+ onPushClick,
+ onSwitchBranchClick,
+ isPushDisabled,
+}: GitSyncOptionsDropdownProps) => {
+ return (
+ <Combobox.Dropdown p={0}>
+ <Combobox.Options>
+ <Tooltip
+ label={isPushDisabled ? t`No changes to push` : t`Push changes`}
+ >
+ <Combobox.Option
+ disabled={isPushDisabled}
+ onClick={onPushClick}
+ py="sm"
+ value="push"
+ >
+ <Group gap="md" wrap="nowrap">
+ <Icon name="arrow_up" size={12} />
+ <Text>{t`Push changes`}</Text>
+ </Group>
+ </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>
+
+ <Combobox.Option
+ onClick={onSwitchBranchClick}
+ py="sm"
+ value="switch-branch"
+ >
+ <Group gap="md" wrap="nowrap">
+ <Icon name="git_branch" size={12} />
+ <Text>{t`Switch branch`}</Text>
+ </Group>
+ </Combobox.Option>
+ </Combobox.Options>
+ </Combobox.Dropdown>
+ );
+};
diff --git a/frontend/src/metabase/plugins/oss/remote-sync.ts b/frontend/src/metabase/plugins/oss/remote-sync.ts
index 368b41bb963..0f07724b3d4 100644
--- a/frontend/src/metabase/plugins/oss/remote-sync.ts
+++ b/frontend/src/metabase/plugins/oss/remote-sync.ts
@@ -18,10 +18,6 @@ export type CollectionsNavTreeProps = {
onSelect?: (item: ITreeNodeItem) => void;
};
-export interface GitSyncAppBarControlsProps {
- fullWidth?: boolean;
-}
-
export interface GitSettingsModalProps {
isOpen: boolean;
onClose: () => void;
@@ -31,8 +27,7 @@ const getDefaultPluginRemoteSync = () => ({
LibraryNav: PluginPlaceholder,
RemoteSyncSettings: NotFoundPlaceholder,
SyncedCollectionsSidebarSection: PluginPlaceholder,
- GitSyncAppBarControls:
- PluginPlaceholder as ComponentType<GitSyncAppBarControlsProps>,
+ GitSyncAppBarControls: PluginPlaceholder as ComponentType,
GitSettingsModal: PluginPlaceholder as ComponentType<GitSettingsModalProps>,
GitSyncSetupMenuItem: PluginPlaceholder,
CollectionsNavTree: null as ComponentType<CollectionsNavTreeProps> | null,
@@ -53,7 +48,7 @@ export const PLUGIN_REMOTE_SYNC: {
LibraryNav: ComponentType;
RemoteSyncSettings: ComponentType;
SyncedCollectionsSidebarSection: ComponentType<SyncedCollectionsSidebarSectionProps>;
- GitSyncAppBarControls: ComponentType<GitSyncAppBarControlsProps>;
+ GitSyncAppBarControls: ComponentType;
GitSettingsModal: ComponentType<GitSettingsModalProps>;
GitSyncSetupMenuItem: ComponentType<GitSyncSetupMenuItemProps>;
CollectionsNavTree: ComponentType<CollectionsNavTreeProps> | null;
diff --git a/frontend/src/metabase/ui/index.ts b/frontend/src/metabase/ui/index.ts
index d27e39618d8..d6d7b8d2760 100644
--- a/frontend/src/metabase/ui/index.ts
+++ b/frontend/src/metabase/ui/index.ts
@@ -1,5 +1,6 @@
export { rem, useCombobox, useMantineTheme } from "@mantine/core";
export type {
+ ComboboxStore,
FloatingPosition,
MantineSize,
MantineStyleProps,