From 31816775d199037e28610b42fdac9822fab790ab Mon Sep 17 00:00:00 2001 From: Sharon Gratch Date: Thu, 22 Aug 2024 16:20:31 +0300 Subject: [PATCH] Fix statuses handing in StandardPage component of k8s API for retreiving resources When calling k8s hook APIs for retreiving resources, the API returns 2 statuses: loaded and error. See https://github.com/openshift/console/blob/master/frontend/packages/console-dynamic-plugin-sdk/src/utils/k8s/hooks/useK8sWatchResources.ts Based on the code and on debugging, if an error status is returned setting to true, the loaded status is not nessesarily set to true as well. Therefore, fixing this in StandardPage component is required to display an API failure's error message of "Unable to retrieve data" in the center of the page insead of keep rendering a Loading component. For example, in the edge case scenrio of a non admin user that trying to list the "all namespaces" resources, the API returns an error of "403 Forbidden" and loaded is returned set to false. The providers page appears as follows before the fix: And after the fix: Signed-off-by: Sharon Gratch --- .../src/components/page/StandardPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/forklift-console-plugin/src/components/page/StandardPage.tsx b/packages/forklift-console-plugin/src/components/page/StandardPage.tsx index 55263bb47..226fecec0 100644 --- a/packages/forklift-console-plugin/src/components/page/StandardPage.tsx +++ b/packages/forklift-console-plugin/src/components/page/StandardPage.tsx @@ -333,7 +333,7 @@ export function StandardPage({ [filteredData, currentPage, itemsPerPage], ); - const errorFetchingData = loaded && error; + const errorFetchingData = error; const noResults = loaded && !error && sortedData.length == 0; const noMatchingResults = loaded && !error && filteredData.length === 0 && sortedData.length > 0; @@ -444,7 +444,7 @@ export function StandardPage({ toId={toId} expandedIds={expandedIds} > - {!loaded && } + {!loaded && !error && } {errorFetchingData && } {noResults && (customNoResultsFound ?? (