UNPKG

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

Version:
126 lines (123 loc) 3.57 kB
import { jsx, jsxs, Fragment } from 'react/jsx-runtime'; import { useState } from 'react'; import ErrorOutline from '@mui/icons-material/ErrorOutline'; import InfoOutlined from '@mui/icons-material/InfoOutlined'; import Box from '@mui/material/Box'; import Tab from '@mui/material/Tab'; import Tabs from '@mui/material/Tabs'; import Typography from '@mui/material/Typography'; import { useFormikContext } from 'formik'; import { PreviewPullRequest } from './PreviewPullRequest.esm.js'; const CustomTabPanel = ({ children, value, index, ...other }) => { return /* @__PURE__ */ jsx( "div", { role: "tabpanel", hidden: value !== index, id: `preview-pullrequest-panel-${index}`, ...other, children: value === index && /* @__PURE__ */ jsx(Fragment, { children }) } ); }; const getLabel = (status, repoId, repoName) => { if (status?.errors?.[`${repoId}`]) { return /* @__PURE__ */ jsxs(Typography, { component: "span", "data-testid": "pr-creation-failed", children: [ /* @__PURE__ */ jsx( ErrorOutline, { color: "error", style: { verticalAlign: "sub", paddingTop: "7px" } } ), " ", repoName ] }); } if (status?.infos?.[`${repoId}`]) { return /* @__PURE__ */ jsxs(Typography, { component: "span", "data-testid": "info-message", children: [ /* @__PURE__ */ jsx( InfoOutlined, { color: "info", style: { verticalAlign: "sub", paddingTop: "7px" } } ), " ", repoName ] }); } return repoName; }; const PreviewPullRequests = ({ repositories, pullRequest, setPullRequest, formErrors, setFormErrors }) => { const [value, setValue] = useState(0); const { status } = useFormikContext(); const handleChange = (_event, newValue) => { setValue(newValue); }; if (Object.values(repositories || []).length === 1) { return /* @__PURE__ */ jsx( PreviewPullRequest, { repoId: Object.values(repositories)[0].id || "", repoUrl: Object.values(repositories)[0].repoUrl || "", repoBranch: Object.values(repositories)[0].defaultBranch || "main", pullRequest, setPullRequest, formErrors, setFormErrors } ); } return /* @__PURE__ */ jsxs(Box, { sx: { width: "100%" }, children: [ /* @__PURE__ */ jsx(Box, { sx: { borderBottom: 1, borderColor: "divider" }, children: /* @__PURE__ */ jsx( Tabs, { value, onChange: handleChange, variant: "scrollable", indicatorColor: "primary", scrollButtons: "auto", "aria-label": "preview-pull-requests", children: repositories.map((repo) => { return /* @__PURE__ */ jsx( Tab, { label: getLabel(status, repo.id, repo?.repoName || ""), id: repo.repoName }, repo.id ); }) } ) }), Object.values(repositories).map((repo, index) => { return /* @__PURE__ */ jsx(CustomTabPanel, { value, index, children: /* @__PURE__ */ jsx( PreviewPullRequest, { repoId: repo.id, repoUrl: repo.repoUrl || "", repoBranch: repo.defaultBranch || "main", pullRequest, setPullRequest, formErrors, setFormErrors, others: { addPaddingTop: true } } ) }, repo.id); }) ] }); }; export { PreviewPullRequests }; //# sourceMappingURL=PreviewPullRequests.esm.js.map