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

[#5230] Fix bug standalone project hierarchy #5244

Merged
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
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 @@ -26,16 +26,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