-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create a HarvesterInfoModal component that unifies error and success …
…texts Refactor StartHarvester.js and UDP.js to use the HarvesterInfoModal component Use okapiKy to call /start endpoint on harvester
- Loading branch information
Showing
8 changed files
with
211 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import PropTypes from 'prop-types'; | ||
import { Button, Modal } from '@folio/stripes-components'; | ||
import { FormattedMessage } from 'react-intl'; | ||
import { Link } from 'react-router-dom'; | ||
import urls from '../../util/urls'; | ||
|
||
const createSuccessText = (udpLabel) => { | ||
const additionalValues = udpLabel ? { provider: true, name: udpLabel } : { provider: false }; | ||
return ( | ||
<FormattedMessage | ||
id="ui-erm-usage.harvester.start.success" | ||
values={{ | ||
link: ( | ||
<Link to={urls.jobsView + '?sort=-startedAt'}> | ||
<FormattedMessage id="ui-erm-usage.harvester.jobs.paneTitle" /> | ||
</Link> | ||
), | ||
...additionalValues, | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
const createErrorText = (udpLabel) => { | ||
const values = udpLabel ? { provider: true, name: udpLabel } : { provider: false }; | ||
return <FormattedMessage id="ui-erm-usage.harvester.start.failure" values={values} />; | ||
}; | ||
|
||
const createLabelText = (isSuccess) => { | ||
const msgId = isSuccess | ||
? 'ui-erm-usage.harvester.start.started' | ||
: 'ui-erm-usage.harvester.start.failed'; | ||
return <FormattedMessage id={msgId} />; | ||
}; | ||
|
||
const HarvesterInfoModal = ({ errMessage = null, isSuccess = false, onClose, open = false, udpLabel }) => ( | ||
<Modal | ||
dismissible | ||
closeOnBackgroundClick | ||
open={open} | ||
onClose={onClose} | ||
label={createLabelText(isSuccess)} | ||
footer={ | ||
<Button onClick={onClose}> | ||
<FormattedMessage id="ui-erm-usage.general.ok" /> | ||
</Button> | ||
} | ||
> | ||
{isSuccess ? ( | ||
createSuccessText(udpLabel) | ||
) : ( | ||
<> | ||
{createErrorText(udpLabel)} | ||
<br /> | ||
{errMessage} | ||
</> | ||
)} | ||
</Modal> | ||
); | ||
|
||
HarvesterInfoModal.propTypes = { | ||
errMessage: PropTypes.string, | ||
isSuccess: PropTypes.bool, | ||
onClose: PropTypes.func, | ||
open: PropTypes.bool, | ||
udpLabel: PropTypes.string, | ||
}; | ||
|
||
export default HarvesterInfoModal; |
69 changes: 69 additions & 0 deletions
69
src/components/HarvesterInfoModal/HarvesterInfoModal.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import renderWithIntl from '../../../test/jest/helpers/renderWithIntl'; | ||
import HarvesterInfoModal from './HarvesterInfoModal'; | ||
|
||
const render = (props) => { | ||
return renderWithIntl( | ||
<MemoryRouter> | ||
<HarvesterInfoModal {...props} /> | ||
</MemoryRouter> | ||
); | ||
}; | ||
|
||
describe('HarvesterInfoModal', () => { | ||
test('default values', () => { | ||
const { container } = render(); | ||
expect(container.innerHTML).toBe('<div></div>'); | ||
}); | ||
|
||
test('open == false', () => { | ||
const { container } = render({ open: false }); | ||
expect(container.innerHTML).toBe('<div></div>'); | ||
}); | ||
|
||
test('isSuccess==true, udpLabel', () => { | ||
const { getByText, getByRole } = render({ | ||
open: true, | ||
isSuccess: true, | ||
udpLabel: 'Provider123', | ||
}); | ||
expect(getByText('Harvester started')).toBeInTheDocument(); | ||
expect(getByText(/^A harvesting job for 'Provider123' has been/)).toBeInTheDocument(); | ||
expect(getByText('Harvesting jobs')).toHaveAttribute('href', '/eusage/jobs?sort=-startedAt'); | ||
expect(getByRole('button', { name: 'OK' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('isSuccess==true, no udpLabel', () => { | ||
const { getByText, getByRole } = render({ | ||
open: true, | ||
isSuccess: true, | ||
}); | ||
expect(getByText('Harvester started')).toBeInTheDocument(); | ||
expect(getByText(/^A harvesting job has been/)).toBeInTheDocument(); | ||
expect(getByText('Harvesting jobs')).toHaveAttribute('href', '/eusage/jobs?sort=-startedAt'); | ||
expect(getByRole('button', { name: 'OK' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('isSuccess==false, udpLabel', () => { | ||
const { getByRole, queryByText } = render({ | ||
open: true, | ||
isSuccess: false, | ||
udpLabel: 'Provider123', | ||
}); | ||
expect(queryByText('Harvester failed to start')).toBeInTheDocument(); | ||
expect(queryByText(/^Failed to schedule .* for 'Provider123'/)).toBeInTheDocument(); | ||
expect(queryByText('Harvesting jobs')).toBeNull(); | ||
expect(getByRole('button', { name: 'OK' })).toBeInTheDocument(); | ||
}); | ||
|
||
test('isSuccess==false, no udpLabel', () => { | ||
const { getByRole, queryByText } = render({ | ||
open: true, | ||
isSuccess: false, | ||
}); | ||
expect(queryByText('Harvester failed to start')).toBeInTheDocument(); | ||
expect(queryByText(/^Failed to schedule a harvesting job.$/)).toBeInTheDocument(); | ||
expect(queryByText('Harvesting jobs')).toBeNull(); | ||
expect(getByRole('button', { name: 'OK' })).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './HarvesterInfoModal'; |
115 changes: 0 additions & 115 deletions
115
src/components/StartHarvesterModal/StartHarvesterModal.js
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.