File size: 1,370 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
import { SelectDropdown } from '@automattic/components';
import { useI18n } from '@wordpress/react-i18n';
import {
GitHubInstallationData,
useGithubInstallationsQuery,
} from '../../use-github-installations-query';
import './style.scss';
interface GitHubInstallationsDropdown {
installations: GitHubInstallationData[];
onAddInstallation(): void;
value?: GitHubInstallationData;
onChange( value: GitHubInstallationData ): void;
}
export const GitHubInstallationsDropdown = ( {
onAddInstallation,
installations,
value,
onChange,
}: GitHubInstallationsDropdown ) => {
const { __ } = useI18n();
const { isFetching } = useGithubInstallationsQuery();
return (
<SelectDropdown
className="github-deployments-installations-select"
selectedText={ value?.account_name || __( 'Select account' ) }
isLoading={ isFetching }
disabled={ ! installations.length }
>
{ installations.map( ( installation ) => (
<SelectDropdown.Item
key={ installation.account_name }
selected={ value?.account_name === installation.account_name }
onClick={ () => onChange( installation ) }
>
{ installation.account_name }
</SelectDropdown.Item>
) ) }
<SelectDropdown.Separator />
<SelectDropdown.Item onClick={ onAddInstallation } key="add">
{ __( 'Add GitHub account' ) }
</SelectDropdown.Item>
</SelectDropdown>
);
};
|