Skip to content

Commit

Permalink
Fix statuses handing in StandardPage component of k8s API for retreiv…
Browse files Browse the repository at this point in the history
…ing 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 <[email protected]>
  • Loading branch information
sgratch committed Aug 22, 2024
1 parent 509aa55 commit 3181677
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ export function StandardPage<T>({
[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;

Expand Down Expand Up @@ -444,7 +444,7 @@ export function StandardPage<T>({
toId={toId}
expandedIds={expandedIds}
>
{!loaded && <Loading key="loading" title={t('Loading')} />}
{!loaded && !error && <Loading key="loading" title={t('Loading')} />}
{errorFetchingData && <ErrorState key="error" title={t('Unable to retrieve data')} />}
{noResults &&
(customNoResultsFound ?? (
Expand Down

0 comments on commit 3181677

Please sign in to comment.