import * as React from '@theia/core/shared/react'; import Tippy from '@tippyjs/react'; import { AvailableBoard } from '../../boards/boards-service-provider'; import { CertificateListComponent } from './certificate-list'; import { SelectBoardComponent } from './select-board-components'; import { CertificateAddComponent } from './certificate-add-new'; import { nls } from '@theia/core/lib/common'; export const CertificateUploaderComponent = ({ availableBoards, certificates, addCertificate, updatableFqbns, uploadCertificates, openContextMenu, }: { availableBoards: AvailableBoard[]; certificates: string[]; addCertificate: (cert: string) => void; updatableFqbns: string[]; uploadCertificates: ( fqbn: string, address: string, urls: string[] ) => Promise; openContextMenu: (x: number, y: number, cert: string) => void; }): React.ReactElement => { const [installFeedback, setInstallFeedback] = React.useState< 'ok' | 'fail' | 'installing' | null >(null); const [showAdd, setShowAdd] = React.useState(false); const [selectedCerts, setSelectedCerts] = React.useState([]); const [selectedBoard, setSelectedBoard] = React.useState(null); const installCertificates = async () => { if (!selectedBoard || !selectedBoard.fqbn || !selectedBoard.port) { return; } setInstallFeedback('installing'); try { await uploadCertificates( selectedBoard.fqbn, selectedBoard.port.address, selectedCerts ); setInstallFeedback('ok'); } catch { setInstallFeedback('fail'); } }; const onBoardSelect = React.useCallback( (board: AvailableBoard) => { const newFqbn = (board && board.fqbn) || null; const prevFqbn = (selectedBoard && selectedBoard.fqbn) || null; if (newFqbn !== prevFqbn) { setInstallFeedback(null); setSelectedBoard(board); } }, [selectedBoard] ); return ( <>
{nls.localize( 'arduino/certificate/selectCertificateToUpload', '1. Select certificate to upload' )} { addCertificate(cert); setShowAdd(false); }} /> } placement="bottom-end" onClickOutside={() => setShowAdd(false)} visible={showAdd} interactive={true} >
{nls.localize( 'arduino/certificate/selectDestinationBoardToUpload', '2. Select destination board and upload certificate' )}
{installFeedback === 'installing' && (
{nls.localize( 'arduino/certificate/uploadingCertificates', 'Uploading certificates.' )}
)} {installFeedback === 'ok' && (
{nls.localize( 'arduino/certificate/certificatesUploaded', 'Certificates uploaded.' )}
)} {installFeedback === 'fail' && (
{nls.localize( 'arduino/certificate/uploadFailed', 'Upload failed. Please try again.' )}
)}
); };