import PropTypes from 'prop-types'; import React from 'react'; import URI from 'urijs'; import { Alert, Button, Divider, Skeleton } from '@patternfly/react-core'; import { useForemanLocation, useForemanOrganization, } from 'foremanReact/Root/Context/ForemanContext'; import { translate as __, sprintf } from 'foremanReact/common/I18n'; import { useAPI } from 'foremanReact/common/hooks/API/APIHooks'; import { STATUS } from 'foremanReact/constants'; import PageLayout from 'foremanReact/routes/common/PageLayout/PageLayout'; import { JobWizard } from './JobWizard'; import { JOB_API_KEY } from './JobWizardConstants'; const JobWizardPageRerun = ({ match: { params: { id }, }, location: { search }, }) => { const uri = new URI(search); const { failed_only: failedOnly } = uri.search(true); const { succeeded_only: succeededOnly } = uri.search(true); let queryParams = ''; if (failedOnly) { queryParams = '&failed_only=1'; } else if (succeededOnly) { queryParams = '&succeeded_only=1'; } const { response, status } = useAPI( 'get', `/ui_job_wizard/job_invocation?id=${id}${queryParams}`, JOB_API_KEY ); const title = __('Run job'); const breadcrumbOptions = { breadcrumbItems: [ { caption: __('Jobs'), url: `/job_invocations` }, { caption: title }, ], }; const jobOrganization = response.job_organization; const jobLocation = response.job_location; const currentOrganization = useForemanOrganization(); const currentLocation = useForemanLocation(); return ( {__('Use legacy form')} } > {!status || status === STATUS.PENDING ? (
) : ( {jobOrganization?.id !== currentOrganization?.id && ( )} {jobLocation?.id !== currentLocation?.id && ( )} )}
); }; JobWizardPageRerun.propTypes = { match: PropTypes.shape({ params: PropTypes.shape({ id: PropTypes.string.isRequired, }), }).isRequired, location: PropTypes.shape({ search: PropTypes.string, }), }; JobWizardPageRerun.defaultProps = { location: { search: '' }, }; export default JobWizardPageRerun;