-
Notifications
You must be signed in to change notification settings - Fork 4
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
Add AbortSignal to OpenSRPServer service #625
Changes from 23 commits
b73a191
a03c96b
73fa70d
c232cbf
37e4376
99b908f
d75fd4b
15f060d
a2a23c1
daaede0
3cb4eed
319b660
6d24bf6
64d18ea
c93e1be
986710f
af29459
d3a19bc
c2c724b
abeb790
16eba72
652ac54
99cd428
237931c
c33e1cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import ListView from '@onaio/list-view'; | ||
import reducerRegistry, { Registry } from '@onaio/redux-reducer-registry'; | ||
import React, { useEffect, useState } from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
|
@@ -22,6 +22,7 @@ import { planStatusDisplay } from '../../../../configs/settings'; | |
import { | ||
ASSIGN_PLAN_URL, | ||
HOME_URL, | ||
OPENSRP_PLANS, | ||
PLAN_RECORD_BY_ID, | ||
REPORT_IRS_PLAN_URL, | ||
} from '../../../../constants'; | ||
|
@@ -43,21 +44,21 @@ import { | |
/** register the plan definitions reducer */ | ||
reducerRegistry.register(IRSPlansReducerName, IRSPlansReducer); | ||
|
||
const OpenSrpPlanService = new OpenSRPService('plans'); | ||
|
||
/** Plans filter selector */ | ||
const plansArraySelector = makePlansArraySelector(PLAN_RECORD_BY_ID); | ||
|
||
/** interface for PlanAssignmentsListProps props */ | ||
interface PlanAssignmentsListProps { | ||
fetchPlans: typeof fetchPlanRecords; | ||
plans: PlanRecord[]; | ||
service: typeof OpenSRPService; | ||
} | ||
|
||
/** Simple component that loads plans and allows you to manage plan-jurisdiciton-organization assignments */ | ||
/** Simple component that loads plans and allows you to manage plan-jurisdiction-organization assignments */ | ||
const IRSAssignmentPlansList = (props: PlanAssignmentsListProps) => { | ||
const { fetchPlans, plans } = props; | ||
const [loading, setLoading] = useState<boolean>(plans.length < 1); | ||
const { fetchPlans, plans, service } = props; | ||
|
||
const OpenSrpPlanService = new service(OPENSRP_PLANS); | ||
|
||
const pageTitle: string = `${ASSIGN_PLANS}`; | ||
|
||
|
@@ -77,7 +78,6 @@ const IRSAssignmentPlansList = (props: PlanAssignmentsListProps) => { | |
/** async function to load the data */ | ||
async function loadData() { | ||
try { | ||
setLoading(plans.length < 1); // only set loading when there are no plans | ||
await OpenSrpPlanService.list() | ||
.then(planResults => { | ||
if (planResults) { | ||
|
@@ -89,7 +89,6 @@ const IRSAssignmentPlansList = (props: PlanAssignmentsListProps) => { | |
.catch(err => { | ||
displayError(err); | ||
}); | ||
setLoading(false); | ||
} catch (e) { | ||
displayError(e); | ||
} | ||
|
@@ -99,7 +98,7 @@ const IRSAssignmentPlansList = (props: PlanAssignmentsListProps) => { | |
loadData().catch(error => displayError(error)); | ||
}, []); | ||
|
||
if (loading) { | ||
if (plans.length < 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we get 0 plans from the API, does this mean we will show the loading indicator forever? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i was thinking about this wrong. let me refactor. |
||
return <Loading />; | ||
} | ||
cKellyDesign marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
@@ -147,6 +146,7 @@ const IRSAssignmentPlansList = (props: PlanAssignmentsListProps) => { | |
const defaultProps: PlanAssignmentsListProps = { | ||
fetchPlans: fetchPlanRecords, | ||
plans: [], | ||
service: OpenSRPService, | ||
}; | ||
|
||
IRSAssignmentPlansList.defaultProps = defaultProps; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import ListView from '@onaio/list-view'; | ||
import reducerRegistry from '@onaio/redux-reducer-registry'; | ||
import React, { useEffect, useState } from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import { connect } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
|
@@ -41,7 +41,6 @@ interface PlanListProps { | |
/** Simple component that loads the new plan form and allows you to create a new plan */ | ||
const PlanDefinitionList = (props: PlanListProps) => { | ||
const { fetchPlans, plans, service } = props; | ||
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
const apiService = new service(OPENSRP_PLANS); | ||
|
||
|
@@ -63,21 +62,18 @@ const PlanDefinitionList = (props: PlanListProps) => { | |
/** async function to load the data */ | ||
async function loadData() { | ||
try { | ||
setLoading(plans.length < 1); // only set loading when there are no plans | ||
const planObjects = await apiService.list(); | ||
fetchPlans(planObjects); | ||
} catch (e) { | ||
displayError(e); | ||
} finally { | ||
setLoading(false); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
loadData().catch(err => displayError(err)); | ||
}, []); | ||
|
||
if (loading === true) { | ||
if (plans.length < 1) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we get 0 plans from the API, does this mean we will show the loading indicator forever? |
||
return <Loading />; | ||
} | ||
cKellyDesign marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import reducerRegistry from '@onaio/redux-reducer-registry'; | ||
import React, { useEffect, useState } from 'react'; | ||
import React, { useEffect } from 'react'; | ||
import { Helmet } from 'react-helmet'; | ||
import { connect } from 'react-redux'; | ||
import { RouteComponentProps } from 'react-router'; | ||
|
@@ -46,7 +46,6 @@ export interface RouteParams { | |
const UpdatePlan = (props: RouteComponentProps<RouteParams> & UpdatePlanProps) => { | ||
const { fetchPlan, plan, service } = props; | ||
const planIdentifier = props.match.params.id; | ||
const [loading, setLoading] = useState<boolean>(true); | ||
|
||
if (!planIdentifier) { | ||
return null; /** we should make this into a better error page */ | ||
|
@@ -56,22 +55,19 @@ const UpdatePlan = (props: RouteComponentProps<RouteParams> & UpdatePlanProps) = | |
/** async function to load the data */ | ||
async function loadData() { | ||
try { | ||
setLoading(plan === null); // only set loading when there are no plans | ||
const planFromAPI = await apiService.read(planIdentifier); | ||
const currentPlan = Array.isArray(planFromAPI) ? planFromAPI[0] : planFromAPI; | ||
fetchPlan(currentPlan); | ||
} catch (e) { | ||
displayError(e); | ||
} finally { | ||
setLoading(false); | ||
} | ||
} | ||
|
||
useEffect(() => { | ||
loadData().catch(err => displayError(err)); | ||
}, []); | ||
|
||
if (loading === true) { | ||
if (plan === null) { | ||
Comment on lines
-74
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why this change? |
||
return <Loading />; | ||
} | ||
cKellyDesign marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,9 +47,7 @@ describe('src/containers/pages/OrganizationViews/helpers/servicehooks', () => { | |
mockClass, | ||
fetchPractitionerRolesMock, | ||
fetchPractitionersMock | ||
).catch(e => { | ||
throw e; | ||
}); | ||
).catch(err => err); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Naah!, this is part of the test, I want the error to actually fail the test. |
||
await flushPromises(); | ||
|
||
// calls the correct endpoint | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to add a test that
displayError
is, in fact, called?