mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-08 01:15:49 +02:00
feat: implement call to add release-plan to feature environment (#8778)
This commit is contained in:
parent
69f73f45f4
commit
0ce976a0d5
@ -3,6 +3,9 @@ import StringTruncator from 'component/common/StringTruncator/StringTruncator';
|
|||||||
import { Link, styled } from '@mui/material';
|
import { Link, styled } from '@mui/material';
|
||||||
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
import { usePlausibleTracker } from 'hooks/usePlausibleTracker';
|
||||||
import type { IReleasePlanTemplate } from 'interfaces/releasePlans';
|
import type { IReleasePlanTemplate } from 'interfaces/releasePlans';
|
||||||
|
import { useReleasePlansApi } from 'hooks/api/actions/useReleasePlansApi/useReleasePlansApi';
|
||||||
|
import useToast from 'hooks/useToast';
|
||||||
|
import { formatUnknownError } from 'utils/formatUnknownError';
|
||||||
|
|
||||||
const StyledIcon = styled('div')(({ theme }) => ({
|
const StyledIcon = styled('div')(({ theme }) => ({
|
||||||
width: theme.spacing(4),
|
width: theme.spacing(4),
|
||||||
@ -57,15 +60,31 @@ export const FeatureReleasePlanCard = ({
|
|||||||
}: IFeatureReleasePlanCardProps) => {
|
}: IFeatureReleasePlanCardProps) => {
|
||||||
const Icon = getFeatureStrategyIcon('releasePlanTemplate');
|
const Icon = getFeatureStrategyIcon('releasePlanTemplate');
|
||||||
const { trackEvent } = usePlausibleTracker();
|
const { trackEvent } = usePlausibleTracker();
|
||||||
|
const { addReleasePlanToFeature } = useReleasePlansApi();
|
||||||
|
const { setToastApiError, setToastData } = useToast();
|
||||||
|
|
||||||
|
const addReleasePlan = async () => {
|
||||||
|
try {
|
||||||
|
await addReleasePlanToFeature(
|
||||||
|
featureId,
|
||||||
|
releasePlanTemplate.id,
|
||||||
|
projectId,
|
||||||
|
environmentId,
|
||||||
|
);
|
||||||
|
setToastData({
|
||||||
|
type: 'success',
|
||||||
|
title: 'Release plan added',
|
||||||
|
});
|
||||||
|
} catch (error: unknown) {
|
||||||
|
setToastApiError(formatUnknownError(error));
|
||||||
|
}
|
||||||
|
|
||||||
const addReleasePlan = () => {
|
|
||||||
trackEvent('release-plans', {
|
trackEvent('release-plans', {
|
||||||
props: {
|
props: {
|
||||||
eventType: 'add',
|
eventType: 'add',
|
||||||
name: releasePlanTemplate.name,
|
name: releasePlanTemplate.name,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log('TODO: call and implement addReleasePlan');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -0,0 +1,31 @@
|
|||||||
|
import useAPI from '../useApi/useApi';
|
||||||
|
export const useReleasePlansApi = () => {
|
||||||
|
const { makeRequest, makeLightRequest, createRequest, errors, loading } =
|
||||||
|
useAPI({
|
||||||
|
propagateErrors: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
const addReleasePlanToFeature = async (
|
||||||
|
featureName: string,
|
||||||
|
releasePlanTemplateId: string,
|
||||||
|
projectId: string,
|
||||||
|
environment: string,
|
||||||
|
): Promise<void> => {
|
||||||
|
const requestId = 'createReleasePlanTemplate';
|
||||||
|
const path = `api/admin/projects/${projectId}/features/${featureName}/environments/${environment}/release_plans/${releasePlanTemplateId}`;
|
||||||
|
const req = createRequest(
|
||||||
|
path,
|
||||||
|
{
|
||||||
|
method: 'POST',
|
||||||
|
body: JSON.stringify({}),
|
||||||
|
},
|
||||||
|
requestId,
|
||||||
|
);
|
||||||
|
|
||||||
|
await makeRequest(req.caller, req.id);
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
addReleasePlanToFeature,
|
||||||
|
};
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user