UNPKG

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

Version:
93 lines (90 loc) 3.54 kB
import { jsx, Fragment, jsxs } from 'react/jsx-runtime'; import { Link, StatusOK } from '@backstage/core-components'; 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 { useTranslation } from '../../hooks/useTranslation.esm.js'; import { RepositorySelection } from '../../types/types.esm.js'; import { getCustomisedErrorMessage } from '../../utils/repository-utils.esm.js'; import { useDrawer } from '../DrawerContext.esm.js'; const PreviewFile = ({ data }) => { const { t } = useTranslation(); 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, (key) => t(key, {}) ); 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 : t("previewFile.prCreationUnsuccessful"), children: /* @__PURE__ */ jsxs(Typography, { component: "span", children: [ /* @__PURE__ */ jsx( ErrorOutline, { color: "error", style: { verticalAlign: "sub", paddingTop: "7px" } } ), /* @__PURE__ */ jsxs(Typography, { component: "span", "data-testid": "failed", children: [ " ", t("previewFile.failedToCreatePR"), " " ] }) ] }) } ), /* @__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: [ t("previewFile.viewRepository"), " ", /* @__PURE__ */ jsx( OpenInNewIcon, { style: { verticalAlign: "sub", paddingTop: "7px" } } ), " " ] }) : t("common.edit") } ) ] }) : /* @__PURE__ */ jsxs( Typography, { component: "span", style: { display: "flex", alignItems: "baseline" }, children: [ /* @__PURE__ */ jsx(StatusOK, {}), t("status.readyToImport"), /* @__PURE__ */ jsx( Link, { to: "", style: { marginLeft: "4px" }, onClick: () => openDrawer(data), "data-testid": Object.keys(data?.selectedRepositories || []).length > 1 ? "preview-files" : "preview-file", children: Object.keys(data?.selectedRepositories || []).length > 1 ? t("previewFile.previewFiles") : t("previewFile.previewFile") } ) ] } ) }); }; export { PreviewFile }; //# sourceMappingURL=PreviewFile.esm.js.map