Skip to content

Commit

Permalink
DOP-3733: add warning toast on fetch error (#823)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs authored May 31, 2023
1 parent 856841d commit 906afdf
Show file tree
Hide file tree
Showing 5 changed files with 197 additions and 45 deletions.
182 changes: 175 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
"@leafygreen-ui/tabs": "^8.0.0",
"@leafygreen-ui/text-area": "^6.1.0",
"@leafygreen-ui/text-input": "^10.1.0",
"@leafygreen-ui/toast": "^6.1.4",
"@leafygreen-ui/tooltip": "^7.1.0",
"@leafygreen-ui/typography": "^13.0.0",
"@loadable/component": "^5.14.1",
Expand Down
18 changes: 17 additions & 1 deletion src/components/OpenAPIChangelog/OpenAPIChangelog.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { useEffect, useMemo, useState } from 'react';
import Skeleton from 'react-loading-skeleton';
import { css } from '@leafygreen-ui/emotion';
import styled from '@emotion/styled';
import { palette } from '@leafygreen-ui/palette';
import { Body, H2 } from '@leafygreen-ui/typography';
import Button from '@leafygreen-ui/button';
import { Toast, ToastProvider, Variant } from '@leafygreen-ui/toast';
import { theme } from '../../theme/docsTheme';
import useChangelogData from '../../utils/use-changelog-data';
import FiltersPanel from './components/FiltersPanel';
Expand Down Expand Up @@ -76,8 +78,9 @@ const OpenAPIChangelog = () => {
const [resourceVersionOne, setResourceVersionOne] = useState(resourceVersions[0]);
const [resourceVersionTwo, setResourceVersionTwo] = useState();
const [isLoading, setIsLoading] = useState(false);
const [toastOpen, setToastOpen] = useState(false);

const [diff] = useFetchDiff(resourceVersionOne, resourceVersionTwo, setIsLoading);
const [diff] = useFetchDiff(resourceVersionOne, resourceVersionTwo, setIsLoading, setToastOpen);
const [diffResourcesList, setDiffResourcesList] = useState(getDiffResourcesList(diff));

const [filteredDiff, setFilteredDiff] = useState(diff);
Expand Down Expand Up @@ -166,6 +169,19 @@ const OpenAPIChangelog = () => {
))}
</SkeletonWrapper>
)}
<ToastProvider
portalClassName={css`
z-index: 3;
`}
>
<Toast
title="We've encountered an error fetching this data"
description="Please try again at a later time."
variant={Variant.Warning}
open={toastOpen}
onClose={() => setToastOpen(false)}
/>
</ToastProvider>
</ChangelogPage>
);
};
Expand Down
35 changes: 0 additions & 35 deletions src/components/OpenAPIChangelog/data/mockData.js

This file was deleted.

6 changes: 4 additions & 2 deletions src/components/OpenAPIChangelog/utils/useFetchDiff.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fetchOADiff } from '../../../utils/realm';
import useChangelogData from '../../../utils/use-changelog-data';
import { getDiffRequestFormat } from './getDiffRequestFormat';

export const useFetchDiff = (resourceVersionOne, resourceVersionTwo, setIsLoading) => {
export const useFetchDiff = (resourceVersionOne, resourceVersionTwo, setIsLoading, setToastOpen) => {
const { index = {}, mostRecentDiff = {} } = useChangelogData();
const [diff, setDiff] = useState([]);

Expand All @@ -26,9 +26,11 @@ export const useFetchDiff = (resourceVersionOne, resourceVersionTwo, setIsLoadin
.catch((err) => {
console.error(err);
setIsLoading(false);
setToastOpen(true);
setTimeout(() => setToastOpen(false), 5000);
});
}
}, [resourceVersionOne, resourceVersionTwo, index, setIsLoading, mostRecentDiff]);
}, [resourceVersionOne, resourceVersionTwo, index, mostRecentDiff, setIsLoading, setToastOpen]);

return [diff, setDiff];
};

0 comments on commit 906afdf

Please sign in to comment.