From e436cf72e6a4519128abb76e4fbd38b8927689b3 Mon Sep 17 00:00:00 2001 From: Mateusz Kwasniewski Date: Fri, 18 Apr 2025 11:42:43 +0200 Subject: [PATCH] feat: revert to production (#9802) --- .../CleanupReminder/CleanupReminder.test.tsx | 1 + .../CleanupReminder/CleanupReminder.tsx | 44 +++++++++++++------ .../FeatureLifecycle/FeatureLifecycle.tsx | 19 +++----- .../FeatureLifecycle/useUncomplete.ts | 31 +++++++++++++ 4 files changed, 69 insertions(+), 26 deletions(-) create mode 100644 frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/useUncomplete.ts diff --git a/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.test.tsx b/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.test.tsx index c34676bac8..3e26454534 100644 --- a/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.test.tsx +++ b/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.test.tsx @@ -59,6 +59,7 @@ test('render remove flag from code reminder', async () => { }); await screen.findByText('Time to remove flag from code?'); + await screen.findByText('Revert to production'); const reminder = await screen.findByText('Remind me later'); reminder.click(); diff --git a/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.tsx b/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.tsx index 3389eaf02b..5f7cfac9c9 100644 --- a/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.tsx +++ b/frontend/src/component/feature/FeatureView/CleanupReminder/CleanupReminder.tsx @@ -19,6 +19,7 @@ import { FeatureArchiveDialog } from 'component/common/FeatureArchiveDialog/Feat import { useNavigate } from 'react-router-dom'; import { useFlagReminders } from './useFlagReminders'; import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; +import { useUncomplete } from '../FeatureOverview/FeatureLifecycle/useUncomplete'; const StyledBox = styled(Box)(({ theme }) => ({ marginRight: theme.spacing(2), @@ -43,6 +44,11 @@ export const CleanupReminder: FC<{ const [markCompleteDialogueOpen, setMarkCompleteDialogueOpen] = useState(false); const [archiveDialogueOpen, setArchiveDialogueOpen] = useState(false); + const { onUncompleteHandler, loading } = useUncomplete({ + feature: feature.name, + project: feature.project, + onChange, + }); const currentStage = populateCurrentStage(feature); const isRelevantType = @@ -180,19 +186,31 @@ export const CleanupReminder: FC<{ severity='warning' icon={} action={ - + + + + Revert to production + + } > Time to remove flag from code? diff --git a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/FeatureLifecycle.tsx b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/FeatureLifecycle.tsx index 191a8a507b..7b932b5e88 100644 --- a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/FeatureLifecycle.tsx +++ b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/FeatureLifecycle.tsx @@ -1,12 +1,11 @@ import { FeatureLifecycleStageIcon } from 'component/common/FeatureLifecycle/FeatureLifecycleStageIcon'; import { FeatureLifecycleTooltip } from './FeatureLifecycleTooltip'; -import useFeatureLifecycleApi from 'hooks/api/actions/useFeatureLifecycleApi/useFeatureLifecycleApi'; import { populateCurrentStage } from './populateCurrentStage'; import type { FC } from 'react'; import type { Lifecycle } from 'interfaces/featureToggle'; -import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; import { getFeatureLifecycleName } from 'component/common/FeatureLifecycle/getFeatureLifecycleName'; import { Box } from '@mui/material'; +import { useUncomplete } from './useUncomplete'; export interface LifecycleFeature { lifecycle?: Lifecycle; @@ -28,18 +27,12 @@ export const FeatureLifecycle: FC<{ expanded?: boolean; }> = ({ feature, expanded, onComplete, onUncomplete, onArchive }) => { const currentStage = populateCurrentStage(feature); - const { markFeatureUncompleted, loading } = useFeatureLifecycleApi(); - const { trackEvent } = usePlausibleTracker(); - const onUncompleteHandler = async () => { - await markFeatureUncompleted(feature.name, feature.project); - onUncomplete?.(); - trackEvent('feature-lifecycle', { - props: { - eventType: 'uncomplete', - }, - }); - }; + const { onUncompleteHandler, loading } = useUncomplete({ + feature: feature.name, + project: feature.project, + onChange: onUncomplete, + }); return currentStage ? ( ({ display: 'flex', gap: theme.spacing(0.5) })}> diff --git a/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/useUncomplete.ts b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/useUncomplete.ts new file mode 100644 index 0000000000..ecbc143428 --- /dev/null +++ b/frontend/src/component/feature/FeatureView/FeatureOverview/FeatureLifecycle/useUncomplete.ts @@ -0,0 +1,31 @@ +import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; +import useToast from 'hooks/useToast'; +import useFeatureLifecycleApi from 'hooks/api/actions/useFeatureLifecycleApi/useFeatureLifecycleApi'; +import { formatUnknownError } from 'utils/formatUnknownError'; + +export const useUncomplete = ({ + feature, + project, + onChange, +}: { feature: string; project: string; onChange?: () => void }) => { + const { trackEvent } = usePlausibleTracker(); + const { setToastApiError } = useToast(); + const { markFeatureUncompleted, loading } = useFeatureLifecycleApi(); + + const onUncompleteHandler = async () => { + try { + await markFeatureUncompleted(feature, project); + onChange?.(); + + trackEvent('feature-lifecycle', { + props: { + eventType: 'uncomplete', + }, + }); + } catch (e) { + setToastApiError(formatUnknownError(e)); + } + }; + + return { onUncompleteHandler, loading }; +};