1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi.ts
Tymoteusz Czech c70b38a62a Feature toggle page update (#1140)
* feat: add icon to custom strategies

* feat: update feature toggle screen layout

* strategy and constraints separators

* style disabled envirnments

* strategy constraint style

* strategy drag and drop

* feature env emtpy state

* quick add strategy api

* reorder strategies api integration

* feature strategy header title

* openapi update

* style small chip component

* fix comments after review

* fix issues with strategy constraint operators

* Revert "openapi update"

This reverts commit 27e7651ebae26f61ca76ec910e1f209bae7f2955.

* fix tooltip ref
2022-07-27 10:00:15 +00:00

85 lines
2.7 KiB
TypeScript

import {
IFeatureStrategyPayload,
IFeatureStrategy,
IFeatureStrategySortOrder,
} from 'interfaces/strategy';
import useAPI from '../useApi/useApi';
const useFeatureStrategyApi = () => {
const { makeRequest, createRequest, errors, loading } = useAPI({
propagateErrors: true,
});
const addStrategyToFeature = async (
projectId: string,
featureId: string,
environmentId: string,
payload: IFeatureStrategyPayload
): Promise<IFeatureStrategy> => {
const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies`;
const req = createRequest(
path,
{ method: 'POST', body: JSON.stringify(payload) },
'addStrategyToFeature'
);
return (await makeRequest(req.caller, req.id)).json();
};
const deleteStrategyFromFeature = async (
projectId: string,
featureId: string,
environmentId: string,
strategyId: string
): Promise<void> => {
const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies/${strategyId}`;
const req = createRequest(
path,
{ method: 'DELETE' },
'deleteStrategyFromFeature'
);
await makeRequest(req.caller, req.id);
};
const updateStrategyOnFeature = async (
projectId: string,
featureId: string,
environmentId: string,
strategyId: string,
payload: IFeatureStrategyPayload
): Promise<void> => {
const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies/${strategyId}`;
const req = createRequest(
path,
{ method: 'PUT', body: JSON.stringify(payload) },
'updateStrategyOnFeature'
);
await makeRequest(req.caller, req.id);
};
const setStrategiesSortOrder = async (
projectId: string,
featureId: string,
environmentId: string,
payload: IFeatureStrategySortOrder[]
): Promise<void> => {
const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies/set-sort-order`;
const req = createRequest(
path,
{ method: 'POST', body: JSON.stringify(payload) },
'setStrategiesSortOrderOnFeature'
);
await makeRequest(req.caller, req.id);
};
return {
addStrategyToFeature,
updateStrategyOnFeature,
deleteStrategyFromFeature,
setStrategiesSortOrder,
loading,
errors,
};
};
export default useFeatureStrategyApi;