1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-05 17:53:12 +02:00

bulk feature archive api

This commit is contained in:
Tymoteusz Czech 2023-03-14 10:12:41 +01:00
parent abe19d3040
commit a8f66dc772
No known key found for this signature in database
GPG Key ID: 133555230D88D75F
3 changed files with 14 additions and 7 deletions

View File

@ -4,6 +4,7 @@ import useFeatureApi from 'hooks/api/actions/useFeatureApi/useFeatureApi';
import useToast from 'hooks/useToast'; import useToast from 'hooks/useToast';
import { formatUnknownError } from 'utils/formatUnknownError'; import { formatUnknownError } from 'utils/formatUnknownError';
import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender'; import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender';
import useProjectApi from 'hooks/api/actions/useProjectApi/useProjectApi';
interface IFeatureArchiveDialogProps { interface IFeatureArchiveDialogProps {
isOpen: boolean; isOpen: boolean;
@ -21,6 +22,7 @@ export const FeatureArchiveDialog: VFC<IFeatureArchiveDialogProps> = ({
featureIds, featureIds,
}) => { }) => {
const { archiveFeatureToggle } = useFeatureApi(); const { archiveFeatureToggle } = useFeatureApi();
const { archiveFeatures } = useProjectApi();
const { setToastData, setToastApiError } = useToast(); const { setToastData, setToastApiError } = useToast();
const isBulkArchive = featureIds?.length > 1; const isBulkArchive = featureIds?.length > 1;
@ -42,12 +44,7 @@ export const FeatureArchiveDialog: VFC<IFeatureArchiveDialogProps> = ({
const archiveToggles = async () => { const archiveToggles = async () => {
try { try {
// TODO: bulk archive await archiveFeatures(projectId, featureIds);
await Promise.allSettled(
featureIds.map(id => {
archiveFeatureToggle(projectId, id);
})
);
setToastData({ setToastData({
text: 'Selected feature toggles have been archived', text: 'Selected feature toggles have been archived',
type: 'success', type: 'success',

View File

@ -202,6 +202,16 @@ const useProjectApi = () => {
return makeRequest(req.caller, req.id); return makeRequest(req.caller, req.id);
}; };
const archiveFeatures = async (projectId: string, featureIds: string[]) => {
const path = `api/admin/projects/${projectId}/archive`;
const req = createRequest(path, {
method: 'POST',
body: JSON.stringify({ features: featureIds }),
});
return makeRequest(req.caller, req.id);
};
return { return {
createProject, createProject,
validateId, validateId,
@ -214,6 +224,7 @@ const useProjectApi = () => {
removeGroupFromRole, removeGroupFromRole,
changeUserRole, changeUserRole,
changeGroupRole, changeGroupRole,
archiveFeatures,
errors, errors,
loading, loading,
searchProjectUser, searchProjectUser,

View File

@ -44,7 +44,6 @@ process.nextTick(async () => {
projectStatusApi: true, projectStatusApi: true,
showProjectApiAccess: true, showProjectApiAccess: true,
projectScopedSegments: true, projectScopedSegments: true,
bulkOperations: true,
projectScopedStickiness: true, projectScopedStickiness: true,
}, },
}, },