Skip to content

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

2.0 KB
Raw Blame
import { t } from "ttag";

import { Box, Combobox, Group, Icon, Loader, Text, Tooltip } from "metabase/ui";

export interface GitSyncOptionsDropdownProps {
  isPullDisabled: boolean;
  isPullError: boolean;
  isLoadingPull: boolean;
  isPushDisabled: boolean;
  onPullClick: VoidFunction;
  onPushClick: VoidFunction;
}

export const GitSyncOptionsDropdown = ({
  isPullDisabled,
  isPullError,
  isLoadingPull,
  isPushDisabled,
  onPullClick,
  onPushClick,
}: GitSyncOptionsDropdownProps) => {
  if (isPullError) {
    return (
      <Combobox.Dropdown p={0}>
        <Box p="lg">
          <Text size="sm" c="feedback-negative" ta="center">
            {t`Failed to check for changes — check your authentication token`}
          </Text>
        </Box>
      </Combobox.Dropdown>
    );
  }

  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="lg" wrap="nowrap">
              <Icon name="arrow_up" size={12} />
              <Text>{t`Push changes`}</Text>
            </Group>
          </Combobox.Option>
        </Tooltip>

        <Tooltip
          label={isPullDisabled ? t`No changes to pull` : t`Pull from remote`}
        >
          <Combobox.Option
            disabled={isPullDisabled || isLoadingPull}
            onClick={onPullClick}
            py="sm"
            value="pull"
          >
            <Group gap="lg" wrap="nowrap">
              {isLoadingPull ? (
                <Loader size={12} data-testid="pull-changes-loader" />
              ) : (
                <Icon name="arrow_down" size={12} />
              )}
              <Text>{t`Pull changes`}</Text>
            </Group>
          </Combobox.Option>
        </Tooltip>
      </Combobox.Options>
    </Combobox.Dropdown>
  );
};