import { useNavigate } from 'react-router-dom-v5-compat';
import { Trans, t } from '@grafana/i18n';
import { Alert, Button, Dropdown, Icon, LinkButton, Menu, Stack } from '@grafana/ui';
import { Repository } from 'app/api/clients/provisioning/v0alpha1';
import { RepoType } from '../Wizard/types';
import { CONNECT_URL } from '../constants';
import { checkSyncSettings } from '../utils/checkSyncSettings';
interface Props {
items?: Repository[];
showDropdown?: boolean;
}
type ConnectUrl = `${typeof CONNECT_URL}/${RepoType}`;
const gitURL: ConnectUrl = `${CONNECT_URL}/github`;
const localURL: ConnectUrl = `${CONNECT_URL}/local`;
export function ConnectRepositoryButton({ items, showDropdown = false }: Props) {
const state = checkSyncSettings(items);
const navigate = useNavigate();
if (state.instanceConnected) {
return null;
}
if (state.maxReposReached) {
return (
);
}
if (showDropdown) {
return (
{
navigate(gitURL);
}}
/>
{
navigate(localURL);
}}
/>
}
>
);
}
return (
Configure Git Sync
Configure file provisioning
);
}