Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove duplicated API calls [DHIS2-14112] #169

Merged
merged 6 commits into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 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-05-29T16:48:00.591Z\n"
"PO-Revision-Date: 2023-05-29T16:48:00.591Z\n"
"POT-Creation-Date: 2023-07-05T09:36:08.695Z\n"
"PO-Revision-Date: 2023-07-05T09:36:08.695Z\n"

msgid ""
"The initial configuration of the app has been completed and it is now ready "
Expand Down Expand Up @@ -974,3 +974,6 @@ msgstr "Check the amount of data a user would sync to their device."

msgid "User"
msgstr "User"

msgid "Failed to get data"
msgstr "Failed to get data"
5 changes: 2 additions & 3 deletions src/components/analyticVisualization/SelectDataset.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'
import { useReadDatasetQuery } from '../../pages/Analytics/Dataset/DatasetVisualizationQuery'
import { useWorkflowContext } from '../../workflow-context'
import { SelectField } from '../field'

export const SelectDataset = ({ settings, onChange }) => {
const { datasetList, loading } = useReadDatasetQuery()
const { dataSets: datasetList } = useWorkflowContext()
const options = datasetList || []

const handleChange = (e) => {
Expand All @@ -26,7 +26,6 @@ export const SelectDataset = ({ settings, onChange }) => {
selected={settings.dataset || ''}
onChange={handleChange}
options={options}
loading={loading}
/>
)
}
Expand Down
5 changes: 2 additions & 3 deletions src/components/analyticVisualization/SelectProgram.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import i18n from '@dhis2/d2-i18n'
import PropTypes from 'prop-types'
import React from 'react'
import { useReadProgramQuery } from '../../pages/Analytics/Program/ProgramVisualizationQueries'
import { useWorkflowContext } from '../../workflow-context'
import { SelectField } from '../field'

export const SelectProgram = ({ settings, onChange }) => {
const { programList, loading } = useReadProgramQuery()
const { programs: programList } = useWorkflowContext()
const options = programList || []

const handleChange = (e) => {
Expand All @@ -25,7 +25,6 @@ export const SelectProgram = ({ settings, onChange }) => {
label={i18n.t('Program')}
selected={settings.program || ''}
onChange={handleChange}
loading={loading}
options={options}
/>
)
Expand Down
4 changes: 2 additions & 2 deletions src/pages/Analytics/Dataset/DatasetAnalyticList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import { DatasetTable } from '../../../components/analyticVisualization'
import { NoticeError } from '../../../components/noticeAlert'
import { useWorkflowContext } from '../../../workflow-context'
import { getVisualizationIdList } from '../helper'
import { useVisualizations } from '../VisualizationQuery'
import { useReadDatasetQuery } from './DatasetVisualizationQuery'
import { prepareRows, rowsToDataStore } from './helper'
import NewDatasetVisualization from './NewDatasetVisualization'

Expand All @@ -22,7 +22,7 @@ const DatasetAnalyticList = ({
error,
visualizations: visualizationAPI,
} = useVisualizations(getVisualizationIdList(visualizations))
const { datasetList } = useReadDatasetQuery()
const { dataSets: datasetList } = useWorkflowContext()
const [rows, setRows] = useState()
const [initialRows, setInitialRows] = useState()
const [groups, setGroups] = useState()
Expand Down
25 changes: 0 additions & 25 deletions src/pages/Analytics/Dataset/DatasetVisualizationQuery.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/pages/Analytics/Program/ProgramAnalyticsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import { ProgramTable } from '../../../components/analyticVisualization'
import { NoticeError } from '../../../components/noticeAlert'
import { useWorkflowContext } from '../../../workflow-context'
import { getVisualizationIdList } from '../helper'
import { useVisualizations } from '../VisualizationQuery'
import { prepareRows, rowsToDataStore } from './helper'
import NewProgramVisualization from './NewProgramVisualization'
import { useReadProgramQuery } from './ProgramVisualizationQueries'

const ProgramAnalyticsList = ({
visualizations,
Expand All @@ -22,7 +22,7 @@ const ProgramAnalyticsList = ({
error,
visualizations: visualizationAPI,
} = useVisualizations(getVisualizationIdList(visualizations))
const { programList } = useReadProgramQuery()
const { programs: programList } = useWorkflowContext()
const [rows, setRows] = useState()
const [initialRows, setInitialRows] = useState()
const [groups, setGroups] = useState()
Expand Down
21 changes: 0 additions & 21 deletions src/pages/Analytics/Program/ProgramVisualizationQueries.js

This file was deleted.

5 changes: 4 additions & 1 deletion src/pages/AppLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AuthWall } from '../auth'
import Router from '../components/Router'
import SideBar from '../components/sidebar/Sidebar'
import styles from '../styles/Layout.module.css'
import { WorkflowProvider } from '../workflow-context'

const AppLayout = () => (
<HashRouter>
Expand All @@ -15,7 +16,9 @@ const AppLayout = () => (
<SideBar />
</div>
<div className={styles.content}>
<Router />
<WorkflowProvider>
<Router />
</WorkflowProvider>
</div>
</div>
</AuthWall>
Expand Down
12 changes: 8 additions & 4 deletions src/pages/Appearance/Datasets/DatasetSpecificSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import keyBy from 'lodash/keyBy'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import PageSubtitle from '../../../components/page/PageSubtitle'
import { filterUnusedElements } from '../../../utils/utils'
import { useReadDataset } from './datasetQuery'
import {
filterListByDataWriteAccess,
filterUnusedElements,
} from '../../../utils/utils'
import { useWorkflowContext } from '../../../workflow-context'
import { prepareSpecificSettingsList } from './helper'
import NewDatasetSettings from './NewDatasetSettings'
import SpecificTableAction from './SpecificTableAction'

const DatasetSpecificSettings = ({ onChange, specificSettings, disabled }) => {
const { datasetList } = useReadDataset()
const { dataSets } = useWorkflowContext()
const datasetList = filterListByDataWriteAccess(dataSets)
const [initialRows, setInitialRows] = useState()
const [rows, setRows] = useState()
const [listName, setListName] = useState()
Expand All @@ -28,7 +32,7 @@ const DatasetSpecificSettings = ({ onChange, specificSettings, disabled }) => {
setListName(filterUnusedElements(datasetList, updated))
setLoad(true)
}
}, [specificSettings, datasetList])
}, [specificSettings])

useEffect(() => {
if (rows && !isEqual(rows, initialRows)) {
Expand Down
25 changes: 0 additions & 25 deletions src/pages/Appearance/Datasets/datasetQuery.js

This file was deleted.

12 changes: 8 additions & 4 deletions src/pages/Synchronization/Datasets/DatasetSpecificSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import keyBy from 'lodash/keyBy'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import PageHeader from '../../../components/page/PageHeader'
import { filterUnusedElements } from '../../../utils/utils'
import { useReadDataset } from './datasetQueries'
import {
filterListByReadAccess,
filterUnusedElements,
} from '../../../utils/utils'
import { useWorkflowContext } from '../../../workflow-context'
import { prepareSpecificSettingsList } from './helper'
import NewDatasetSpecific from './NewDatasetSpecific'
import SpecificTableAction from './SpecificTableAction'
Expand All @@ -15,8 +18,9 @@ const DatasetSpecificSettings = ({
handleSpecificSettings,
disabled,
}) => {
const { datasetList } = useReadDataset()
const { dataSets } = useWorkflowContext()
const [rows, setRows] = useState()
const datasetList = filterListByReadAccess(dataSets)
const [initialRows, setInitialRows] = useState()
const [listName, setListName] = useState()
const [loadSpecific, setLoad] = useState(false)
Expand All @@ -32,7 +36,7 @@ const DatasetSpecificSettings = ({
setListName(filterUnusedElements(datasetList, rowList))
setLoad(true)
}
}, [specificSettings, datasetList])
}, [specificSettings])

useEffect(() => {
if (rows && initialRows && !isEqual(rows, initialRows)) {
Expand Down
26 changes: 0 additions & 26 deletions src/pages/Synchronization/Datasets/datasetQueries.js

This file was deleted.

12 changes: 8 additions & 4 deletions src/pages/Synchronization/Programs/ProgramSpecificSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import keyBy from 'lodash/keyBy'
import PropTypes from 'prop-types'
import React, { useEffect, useState } from 'react'
import PageHeader from '../../../components/page/PageHeader'
import { filterUnusedElements } from '../../../utils/utils'
import {
filterListByReadAccess,
filterUnusedElements,
} from '../../../utils/utils'
import { useWorkflowContext } from '../../../workflow-context'
import { prepareSpecificSettingsList } from './helper'
import NewProgramSpecific from './NewProgramSpecific'
import { useReadProgram } from './programQueries'
import SpecificTableAction from './SpecificTableAction'

const ProgramSpecificSettings = ({
specificSettings,
changeSpecificSettings,
disabled,
}) => {
const { programList } = useReadProgram()
const { programs } = useWorkflowContext()
const programList = filterListByReadAccess(programs)
const [rows, setRows] = useState()
const [initialRows, setInitialRows] = useState()
const [listName, setListName] = useState()
Expand All @@ -32,7 +36,7 @@ const ProgramSpecificSettings = ({
setListName(filterUnusedElements(programList, rowList))
setLoad(true)
}
}, [specificSettings, programList])
}, [specificSettings])

useEffect(() => {
if (rows && initialRows && !isEqual(rows, initialRows)) {
Expand Down
25 changes: 0 additions & 25 deletions src/pages/Synchronization/Programs/programQueries.js

This file was deleted.

7 changes: 7 additions & 0 deletions src/utils/utils/filterListByAccess.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import filter from 'lodash/filter'

export const filterListByReadAccess = (list) =>
filter(list, { access: { read: true } })

export const filterListByDataWriteAccess = (list) =>
filter(list, { access: { data: { write: true } } })
1 change: 1 addition & 0 deletions src/utils/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './filterListByAccess'
export * from './filterUnusedElements'
export * from './findProgramNameById'
export * from './formatList'
Expand Down
8 changes: 8 additions & 0 deletions src/workflow-context/WorkflowContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createContext } from 'react'

const WorkflowContext = createContext({
programs: [],
dataSets: [],
})

export { WorkflowContext }
Loading
Loading