From 624f1a84d22359b71bef697631ec9d89b31f45a2 Mon Sep 17 00:00:00 2001 From: Youssef Khedher Date: Mon, 17 Jan 2022 12:39:10 +0100 Subject: [PATCH] feat: add dont show again when update prod env (#588) * feat: add dont show again when update prod env * fix: remove unused dependency * fix: update key Co-authored-by: Fredrik Oseberg --- .../FeatureStrategiesConfigure.tsx | 11 +++++--- .../FeatureStrategiesEnvironmentList.tsx | 7 +++++- .../FeatureStrategiesProductionGuard.tsx | 25 ++++++++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesConfigure/FeatureStrategiesConfigure.tsx b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesConfigure/FeatureStrategiesConfigure.tsx index e83070d3be..2686eaa42b 100644 --- a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesConfigure/FeatureStrategiesConfigure.tsx +++ b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesConfigure/FeatureStrategiesConfigure.tsx @@ -9,7 +9,9 @@ import FeatureStrategyAccordion from '../../FeatureStrategyAccordion/FeatureStra import useFeatureStrategyApi from '../../../../../../hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi'; import { useStyles } from './FeatureStrategiesConfigure.styles'; -import FeatureStrategiesProductionGuard from '../FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard'; +import FeatureStrategiesProductionGuard, { + FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING, +} from '../FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard'; import { IFeatureViewParams } from '../../../../../../interfaces/params'; import cloneDeep from 'lodash.clonedeep'; import { PRODUCTION } from '../../../../../../constants/environmentTypes'; @@ -26,7 +28,10 @@ const FeatureStrategiesConfigure = () => { const { refetch } = useFeature(projectId, featureId); const [productionGuard, setProductionGuard] = useState(false); - + const dontShow = JSON.parse( + localStorage.getItem(FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING) || + 'false' + ); const styles = useStyles(); const { activeEnvironment, @@ -51,7 +56,7 @@ const FeatureStrategiesConfigure = () => { }; const resolveSubmit = () => { - if (activeEnvironment.type === PRODUCTION) { + if (activeEnvironment.type === PRODUCTION && !dontShow) { setProductionGuard(true); return; } diff --git a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironmentList/FeatureStrategiesEnvironmentList.tsx b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironmentList/FeatureStrategiesEnvironmentList.tsx index d92c285814..e3c38c9896 100644 --- a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironmentList/FeatureStrategiesEnvironmentList.tsx +++ b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesEnvironmentList/FeatureStrategiesEnvironmentList.tsx @@ -17,6 +17,7 @@ import { getStrategyObject } from '../../../../../../utils/get-strategy-object'; import { useStyles } from './FeatureStrategiesEnvironmentList.styles'; import FeatureOverviewEnvSwitch from '../../../FeatureOverview/FeatureOverviewEnvSwitches/FeatureOverviewEnvSwitch/FeatureOverviewEnvSwitch'; +import { FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING } from '../FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard'; interface IFeatureStrategiesEnvironmentListProps { strategies: IFeatureStrategy[]; @@ -31,6 +32,10 @@ const FeatureStrategiesEnvironmentList = ({ }: IFeatureStrategiesEnvironmentListProps) => { const styles = useStyles(); const { strategies: selectableStrategies } = useStrategies(); + const dontShow = JSON.parse( + localStorage.getItem(FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING) || + 'false' + ); const { activeEnvironmentsRef, @@ -94,7 +99,7 @@ const FeatureStrategiesEnvironmentList = ({ }); const resolveUpdateStrategy = (strategy: IFeatureStrategy, callback) => { - if (activeEnvironmentsRef?.current?.type === PRODUCTION) { + if (activeEnvironmentsRef?.current?.type === PRODUCTION && !dontShow) { setProductionGuard({ show: true, strategy, callback }); return; } diff --git a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard.tsx b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard.tsx index 265842f2cb..b58d3ab65b 100644 --- a/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard.tsx +++ b/frontend/src/component/feature/FeatureView2/FeatureStrategies/FeatureStrategiesEnvironments/FeatureStrategiesProductionGuard/FeatureStrategiesProductionGuard.tsx @@ -1,6 +1,11 @@ +import { Checkbox, FormControlLabel } from '@material-ui/core'; import { Alert } from '@material-ui/lab'; +import { useState } from 'react'; import Dialogue from '../../../../../common/Dialogue'; +export const FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING = + 'FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING'; + interface IFeatureStrategiesProductionGuard { show: boolean; onClick: () => void; @@ -16,6 +21,19 @@ const FeatureStrategiesProductionGuard = ({ primaryButtonText, loading, }: IFeatureStrategiesProductionGuard) => { + const [checked, setIsChecked] = useState( + JSON.parse( + localStorage.getItem(FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING) || + 'false' + ) + ); + const handleOnchange = () => { + setIsChecked(!checked); + localStorage.setItem( + FEATURE_STRATEGY_PRODUCTION_GUARD_SETTING, + (!checked).toString() + ); + }; return ( -

Are you sure you want to proceed?

+ + } + />
); };