From b5072928b3945fe70f5144bc26b6659020fce862 Mon Sep 17 00:00:00 2001 From: Youssef Date: Fri, 15 Oct 2021 10:52:35 +0100 Subject: [PATCH] fix:handle non-existing feature toggle --- frontend/src/component/App.tsx | 37 ++-- .../feature/FeatureView2/FeatureView2.tsx | 176 ++++++++++-------- 2 files changed, 126 insertions(+), 87 deletions(-) diff --git a/frontend/src/component/App.tsx b/frontend/src/component/App.tsx index f6499be5a2..9ed8fce469 100644 --- a/frontend/src/component/App.tsx +++ b/frontend/src/component/App.tsx @@ -75,17 +75,32 @@ const App = ({ location, user, fetchUiBootstrap, feedback }: IAppProps) => { }; return ( - { - if (!isUnauthorized()) { - setToastData({ - show: true, - type: 'error', - text: error.message, - }); - } - }, - }}> + { + // Never retry on 404. + if (error.status === 404) { + return error; + } + setTimeout(() => revalidate({ retryCount }), 5000); + }, + onError: error => { + if (!isUnauthorized()) { + setToastData({ + show: true, + type: 'error', + text: error.message, + }); + } + }, + }} + >
diff --git a/frontend/src/component/feature/FeatureView2/FeatureView2.tsx b/frontend/src/component/feature/FeatureView2/FeatureView2.tsx index 28715ba501..5db9e05518 100644 --- a/frontend/src/component/feature/FeatureView2/FeatureView2.tsx +++ b/frontend/src/component/feature/FeatureView2/FeatureView2.tsx @@ -18,10 +18,12 @@ import FeatureVariants from './FeatureVariants/FeatureVariants'; import { useStyles } from './FeatureView2.styles'; import FeatureSettings from './FeatureSettings/FeatureSettings'; import useLoading from '../../../hooks/useLoading'; +import ConditionallyRender from '../../common/ConditionallyRender'; +import { getCreateTogglePath } from '../../../utils/route-path-helpers'; const FeatureView2 = () => { const { projectId, featureId } = useParams(); - const { feature, loading } = useFeature(projectId, featureId); + const { feature, loading, error } = useFeature(projectId, featureId); const { a11yProps } = useTabs(0); const { archiveFeatureToggle } = useFeatureApi(); const { toast, setToastData } = useToast(); @@ -97,82 +99,104 @@ const FeatureView2 = () => { }); }; - return ( -
-
-
-

- {feature.name} -

-
- - - - setShowDelDialog(true)} - > - - -
-
-
-
- - {renderTabs()} - -
+ const renderFeatureNotExist = () => { + return ( +
+

+ The feature {featureId} does not exist. Do + you want to   + create it +  ? +

- - - - - - - archiveToggle()} - open={showDelDialog} - onClose={handleCancel} - primaryButtonText="Archive toggle" - secondaryButtonText="Cancel" - title="Archive feature toggle" - > - Are you sure you want to archive this feature toggle? - - {toast} -
+ ); + }; + + return ( + +
+
+

+ {feature.name} +

+
+ + + + setShowDelDialog(true)} + > + + +
+
+
+
+ + {renderTabs()} + +
+
+ + + + + + + archiveToggle()} + open={showDelDialog} + onClose={handleCancel} + primaryButtonText="Archive toggle" + secondaryButtonText="Cancel" + title="Archive feature toggle" + > + Are you sure you want to archive this feature toggle? + + {toast} +
+ } + elseShow={renderFeatureNotExist()} + /> ); };