From b0ecfd4d34f7aba56f37da6ea062959ee2a7ae28 Mon Sep 17 00:00:00 2001 From: Jaanus Sellin Date: Wed, 24 Jan 2024 21:46:08 +0200 Subject: [PATCH] feat: add plausible change-requests-conflicts (#6024) --- .../ChangeRequestOverview.tsx | 44 ++++++------------- .../ChangeRequestSidebar.tsx | 2 +- .../changeRequest/changeRequest.types.ts | 6 +++ .../useChangeRequestApi.ts | 3 ++ frontend/src/hooks/usePlausibleTracker.ts | 1 - 5 files changed, 24 insertions(+), 32 deletions(-) diff --git a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx index 939648f280..68a7a0b1a5 100644 --- a/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx +++ b/frontend/src/component/changeRequest/ChangeRequestOverview/ChangeRequestOverview.tsx @@ -35,6 +35,7 @@ import { } from './ChangeRequestScheduledDialogs/changeRequestScheduledDialogs'; import { ScheduleChangeRequestDialog } from './ChangeRequestScheduledDialogs/ScheduleChangeRequestDialog'; import { usePlausibleTracker } from 'hooks/usePlausibleTracker'; +import { PlausibleChangeRequestState } from '../changeRequest.types'; const StyledAsideBox = styled(Box)(({ theme }) => ({ width: '30%', @@ -114,13 +115,18 @@ export const ChangeRequestOverview: FC = () => { changeRequest.environment, ); - const hasSchedule = Boolean( - 'schedule' in changeRequest && changeRequest.schedule?.scheduledAt, - ); + const getCurrentState = (): PlausibleChangeRequestState => { + switch (changeRequest.state) { + case 'Scheduled': + return `${changeRequest.state} ${changeRequest.schedule.status}`; + default: + return changeRequest.state; + } + }; const onApplyChanges = async () => { try { - await changeState(projectId, Number(id), { + await changeState(projectId, Number(id), getCurrentState(), { state: 'Applied', }); setShowApplyScheduledDialog(false); @@ -131,24 +137,14 @@ export const ChangeRequestOverview: FC = () => { title: 'Success', text: 'Changes applied', }); - if (hasSchedule) { - trackEvent('scheduled-configuration-changes', { - props: { - action: 'scheduled-applied', - }, - }); - } } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } }; const onScheduleChangeRequest = async (scheduledDate: Date) => { - const plausibleAction = hasSchedule - ? 'scheduled-updated' - : 'scheduled-created'; try { - await changeState(projectId, Number(id), { + await changeState(projectId, Number(id), getCurrentState(), { state: 'Scheduled', scheduledAt: scheduledDate.toISOString(), }); @@ -160,11 +156,6 @@ export const ChangeRequestOverview: FC = () => { title: 'Success', text: 'Changes scheduled', }); - trackEvent('scheduled-configuration-changes', { - props: { - action: plausibleAction, - }, - }); } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } @@ -187,7 +178,7 @@ export const ChangeRequestOverview: FC = () => { const onCancelChanges = async () => { try { - await changeState(projectId, Number(id), { + await changeState(projectId, Number(id), getCurrentState(), { state: 'Cancelled', }); setShowCancelDialog(false); @@ -205,7 +196,7 @@ export const ChangeRequestOverview: FC = () => { const onReject = async (comment?: string) => { try { - await changeState(projectId, Number(id), { + await changeState(projectId, Number(id), getCurrentState(), { state: 'Rejected', comment, }); @@ -217,13 +208,6 @@ export const ChangeRequestOverview: FC = () => { }); refetchChangeRequest(); refetchChangeRequestOpen(); - if (hasSchedule) { - trackEvent('scheduled-configuration-changes', { - props: { - action: 'scheduled-rejected', - }, - }); - } } catch (error: unknown) { setToastApiError(formatUnknownError(error)); } @@ -231,7 +215,7 @@ export const ChangeRequestOverview: FC = () => { const onApprove = async () => { try { - await changeState(projectId, Number(id), { + await changeState(projectId, Number(id), getCurrentState(), { state: 'Approved', }); refetchChangeRequest(); diff --git a/frontend/src/component/changeRequest/ChangeRequestSidebar/ChangeRequestSidebar.tsx b/frontend/src/component/changeRequest/ChangeRequestSidebar/ChangeRequestSidebar.tsx index 0c8bbb5468..3177cb7b07 100644 --- a/frontend/src/component/changeRequest/ChangeRequestSidebar/ChangeRequestSidebar.tsx +++ b/frontend/src/component/changeRequest/ChangeRequestSidebar/ChangeRequestSidebar.tsx @@ -81,7 +81,7 @@ export const ChangeRequestSidebar: VFC = ({ const onReview = async (draftId: number, comment?: string) => { try { - await changeState(project, draftId, { + await changeState(project, draftId, 'Draft', { state: 'In review', comment, }); diff --git a/frontend/src/component/changeRequest/changeRequest.types.ts b/frontend/src/component/changeRequest/changeRequest.types.ts index 79472f965c..6c28f828a5 100644 --- a/frontend/src/component/changeRequest/changeRequest.types.ts +++ b/frontend/src/component/changeRequest/changeRequest.types.ts @@ -100,6 +100,12 @@ export interface IChangeRequestChangeBase { }; } +export type PlausibleChangeRequestState = + | Exclude + | 'Scheduled pending' + | 'Scheduled failed' + | 'Scheduled suspended'; + export type ChangeRequestState = | 'Draft' | 'Approved' diff --git a/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts b/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts index fb525030bd..00dddaa015 100644 --- a/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts +++ b/frontend/src/hooks/api/actions/useChangeRequestApi/useChangeRequestApi.ts @@ -1,5 +1,6 @@ import useAPI from '../useApi/useApi'; import { usePlausibleTracker } from '../../../usePlausibleTracker'; +import { PlausibleChangeRequestState } from 'component/changeRequest/changeRequest.types'; export interface IChangeSchema { feature: string | null; @@ -54,6 +55,7 @@ export const useChangeRequestApi = () => { const changeState = async ( project: string, changeRequestId: number, + previousState: PlausibleChangeRequestState, payload: { state: | 'Approved' @@ -69,6 +71,7 @@ export const useChangeRequestApi = () => { trackEvent('change_request', { props: { eventType: payload.state, + previousState, }, }); diff --git a/frontend/src/hooks/usePlausibleTracker.ts b/frontend/src/hooks/usePlausibleTracker.ts index a43fe69517..597a14ff46 100644 --- a/frontend/src/hooks/usePlausibleTracker.ts +++ b/frontend/src/hooks/usePlausibleTracker.ts @@ -52,7 +52,6 @@ export type CustomEvents = | 'dependent_features' | 'playground_token_input_used' | 'search-filter' - | 'scheduled-configuration-changes' | 'search-feature-buttons' | 'new-strategy-form' | 'feedback'