From e3ed60f230a192b4659573ea129115a87ac4dfbe Mon Sep 17 00:00:00 2001 From: ifirmawan Date: Fri, 10 Mar 2023 16:30:56 +0700 Subject: [PATCH] [#5230] Fix bug standalone project hierarchy Solved by checking the number of UUIDs and setting loading false when the program is not found and doesn't have children. --- .../spa/app/modules/hierarchy/hierarchy.jsx | 4 ++++ .../rsr/spa/app/modules/hierarchy/services.js | 24 +++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) 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 0d722e2c63..53208e0b0e 100644 --- a/akvo/rsr/spa/app/modules/hierarchy/services.js +++ b/akvo/rsr/spa/app/modules/hierarchy/services.js @@ -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)