-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: add queue-specific actions
- Loading branch information
ismay
committed
Oct 17, 2023
1 parent
0e47e4e
commit c346032
Showing
7 changed files
with
129 additions
and
18 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,41 @@ | ||
import React, { useState } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { MenuItem } from '@dhis2/ui' | ||
import i18n from '@dhis2/d2-i18n' | ||
import { DeleteQueueModal } from '../Modal' | ||
|
||
const DeleteQueueAction = ({ name, onSuccess }) => { | ||
const [showModal, setShowModal] = useState(false) | ||
|
||
return ( | ||
<React.Fragment> | ||
<MenuItem | ||
dense | ||
destructive | ||
onClick={() => { | ||
setShowModal(true) | ||
}} | ||
label={i18n.t('Delete')} | ||
/> | ||
{showModal && ( | ||
<DeleteQueueModal | ||
name={name} | ||
hideModal={ | ||
/* istanbul ignore next */ | ||
() => setShowModal(false) | ||
} | ||
onSuccess={onSuccess} | ||
/> | ||
)} | ||
</React.Fragment> | ||
) | ||
} | ||
|
||
const { string, func } = PropTypes | ||
|
||
DeleteQueueAction.propTypes = { | ||
name: string.isRequired, | ||
onSuccess: func.isRequired, | ||
} | ||
|
||
export default DeleteQueueAction |
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,21 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { MenuItem } from '@dhis2/ui' | ||
import i18n from '@dhis2/d2-i18n' | ||
import history from '../../services/history' | ||
|
||
const EditQueueAction = ({ name }) => ( | ||
<MenuItem | ||
dense | ||
onClick={() => history.push(`/queue/${name}`)} | ||
label={i18n.t('Edit')} | ||
/> | ||
) | ||
|
||
const { string } = PropTypes | ||
|
||
EditQueueAction.propTypes = { | ||
name: string.isRequired, | ||
} | ||
|
||
export default EditQueueAction |
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
8 changes: 4 additions & 4 deletions
8
src/components/JobTable/Actions.test.js → src/components/JobTable/JobActions.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 |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import Actions from './Actions' | ||
import JobActions from './JobActions' | ||
|
||
describe('<Actions>', () => { | ||
describe('<JobActions>', () => { | ||
it('renders without errors for configurable jobs', () => { | ||
shallow(<Actions id="1" configurable refetch={() => {}} />) | ||
shallow(<JobActions id="1" configurable refetch={() => {}} />) | ||
}) | ||
|
||
it('renders without errors for non configurable jobs', () => { | ||
shallow(<Actions id="1" refetch={() => {}} />) | ||
shallow(<JobActions id="1" refetch={() => {}} />) | ||
}) | ||
}) |
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
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
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,29 @@ | ||
import React from 'react' | ||
import PropTypes from 'prop-types' | ||
import { FlyoutMenu, DropdownButton } from '@dhis2/ui' | ||
import i18n from '@dhis2/d2-i18n' | ||
import EditQueueAction from './EditQueueAction' | ||
import DeleteQueueAction from './DeleteQueueAction' | ||
|
||
const QueueActions = ({ name, refetch }) => ( | ||
<DropdownButton | ||
small | ||
component={ | ||
<FlyoutMenu> | ||
<EditQueueAction name={name} /> | ||
<DeleteQueueAction name={name} onSuccess={refetch} /> | ||
</FlyoutMenu> | ||
} | ||
> | ||
{i18n.t('Actions')} | ||
</DropdownButton> | ||
) | ||
|
||
const { string, func } = PropTypes | ||
|
||
QueueActions.propTypes = { | ||
name: string.isRequired, | ||
refetch: func.isRequired, | ||
} | ||
|
||
export default QueueActions |