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:
parent
936fa44ec5
commit
b0ecfd4d34
@ -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();
|
||||
|
@ -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,
|
||||
});
|
||||
|
@ -100,6 +100,12 @@ export interface IChangeRequestChangeBase {
|
||||
};
|
||||
}
|
||||
|
||||
export type PlausibleChangeRequestState =
|
||||
| Exclude<ChangeRequestState, 'Scheduled'>
|
||||
| 'Scheduled pending'
|
||||
| 'Scheduled failed'
|
||||
| 'Scheduled suspended';
|
||||
|
||||
export type ChangeRequestState =
|
||||
| 'Draft'
|
||||
| 'Approved'
|
||||
|
@ -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,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user