UNPKG

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

Version:
112 lines (109 loc) 3.86 kB
import { jsx, jsxs, Fragment } from 'react/jsx-runtime'; import { Link, MarkdownContent } from '@backstage/core-components'; import OpenInNewIcon from '@mui/icons-material/OpenInNew'; import Alert from '@mui/material/Alert'; import AlertTitle from '@mui/material/AlertTitle'; import Box from '@mui/material/Box'; import { useFormikContext } from 'formik'; import { useTranslation } from '../../hooks/useTranslation.esm.js'; import { RepositoryStatus } from '../../types/types.esm.js'; import { getCustomisedErrorMessage } from '../../utils/repository-utils.esm.js'; import { PreviewPullRequestForm } from './PreviewPullRequestForm.esm.js'; const PreviewPullRequest = ({ repoId, repoUrl, pullRequest, setPullRequest, formErrors, setFormErrors, others }) => { const { t } = useTranslation(); const { status } = useFormikContext(); const error = status?.errors?.[repoId]; const info = status?.infos?.[repoId]; if (info?.error?.message.includes( RepositoryStatus.CATALOG_INFO_FILE_EXISTS_IN_REPO ) && !error) { return /* @__PURE__ */ jsx(Box, { marginTop: others?.addPaddingTop ? 2 : 0, children: /* @__PURE__ */ jsx(Alert, { severity: "info", children: getCustomisedErrorMessage( info.error.message, (key) => t(key, {}) ).message }) }); } return /* @__PURE__ */ jsxs(Fragment, { children: [ error && /* @__PURE__ */ jsxs(Box, { marginTop: others?.addPaddingTop ? 2 : 0, children: [ /* @__PURE__ */ jsxs(Alert, { severity: "error", children: [ /* @__PURE__ */ jsx(AlertTitle, { children: error.error?.title ? error.error?.title : t("previewFile.failedToCreatePR") }), getCustomisedErrorMessage( error.error.message, (key) => t(key, {}) ).message, " ", error?.repository?.organization && error?.repository?.name && /* @__PURE__ */ jsxs( Link, { to: `https://github.com/${error.repository.organization}/${error.repository.name}`, children: [ t("previewFile.viewRepository"), /* @__PURE__ */ jsx( OpenInNewIcon, { style: { verticalAlign: "sub", paddingTop: "7px" } } ) ] } ) ] }), !others?.addPaddingTop && /* @__PURE__ */ jsx("br", {}) ] }), info && /* @__PURE__ */ jsxs(Box, { marginTop: others?.addPaddingTop ? 2 : 0, children: [ /* @__PURE__ */ jsxs(Alert, { severity: "info", "data-testid": "other-info", children: [ getCustomisedErrorMessage( info.error.message, (key) => t(key, {}) ).message, " " ] }), !others?.addPaddingTop && /* @__PURE__ */ jsx("br", {}) ] }), pullRequest[repoId]?.pullRequestUrl && /* @__PURE__ */ jsx(Box, { marginTop: others?.addPaddingTop ? 2 : 0, children: /* @__PURE__ */ jsx(Alert, { severity: "info", "data-testid": "pull-request-info", children: /* @__PURE__ */ jsx( Box, { sx: { margin: 0, padding: 0, "& p": { margin: 0, padding: 0 } }, children: /* @__PURE__ */ jsx( MarkdownContent, { content: t("previewFile.pullRequestPendingApproval").replace( "{{pullRequestUrl}}", pullRequest[repoId].pullRequestUrl || "" ).replace( "{{pullRequestText}}", t("previewFile.pullRequestText") ) } ) } ) }) }), /* @__PURE__ */ jsx( PreviewPullRequestForm, { repoId, repoUrl, pullRequest, setPullRequest, formErrors, setFormErrors } ) ] }); }; export { PreviewPullRequest }; //# sourceMappingURL=PreviewPullRequest.esm.js.map