Skip to content

Commit

Permalink
refactor: rename switch
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Nov 16, 2023
1 parent 7ad94fc commit ad29bbd
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 22 deletions.
8 changes: 4 additions & 4 deletions cypress/integration/list/job-toggle/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Given('the user navigated to the job list page', () => {
})

Given('the job toggle switch is off', () => {
cy.findByRole('switch', { name: 'Toggle job' }).should('not.be.checked')
cy.findByRole('switch', { name: 'Enable' }).should('not.be.checked')
})

When('the user clicks the enabled job toggle switch', () => {
Expand All @@ -33,7 +33,7 @@ When('the user clicks the enabled job toggle switch', () => {
{ fixture: 'list/disabled-user-job' }
)

cy.findByRole('switch', { name: 'Toggle job' }).click()
cy.findByRole('switch', { name: 'Disable' }).click()
})

When('the user clicks the disabled job toggle switch', () => {
Expand All @@ -46,9 +46,9 @@ When('the user clicks the disabled job toggle switch', () => {
{ fixture: 'list/enabled-user-job' }
)

cy.findByRole('switch', { name: 'Toggle job' }).click()
cy.findByRole('switch', { name: 'Enable' }).click()
})

Then('the job toggle switch is on', () => {
cy.findByRole('switch', { name: 'Toggle job' }).should('be.checked')
cy.findByRole('switch', { name: 'Disable' }).should('be.checked')
})
11 changes: 7 additions & 4 deletions i18n/en.pot
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
"POT-Creation-Date: 2023-11-16T13:48:39.789Z\n"
"PO-Revision-Date: 2023-11-16T13:48:39.789Z\n"
"POT-Creation-Date: 2023-11-16T14:05:43.332Z\n"
"PO-Revision-Date: 2023-11-16T14:05:43.332Z\n"

msgid "Something went wrong"
msgstr "Something went wrong"
Expand Down Expand Up @@ -259,8 +259,11 @@ msgstr ""
"Something went wrong whilst loading the requested job. Make sure it has not "
"been deleted and try refreshing the page."

msgid "Toggle job"
msgstr "Toggle job"
msgid "Disable"
msgstr "Disable"

msgid "Enable"
msgstr "Enable"

msgid "New Job"
msgstr "New Job"
Expand Down
4 changes: 2 additions & 2 deletions src/components/JobTable/JobTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react'
import PropTypes from 'prop-types'
import { TableRow, TableCell } from '@dhis2/ui'
import { jobTypesMap } from '../../services/server-translations'
import { ToggleJobSwitch } from '../Switches'
import { JobSwitch } from '../Switches'
import JobActions from './JobActions'
import Status from './Status'
import NextRun from './NextRun'
Expand Down Expand Up @@ -36,7 +36,7 @@ const JobTableRow = ({
<Status status={status} />
</TableCell>
<TableCell>
<ToggleJobSwitch
<JobSwitch
id={id}
checked={enabled}
disabled={!configurable}
Expand Down
5 changes: 3 additions & 2 deletions src/components/JobTable/QueueTableRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
IconChevronUp24,
} from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'
import { ToggleJobSwitch } from '../Switches'
import { JobSwitch } from '../Switches'
import QueueActions from './QueueActions'
import Status from './Status'
import NextRun from './NextRun'
Expand Down Expand Up @@ -60,7 +60,8 @@ const QueueTableRow = ({
<Status status={status} />
</TableCell>
<TableCell>
<ToggleJobSwitch
{/* A queue can be toggled by toggling the first job in the queue */}
<JobSwitch
id={id}
checked={enabled}
disabled={!configurable}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { useDataMutation } from '@dhis2/app-runtime'
import i18n from '@dhis2/d2-i18n'
import { Switch } from '@dhis2/ui'

const ToggleJobSwitch = ({ id, checked, disabled, refetch }) => {
const JobSwitch = ({ id, checked, disabled, refetch }) => {
const [disableQuery] = useState({
resource: `jobConfigurations/${id}/disable`,
type: 'create',
Expand All @@ -27,18 +27,18 @@ const ToggleJobSwitch = ({ id, checked, disabled, refetch }) => {
onChange={() => {
toggleJob().then(refetch)
}}
ariaLabel={i18n.t('Toggle job')}
ariaLabel={checked ? i18n.t('Disable') : i18n.t('Enable')}
/>
)
}

const { bool, string, func } = PropTypes

ToggleJobSwitch.propTypes = {
JobSwitch.propTypes = {
checked: bool.isRequired,
disabled: bool.isRequired,
id: string.isRequired,
refetch: func.isRequired,
}

export default ToggleJobSwitch
export default JobSwitch
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import React from 'react'
import waitForExpect from 'wait-for-expect'
import { shallow, mount } from 'enzyme'
import { CustomDataProvider } from '@dhis2/app-runtime'
import ToggleJobSwitch from './ToggleJobSwitch'
import JobSwitch from './JobSwitch'

describe('<ToggleJobSwitch>', () => {
describe('<JobSwitch>', () => {
it('renders without errors', () => {
shallow(
<ToggleJobSwitch
<JobSwitch
id="1"
checked={true}
disabled={false}
Expand All @@ -27,7 +27,7 @@ describe('<ToggleJobSwitch>', () => {
refetch: refetchSpy,
}
const data = { 'jobConfigurations/id/enable': answerSpy }
const wrapper = mount(<ToggleJobSwitch {...props} />, {
const wrapper = mount(<JobSwitch {...props} />, {
wrappingComponent: CustomDataProvider,
wrappingComponentProps: { data },
})
Expand Down Expand Up @@ -58,7 +58,7 @@ describe('<ToggleJobSwitch>', () => {
refetch: refetchSpy,
}
const data = { 'jobConfigurations/id/disable': answerSpy }
const wrapper = mount(<ToggleJobSwitch {...props} />, {
const wrapper = mount(<JobSwitch {...props} />, {
wrappingComponent: CustomDataProvider,
wrappingComponentProps: { data },
})
Expand Down
2 changes: 1 addition & 1 deletion src/components/Switches/index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default as ToggleJobSwitch } from './ToggleJobSwitch'
export { default as JobSwitch } from './JobSwitch'

0 comments on commit ad29bbd

Please sign in to comment.