UNPKG

@red-hat-developer-hub/backstage-plugin-bulk-import

Version:
88 lines (85 loc) 3.26 kB
import { jsx, Fragment, jsxs } from 'react/jsx-runtime'; import { Link } from '@backstage/core-components'; import ReadyIcon from '@mui/icons-material/CheckOutlined'; import ErrorOutline from '@mui/icons-material/ErrorOutline'; import OpenInNewIcon from '@mui/icons-material/OpenInNew'; import Tooltip from '@mui/material/Tooltip'; import Typography from '@mui/material/Typography'; import { useFormikContext } from 'formik'; import { RepositorySelection, RepositoryStatus } from '../../types/types.esm.js'; import { getCustomisedErrorMessage } from '../../utils/repository-utils.esm.js'; import { useDrawer } from '../DrawerContext.esm.js'; const PreviewFile = ({ data }) => { const { status, values } = useFormikContext(); const { setOpenDrawer, setDrawerData } = useDrawer(); const statusErrors = status?.errors || {}; const errorMessage = getCustomisedErrorMessage( Object.values(statusErrors).find((s) => s?.repository?.name === data.repoName)?.error.message ); const openDrawer = (dd) => { setDrawerData(dd); setOpenDrawer(true); }; return /* @__PURE__ */ jsx(Fragment, { children: Object.keys(statusErrors).length > 0 && Object.values(statusErrors).find( (s) => s?.repository?.name === data.repoName || values.repositoryType === RepositorySelection.Organization && s?.repository?.organization === data.orgName ) ? /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx( Tooltip, { title: values.repositoryType === RepositorySelection.Repository ? errorMessage.message : "PR creation was unsuccessful for some repositories. Click on `Edit` to see the reason.", children: /* @__PURE__ */ jsx( ErrorOutline, { color: "error", style: { verticalAlign: "sub", paddingTop: "7px" } } ) } ), /* @__PURE__ */ jsxs(Typography, { component: "span", "data-testid": "failed", children: [ " ", "Failed to create PR", " " ] }), /* @__PURE__ */ jsx( Link, { to: errorMessage.showRepositoryLink ? data.repoUrl || "" : "", onClick: () => errorMessage.showRepositoryLink ? null : openDrawer(data), "data-testid": "edit-pull-request", children: errorMessage.showRepositoryLink ? /* @__PURE__ */ jsxs(Fragment, { children: [ "View repository", " ", /* @__PURE__ */ jsx( OpenInNewIcon, { style: { verticalAlign: "sub", paddingTop: "7px" } } ), " " ] }) : "Edit" } ) ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [ /* @__PURE__ */ jsx( ReadyIcon, { color: "success", style: { verticalAlign: "sub", paddingTop: "7px" } } ), RepositoryStatus.Ready, " ", /* @__PURE__ */ jsx( Link, { to: "", onClick: () => openDrawer(data), "data-testid": Object.keys(data?.selectedRepositories || []).length > 1 ? "preview-files" : "preview-file", children: Object.keys(data?.selectedRepositories || []).length > 1 ? "Preview files" : "Preview file" } ) ] }) }); }; export { PreviewFile }; //# sourceMappingURL=PreviewFile.esm.js.map