diff --git a/akvo/rsr/spa/app/modules/hierarchy/hierarchy.jsx b/akvo/rsr/spa/app/modules/hierarchy/hierarchy.jsx index a9d9eab504..d6605814bc 100644 --- a/akvo/rsr/spa/app/modules/hierarchy/hierarchy.jsx +++ b/akvo/rsr/spa/app/modules/hierarchy/hierarchy.jsx @@ -165,6 +165,10 @@ const Hierarchy = ({ match: { params }, program, userRdr, asProjectTab }) => { ]) setLoading(false) } + if (loading && projects && programs?.length === 0 && children?.length === 0) { + setPrograms(projects) + setLoading(false) + } }, [preload, programs, children, projects, selected]) const filterCountry = (item) => countryFilter diff --git a/akvo/rsr/spa/app/modules/hierarchy/services.js b/akvo/rsr/spa/app/modules/hierarchy/services.js index bdfd70fa0c..5387ca4f88 100644 --- a/akvo/rsr/spa/app/modules/hierarchy/services.js +++ b/akvo/rsr/spa/app/modules/hierarchy/services.js @@ -22,16 +22,20 @@ export const getProjectsApi = (id, successCallback, errorCallback) => { .then(({ data }) => { let _uuid = getProjectUuids(data?.path) _uuid = _uuid.slice(0, _uuid.length - 1) - const endpoints = _uuid?.map((uuid) => api.get(`/project/?uuid=${uuid}&format=json`)) - Promise - .all(endpoints) - .then((res) => { - const _projects = res?.flatMap(({ data: { results } }) => results || []) - successCallback(_projects) - }) - .catch((err) => { - errorCallback(err) - }) + if (_uuid?.length) { + const endpoints = _uuid?.map((uuid) => api.get(`/project/?uuid=${uuid}&format=json`)) + Promise + .all(endpoints) + .then((res) => { + const _projects = res?.flatMap(({ data: { results } }) => results || []) + successCallback(_projects) + }) + .catch((err) => { + errorCallback(err) + }) + } else { + successCallback([data]) + } }) .catch((err) => { errorCallback(err)