Skip to content

Commit

Permalink
refactor: finish naming updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ismay committed Nov 2, 2023
1 parent 984fbd2 commit 7a20811
Show file tree
Hide file tree
Showing 23 changed files with 162 additions and 131 deletions.
4 changes: 2 additions & 2 deletions cypress/integration/add-route/info-link/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'

Given('the user navigated to the add job page', () => {
cy.visit('/#/job/add')
cy.findByRole('heading', { name: 'New Job' }).should('exist')
})

Then('there is a link to the documentation', () => {
cy.findByRole('link', { name: 'About job configuration' })
cy.findByRole('link', { name: 'About the scheduler' })
.should('exist')
.should('have.attr', 'href', infoHref)
.should('have.attr', 'target', '_blank')
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/edit-route/info-link/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'

Given('a single user job exists', () => {
cy.intercept(
Expand All @@ -16,7 +16,7 @@ Given('the user navigated to the edit job page', () => {
})

Then('there is a link to the documentation', () => {
cy.findByRole('link', { name: 'About job configuration' })
cy.findByRole('link', { name: 'About the scheduler' })
.should('exist')
.should('have.attr', 'href', infoHref)
.should('have.attr', 'target', '_blank')
Expand Down
2 changes: 1 addition & 1 deletion cypress/integration/list-route/filter-jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Given('the user enables the include-system-jobs-in-list toggle', () => {
})

When('the user enters a filter string', () => {
cy.findByRole('searchbox', { name: 'Filter jobs' }).type('1')
cy.findByRole('searchbox', { name: 'Filter by name' }).type('1')
})

Then('only user jobs that match the filter will be shown', () => {
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/list-route/info-link/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'

Given('the user navigated to the job list page', () => {
cy.visit('/')
cy.findByRole('heading', { name: 'Scheduled jobs' }).should('exist')
})

Then('there is a link to the documentation', () => {
cy.findByRole('link', { name: 'About job configuration' })
cy.findByRole('link', { name: 'About the scheduler' })
.should('exist')
.should('have.attr', 'href', infoHref)
.should('have.attr', 'target', '_blank')
Expand Down
4 changes: 2 additions & 2 deletions cypress/integration/view-route/info-link/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Given, Then } from 'cypress-cucumber-preprocessor/steps'

const infoHref =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'

Given('a single system job exists', () => {
cy.intercept(
Expand All @@ -18,7 +18,7 @@ Given('the user navigated to the view job page', () => {
})

Then('there is a link to the documentation', () => {
cy.findByRole('link', { name: 'About job configuration' })
cy.findByRole('link', { name: 'About the scheduler' })
.should('exist')
.should('have.attr', 'href', infoHref)
.should('have.attr', 'target', '_blank')
Expand Down
4 changes: 2 additions & 2 deletions src/components/Routes/Routes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react'
import { Route, Switch, Redirect } from 'react-router-dom'
import { Router } from 'react-router'
import JobList from '../../pages/JobList'
import JobAndQueueList from '../../pages/JobAndQueueList'
import JobAdd from '../../pages/JobAdd'
import QueueAdd from '../../pages/QueueAdd'
import QueueEdit from '../../pages/QueueEdit'
Expand All @@ -14,7 +14,7 @@ const Routes = () => (
<Redirect from="/edit/:id" to="/job/:id" />
<Redirect from="/view/:id" to="/job/:id" />
<Redirect from="/add" to="/job/add" />
<Route exact path="/" component={JobList} />
<Route exact path="/" component={JobAndQueueList} />
<Route path="/job/add" component={JobAdd} />
<Route path="/job/:id" component={JobViewOrEdit} />
<Route path="/queue/add" component={QueueAdd} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/Store/Store.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import StoreContext from './StoreContext'

const Store = ({ children }) => {
// State that should persist
const jobFilterState = useState('')
const jobAndQueueFilterState = useState('')
const showSystemJobsState = useState(false)

return (
<StoreContext.Provider
value={{
jobFilter: jobFilterState,
jobAndQueueFilter: jobAndQueueFilterState,
showSystemJobs: showSystemJobsState,
}}
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Store/StoreContext.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createContext } from 'react'

const StoreContext = createContext({
jobFilter: '',
jobAndQueueFilter: '',
showSystemJobs: false,
})

Expand Down
9 changes: 4 additions & 5 deletions src/components/Store/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { useContext } from 'react'
import StoreContext from './StoreContext'

/**
* The state for the job filter and showing system
* jobs is used in the job list, but kept in the
* store since it has to persist after a refetch.
* These hooks are used in the job and queue list, but are connected
* to the store since they have to persist after a refetch.
*/

export const useJobFilter = () => {
export const useJobAndQueueFilter = () => {
const store = useContext(StoreContext)
return store.jobFilter
return store.jobAndQueueFilter
}

export const useShowSystemJobs = () => {
Expand Down
14 changes: 7 additions & 7 deletions src/components/Store/hooks.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React from 'react'
import { renderHook } from '@testing-library/react-hooks'
import { useJobFilter, useShowSystemJobs } from './hooks'
import { useJobAndQueueFilter, useShowSystemJobs } from './hooks'
import StoreContext from './StoreContext'

describe('useJobFilter', () => {
it('should return the jobFilter part of the store', () => {
const jobFilter = 'jobFilter'
describe('useJobAndQueueFilter', () => {
it('should return the jobAndQueueFilter part of the store', () => {
const jobAndQueueFilter = 'jobAndQueueFilter'
const store = {
jobFilter,
jobAndQueueFilter,
}
const wrapper = ({ children }) => (
<StoreContext.Provider value={store}>
{children}
</StoreContext.Provider>
)
const { result } = renderHook(() => useJobFilter(), { wrapper })
const { result } = renderHook(() => useJobAndQueueFilter(), { wrapper })

expect(result.current).toBe(jobFilter)
expect(result.current).toBe(jobAndQueueFilter)
})
})

Expand Down
4 changes: 2 additions & 2 deletions src/components/Store/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useJobFilter, useShowSystemJobs } from './hooks'
import { useJobAndQueueFilter, useShowSystemJobs } from './hooks'

export { default as Store } from './Store'
export { useJobFilter, useShowSystemJobs }
export { useJobAndQueueFilter, useShowSystemJobs }
4 changes: 2 additions & 2 deletions src/pages/JobAdd/JobAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { JobAddFormContainer } from '../../components/Forms'
import styles from './JobAdd.module.css'

const infoLink =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'

const JobAdd = () => {
return (
Expand All @@ -27,7 +27,7 @@ const JobAdd = () => {
<span className={styles.cardHeaderInfo}>
<IconInfo16 />
</span>
{i18n.t('About job configuration')}
{i18n.t('About the scheduler')}
</a>
</header>
<JobAddFormContainer />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@ import React from 'react'
import { NoticeBox, Card, Checkbox, InputField, IconInfo16 } from '@dhis2/ui'
import i18n from '@dhis2/d2-i18n'
import { useJobsAndQueues } from '../../hooks/jobs-and-queues'
import { useJobFilter, useShowSystemJobs } from '../../components/Store'
import { useJobAndQueueFilter, useShowSystemJobs } from '../../components/Store'
import { JobTable } from '../../components/JobTable'
import { LinkButton } from '../../components/LinkButton'
import { Spinner } from '../../components/Spinner'
import styles from './JobList.module.css'
import filterJobs from './filter-jobs'
import styles from './JobAndQueueList.module.css'
import filterJobsAndQueues from './filter-jobs-and-queues'

const infoLink =
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-236/maintaining-the-system/scheduling.html'
'https://docs.dhis2.org/en/use/user-guides/dhis-core-version-master/maintaining-the-system/scheduling.html'

const JobList = () => {
const [jobFilter, setJobFilter] = useJobFilter()
const JobAndQueueList = () => {
const [jobAndQueueFilter, setJobAndQueueFilter] = useJobAndQueueFilter()
const [showSystemJobs, setShowSystemJobs] = useShowSystemJobs()
const { data, loading, error, refetch } = useJobsAndQueues()

Expand All @@ -23,16 +23,20 @@ const JobList = () => {

if (error) {
return (
<NoticeBox error title={i18n.t('Could not load jobs')}>
<NoticeBox error title={i18n.t('Could not load jobs and queues')}>
{i18n.t(
'Something went wrong whilst loading the jobs. Try refreshing the page.'
'Something went wrong whilst loading the jobs and queues. Try refreshing the page.'
)}
</NoticeBox>
)
}

// Apply the current filter settings
const jobsAndQueues = filterJobs({ jobFilter, showSystemJobs, jobs: data })
const jobsAndQueues = filterJobsAndQueues({
jobAndQueueFilter,
showSystemJobs,
jobsAndQueues: data,
})

return (
<React.Fragment>
Expand All @@ -49,21 +53,21 @@ const JobList = () => {
<span className={styles.headerLinkIcon}>
<IconInfo16 />
</span>
{i18n.t('About job configuration')}
{i18n.t('About the scheduler')}
</a>
</header>
<Card>
<div className={styles.controlContainer}>
<InputField
dataTest="job-filter-input"
label={i18n.t('Filter jobs')}
dataTest="name-filter-input"
label={i18n.t('Filter by name')}
onChange={({ value }) => {
setJobFilter(value)
setJobAndQueueFilter(value)
}}
value={jobFilter}
value={jobAndQueueFilter}
type="search"
role="searchbox"
name="job-filter"
name="name-filter"
/>
<div className={styles.controlRight}>
<Checkbox
Expand All @@ -88,4 +92,4 @@ const JobList = () => {
)
}

export default JobList
export default JobAndQueueList
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import React from 'react'
import { shallow } from 'enzyme'
import { useJobsAndQueues } from '../../hooks/jobs-and-queues'
import JobList from './JobList'
import JobAndQueueList from './JobAndQueueList'

jest.mock('../../hooks/jobs-and-queues', () => ({
useJobsAndQueues: jest.fn(),
}))

jest.mock('../../components/Store', () => ({
useJobFilter: jest.fn(() => ['', () => {}]),
useJobAndQueueFilter: jest.fn(() => ['', () => {}]),
useShowSystemJobs: jest.fn(() => [false, () => {}]),
}))

describe('<JobList>', () => {
describe('<JobAndQueueList>', () => {
it('renders a spinner when loading the jobs and queues', () => {
useJobsAndQueues.mockImplementation(() => ({ loading: true }))

const wrapper = shallow(<JobList />)
const wrapper = shallow(<JobAndQueueList />)
const spinner = wrapper.find('Spinner')

expect(spinner).toHaveLength(1)
Expand All @@ -28,7 +28,7 @@ describe('<JobList>', () => {
error: new Error('Something went wrong'),
}))

const wrapper = shallow(<JobList />)
const wrapper = shallow(<JobAndQueueList />)
const noticebox = wrapper.find('NoticeBox')

expect(noticebox).toHaveLength(1)
Expand All @@ -47,7 +47,7 @@ describe('<JobList>', () => {
refetch: () => {},
}))

const wrapper = shallow(<JobList />)
const wrapper = shallow(<JobAndQueueList />)
const jobtable = wrapper.find('JobTable')

expect(jobtable).toHaveLength(1)
Expand Down
20 changes: 20 additions & 0 deletions src/pages/JobAndQueueList/filter-jobs-and-queues.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const filterJobsAndQueues = ({
jobAndQueueFilter,
showSystemJobs,
jobsAndQueues,
}) => {
// Filter jobs and queues by the current jobAndQueueFilter
const applyJobAndQueueFilter = (jobOrQueue) =>
jobOrQueue.name.toLowerCase().includes(jobAndQueueFilter.toLowerCase())

// Filter jobs depending on the current showSystemJobs
const applyShowSystemJobs = (jobOrQueue) =>
// Jobs that are configurable are user jobs
showSystemJobs ? true : jobOrQueue.configurable

return jobsAndQueues
.filter(applyJobAndQueueFilter)
.filter(applyShowSystemJobs)
}

export default filterJobsAndQueues
Loading

0 comments on commit 7a20811

Please sign in to comment.