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

feat: track add and remove dependencies (#5041)

This commit is contained in:
Mateusz Kwasniewski 2023-10-16 10:57:55 +02:00 committed by GitHub
parent 6c21ed5f74
commit 092ba2a625
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import { useChangeRequestApi } from 'hooks/api/actions/useChangeRequestApi/useCh
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
interface IAddDependencyDialogueProps {
project: string;
@ -64,6 +65,7 @@ const useManageDependency = (
parent: string,
onClose: () => void,
) => {
const { trackEvent } = usePlausibleTracker();
const { addChange } = useChangeRequestApi();
const { refetch: refetchChangeRequests } =
usePendingChangeRequests(project);
@ -90,6 +92,11 @@ const useManageDependency = (
payload: { feature: parent },
},
]);
trackEvent('dependent_features', {
props: {
eventType: 'dependency added',
},
});
}
if (actionType === 'deleteDependency') {
await addChange(project, environment, [
@ -110,16 +117,34 @@ const useManageDependency = (
const manageDependency = async () => {
try {
if (isChangeRequestConfiguredInAnyEnv()) {
await handleAddChange(
const actionType =
parent === REMOVE_DEPENDENCY_OPTION.key
? 'deleteDependency'
: 'addDependency',
);
: 'addDependency';
await handleAddChange(actionType);
trackEvent('dependent_features', {
props: {
eventType:
actionType === 'addDependency'
? 'add dependency added to change request'
: 'delete dependency added to change request',
},
});
} else if (parent === REMOVE_DEPENDENCY_OPTION.key) {
await removeDependencies(featureId);
trackEvent('dependent_features', {
props: {
eventType: 'dependency removed',
},
});
setToastData({ title: 'Dependency removed', type: 'success' });
} else {
await addDependency(featureId, { feature: parent });
trackEvent('dependent_features', {
props: {
eventType: 'dependency added',
},
});
setToastData({ title: 'Dependency added', type: 'success' });
}
} catch (error) {

View File

@ -16,8 +16,10 @@ import useToast from 'hooks/useToast';
import { useHighestPermissionChangeRequestEnvironment } from 'hooks/useHighestPermissionChangeRequestEnvironment';
import { useChangeRequestsEnabled } from 'hooks/useChangeRequestsEnabled';
import { formatUnknownError } from 'utils/formatUnknownError';
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
const useDeleteDependency = (project: string, featureId: string) => {
const { trackEvent } = usePlausibleTracker();
const { addChange } = useChangeRequestApi();
const { refetch: refetchChangeRequests } =
usePendingChangeRequests(project);
@ -46,6 +48,11 @@ const useDeleteDependency = (project: string, featureId: string) => {
try {
if (isChangeRequestConfiguredInAnyEnv()) {
await handleAddChange();
trackEvent('dependent_features', {
props: {
eventType: 'delete dependency added to change request',
},
});
setToastData({
text: `${featureId} dependency will be removed`,
type: 'success',
@ -54,6 +61,11 @@ const useDeleteDependency = (project: string, featureId: string) => {
await refetchChangeRequests();
} else {
await removeDependencies(featureId);
trackEvent('dependent_features', {
props: {
eventType: 'dependency removed',
},
});
setToastData({ title: 'Dependency removed', type: 'success' });
await refetchFeature();
}

View File

@ -48,7 +48,8 @@ export type CustomEvents =
| 'project-metrics'
| 'open-integration'
| 'feature-naming-pattern'
| 'project-mode';
| 'project-mode'
| 'dependent_features';
export const usePlausibleTracker = () => {
const plausible = useContext(PlausibleContext);