Skip to content

Commit

Permalink
Merge pull request #5244 from akvo/5230-bug-project-hierarchy-page-br…
Browse files Browse the repository at this point in the history
…oken-for-standalone-projects

[#5230] Fix bug standalone project hierarchy
  • Loading branch information
zuhdil authored Mar 15, 2023
2 parents b144f44 + e3ed60f commit d6aa3b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
4 changes: 4 additions & 0 deletions akvo/rsr/spa/app/modules/hierarchy/hierarchy.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 14 additions & 10 deletions akvo/rsr/spa/app/modules/hierarchy/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d6aa3b3

Please sign in to comment.