1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-11 00:08:30 +01:00

feat: add plausible change-requests-conflicts (#6024)

This commit is contained in:
Jaanus Sellin 2024-01-24 21:46:08 +02:00 committed by GitHub
parent 936fa44ec5
commit b0ecfd4d34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 24 additions and 32 deletions

View File

@ -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();

View File

@ -81,7 +81,7 @@ export const ChangeRequestSidebar: VFC<IChangeRequestSidebarProps> = ({
const onReview = async (draftId: number, comment?: string) => {
try {
await changeState(project, draftId, {
await changeState(project, draftId, 'Draft', {
state: 'In review',
comment,
});

View File

@ -100,6 +100,12 @@ export interface IChangeRequestChangeBase {
};
}
export type PlausibleChangeRequestState =
| Exclude<ChangeRequestState, 'Scheduled'>
| 'Scheduled pending'
| 'Scheduled failed'
| 'Scheduled suspended';
export type ChangeRequestState =
| 'Draft'
| 'Approved'

View File

@ -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,
},
});

View File

@ -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'