Skip to content

Commit

Permalink
chore: remove top back to overview button
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Jul 27, 2023
1 parent 340ba49 commit 7affec5
Show file tree
Hide file tree
Showing 25 changed files with 21 additions and 263 deletions.
9 changes: 0 additions & 9 deletions cypress/integration/add-route/back-to-all-jobs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ Feature: Users should be able to navigate back to the job list
Background:
Given the user navigated to the add job page

Scenario: User clicks the back to all jobs link
When the user clicks the back to all jobs link
Then the job list route will be loaded

Scenario: User clicks the back to all jobs link after editing the form
Given the user has edited the form
When the user clicks the back to all jobs link
Then the user will be asked if they want to discard the form

Scenario: User clicks the cancel button
When the user clicks the cancel button
Then the job list route will be loaded
Expand Down
4 changes: 0 additions & 4 deletions cypress/integration/add-route/back-to-all-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ Given('the user has edited the form', () => {
cy.findByLabelText('Name*').type('Name')
})

When('the user clicks the back to all jobs link', () => {
cy.findByRole('button', { name: 'Back to all jobs' }).click()
})

When('the user clicks the cancel button', () => {
cy.findByRole('button', { name: 'Cancel' }).click()
})
Expand Down
9 changes: 0 additions & 9 deletions cypress/integration/add-sequence/back-to-all-jobs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@ Feature: Users should be able to navigate back to the job list
Background:
Given the user navigated to the add sequence page

Scenario: User clicks the back to all jobs link
When the user clicks the back to all jobs link
Then the job list route will be loaded

Scenario: User clicks the back to all jobs link after editing the form
Given the user has edited the form
When the user clicks the back to all jobs link
Then the user will be asked if they want to discard the form

Scenario: User clicks the cancel button
When the user clicks the cancel button
Then the job list route will be loaded
Expand Down
4 changes: 0 additions & 4 deletions cypress/integration/add-sequence/back-to-all-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ Given('the user has edited the form', () => {
cy.findByLabelText('Name*').type('Name')
})

When('the user clicks the back to all jobs link', () => {
cy.findByRole('button', { name: 'Back to all jobs' }).click()
})

When('the user clicks the cancel button', () => {
cy.findByRole('button', { name: 'Cancel' }).click()
})
Expand Down
9 changes: 0 additions & 9 deletions cypress/integration/edit-route/back-to-all-jobs.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,6 @@ Feature: Users should be able to navigate back to the job list
Given a single user job exists
And the user navigated to the edit job page

Scenario: User clicks the back to all jobs link
When the user clicks the back to all jobs link
Then the job list route will be loaded

Scenario: User clicks the back to all jobs link after editing the form
Given the user has edited the form
When the user clicks the back to all jobs link
Then the user will be asked if they want to discard the form

Scenario: User clicks the cancel button
When the user clicks the cancel button
Then the job list route will be loaded
Expand Down
4 changes: 0 additions & 4 deletions cypress/integration/edit-route/back-to-all-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ Given('the user has edited the form', () => {
cy.findByLabelText('Name*').type('Name')
})

When('the user clicks the back to all jobs link', () => {
cy.findByRole('button', { name: 'Back to all jobs' }).click()
})

When('the user clicks the cancel button', () => {
cy.findByRole('button', { name: 'Cancel' }).click()
})
Expand Down
10 changes: 5 additions & 5 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-07-19T12:52:52.060Z\n"
"PO-Revision-Date: 2023-07-19T12:52:52.060Z\n"
"POT-Creation-Date: 2023-07-27T09:01:30.404Z\n"
"PO-Revision-Date: 2023-07-27T09:01:30.404Z\n"

msgid "Something went wrong"
msgstr "Something went wrong"
Expand Down Expand Up @@ -228,9 +228,6 @@ msgstr "Run"
msgid "Toggle job"
msgstr "Toggle job"

msgid "Back to all jobs"
msgstr "Back to all jobs"

msgid "New Job"
msgstr "New Job"

Expand Down Expand Up @@ -271,6 +268,9 @@ msgstr "New job"
msgid "System job: {{ name }}"
msgstr "System job: {{ name }}"

msgid "Back to all jobs"
msgstr "Back to all jobs"

msgid "New Sequence"
msgstr "New Sequence"

Expand Down
23 changes: 2 additions & 21 deletions src/components/Forms/JobAddForm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import i18n from '@dhis2/d2-i18n'
import { Button, CircularLoader, Box, ReactFinalForm } from '@dhis2/ui'
import { Button, CircularLoader, Box } from '@dhis2/ui'
import { DiscardFormButton } from '../Buttons'
import { FormErrorBox } from '../FormErrorBox'
import {
Expand All @@ -13,32 +13,14 @@ import {
} from '../FormFields'
import styles from './JobAddForm.module.css'

const { useForm } = ReactFinalForm

const JobAddForm = ({
handleSubmit,
pristine,
submitting,
submitError,
hasSubmitErrors,
values,
setIsPristine,
}) => {
const { subscribe } = useForm()

/**
* Lift pristine state up on changes, wrapped in useEffect because calls to setState
* outside of the component that owns the setState should not happen synchronously.
*/
useEffect(() =>
/**
* The subscriber will only be called when pristine changes. It returns a
* cleanup function.
* https://final-form.org/docs/final-form/types/FormApi#subscribe
*/
subscribe(({ pristine }) => setIsPristine(pristine), { pristine: true })
)

// Check if there's currently a selected job type
const jobType = values[fieldNames.JOB_TYPE]

Expand Down Expand Up @@ -96,7 +78,6 @@ JobAddForm.propTypes = {
handleSubmit: func.isRequired,
hasSubmitErrors: bool.isRequired,
pristine: bool.isRequired,
setIsPristine: func.isRequired,
submitting: bool.isRequired,
values: object.isRequired,
submitError: array,
Expand Down
23 changes: 0 additions & 23 deletions src/components/Forms/JobAddForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ describe('<JobAddForm>', () => {
submitError: [message],
hasSubmitErrors: true,
values: {},
setIsPristine: () => {},
}

const wrapper = mount(
Expand All @@ -45,23 +44,6 @@ describe('<JobAddForm>', () => {
expect(actual.text()).toEqual(expect.stringContaining(message))
})

it('calls setIsPristine on form changes', () => {
const spy = jest.fn()
const wrapper = mount(
<Form
onSubmit={() => {}}
setIsPristine={spy}
component={JobAddForm}
/>
)

wrapper
.find({ id: 'name' })
.simulate('change', { target: { value: 'A change' } })

expect(spy).toHaveBeenCalledWith(false)
})

it('shows a spinner when submitting', () => {
const props = {
handleSubmit: () => {},
Expand All @@ -70,7 +52,6 @@ describe('<JobAddForm>', () => {
submitError: [],
hasSubmitErrors: false,
values: {},
setIsPristine: () => {},
}

const wrapper = mount(
Expand All @@ -95,7 +76,6 @@ describe('<JobAddForm>', () => {
const wrapper = mount(
<Form
onSubmit={() => {}}
setIsPristine={() => {}}
component={JobAddForm}
initialValues={{
[fieldNames.JOB_TYPE]: 'jobType',
Expand All @@ -112,7 +92,6 @@ describe('<JobAddForm>', () => {
const wrapper = mount(
<Form
onSubmit={() => {}}
setIsPristine={() => {}}
component={JobAddForm}
initialValues={{
[fieldNames.JOB_TYPE]: 'jobType',
Expand All @@ -133,7 +112,6 @@ describe('<JobAddForm>', () => {
submitError: [],
hasSubmitErrors: false,
values: {},
setIsPristine: () => {},
}

const wrapper = mount(
Expand All @@ -157,7 +135,6 @@ describe('<JobAddForm>', () => {
submitError: [],
hasSubmitErrors: false,
values: {},
setIsPristine: () => {},
}

const wrapper = mount(
Expand Down
10 changes: 1 addition & 9 deletions src/components/Forms/JobAddFormContainer.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import React from 'react'
import PropTypes from 'prop-types'
import { ReactFinalForm } from '@dhis2/ui'
import history from '../../services/history'
import { useSubmitJob } from '../../hooks/jobs'
import JobAddForm from './JobAddForm'

const { Form } = ReactFinalForm

const JobAddFormContainer = ({ setIsPristine }) => {
const JobAddFormContainer = () => {
const redirect = () => {
history.push('/')
}
Expand All @@ -21,16 +20,9 @@ const JobAddFormContainer = ({ setIsPristine }) => {
<Form
onSubmit={submitJob}
component={JobAddForm}
setIsPristine={setIsPristine}
destroyOnUnregister
/>
)
}

const { func } = PropTypes

JobAddFormContainer.propTypes = {
setIsPristine: func.isRequired,
}

export default JobAddFormContainer
23 changes: 2 additions & 21 deletions src/components/Forms/JobEditForm.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react'
import React from 'react'
import PropTypes from 'prop-types'
import i18n from '@dhis2/d2-i18n'
import { Button, CircularLoader, Box, ReactFinalForm } from '@dhis2/ui'
import { Button, CircularLoader, Box } from '@dhis2/ui'
import history from '../../services/history'
import { DiscardFormButton, DeleteJobButton } from '../Buttons'
import { FormErrorBox } from '../FormErrorBox'
Expand All @@ -14,8 +14,6 @@ import {
} from '../FormFields'
import styles from './JobEditForm.module.css'

const { useForm } = ReactFinalForm

const JobEditForm = ({
id,
handleSubmit,
Expand All @@ -24,23 +22,7 @@ const JobEditForm = ({
submitError,
hasSubmitErrors,
values,
setIsPristine,
}) => {
const { subscribe } = useForm()

/**
* Lift pristine state up on changes, wrapped in useEffect because calls to setState
* outside of the component that owns the setState should not happen synchronously.
*/
useEffect(() =>
/**
* The subscriber will only be called when pristine changes. It returns a
* cleanup function.
* https://final-form.org/docs/final-form/types/FormApi#subscribe
*/
subscribe(({ pristine }) => setIsPristine(pristine), { pristine: true })
)

// Check if there's currently a selected job type
const jobType = values[fieldNames.JOB_TYPE]

Expand Down Expand Up @@ -107,7 +89,6 @@ JobEditForm.propTypes = {
hasSubmitErrors: bool.isRequired,
id: string.isRequired,
pristine: bool.isRequired,
setIsPristine: func.isRequired,
submitting: bool.isRequired,
values: object.isRequired,
submitError: array,
Expand Down
25 changes: 0 additions & 25 deletions src/components/Forms/JobEditForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ describe('<JobEditForm>', () => {
submitError: [message],
hasSubmitErrors: true,
values: {},
setIsPristine: () => {},
refetchJobs: () => {},
}

Expand All @@ -47,25 +46,6 @@ describe('<JobEditForm>', () => {
expect(actual.text()).toEqual(expect.stringContaining(message))
})

it('calls setIsPristine on form changes', () => {
const spy = jest.fn()
const wrapper = mount(
<Form
onSubmit={() => {}}
id="id"
refetchJobs={() => {}}
setIsPristine={spy}
component={JobEditForm}
/>
)

wrapper
.find({ id: 'name' })
.simulate('change', { target: { value: 'A change' } })

expect(spy).toHaveBeenCalledWith(false)
})

it('shows a spinner when submitting', () => {
const props = {
id: 'id',
Expand All @@ -75,7 +55,6 @@ describe('<JobEditForm>', () => {
submitError: [],
hasSubmitErrors: false,
values: {},
setIsPristine: () => {},
refetchJobs: () => {},
}

Expand Down Expand Up @@ -103,7 +82,6 @@ describe('<JobEditForm>', () => {
id="id"
refetchJobs={() => {}}
onSubmit={() => {}}
setIsPristine={() => {}}
component={JobEditForm}
initialValues={{
[fieldNames.JOB_TYPE]: 'jobType',
Expand All @@ -122,7 +100,6 @@ describe('<JobEditForm>', () => {
id="id"
refetchJobs={() => {}}
onSubmit={() => {}}
setIsPristine={() => {}}
component={JobEditForm}
initialValues={{
[fieldNames.JOB_TYPE]: 'jobType',
Expand All @@ -144,7 +121,6 @@ describe('<JobEditForm>', () => {
submitError: [],
hasSubmitErrors: false,
values: {},
setIsPristine: () => {},
refetchJobs: () => {},
}

Expand All @@ -170,7 +146,6 @@ describe('<JobEditForm>', () => {
submitError: [],
hasSubmitErrors: false,
values: {},
setIsPristine: () => {},
refetchJobs: () => {},
}

Expand Down
Loading

0 comments on commit 7affec5

Please sign in to comment.