Skip to content

Commit

Permalink
bulk delete
Browse files Browse the repository at this point in the history
  • Loading branch information
anamontiaga committed Aug 31, 2023
1 parent 1b032b0 commit c282800
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import CostSurfaceInfo from './cost-surfaces/info';
import FeaturesTable from './features';
import FeaturesInfo from './features/info';
import FeatureUploadModal from './features/modals/upload';
import ProtectedAreasTable from './protected-areas';
import ProtectedAreasFooter from './protected-areas/footer';
import { InventoryPanel } from './types';
import ProtectedAreasTable from './wdpas';
import ProtectedAreasFooter from './wdpas/footer';

export const INVENTORY_TABS = {
'protected-areas': {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,75 +1,28 @@
import { Session } from 'next-auth';

import { Feature } from 'types/api/feature';
import { CostSurface } from 'types/api/cost-surface';
import { Project } from 'types/api/project';

import PROJECTS from 'services/projects';

export function bulkDeleteFeatureFromProject(
export function bulkDeleteCostSurfaceFromProject(
pid: Project['id'],
fids: Feature['id'][],
csids: CostSurface['id'][],
session: Session
) {
const deleteFeatureFromProject = ({ pid, fid }: { pid: Project['id']; fid: Feature['id'] }) => {
return PROJECTS.delete(`/${pid}/features/${fid}`, {
headers: {
Authorization: `Bearer ${session.accessToken}`,
},
});
};

return Promise.all(fids.map((fid) => deleteFeatureFromProject({ pid, fid })));
}

export function editFeaturesTagsBulk(
projectId: Project['id'],
featureIds: Feature['id'][],
session: Session,
data: {
tagName: string;
}
) {
const editFeatureTag = ({
featureId,
projectId,
data,
}: {
featureId: Feature['id'];
projectId: Project['id'];
data: {
tagName: string;
};
}) => {
return PROJECTS.request({
method: 'PATCH',
url: `/${projectId}/features/${featureId}/tags`,
data,
headers: {
Authorization: `Bearer ${session.accessToken}`,
},
});
};
return Promise.all(featureIds.map((featureId) => editFeatureTag({ projectId, featureId, data })));
}

export function deleteFeaturesTagsBulk(
projectId: Project['id'],
featureIds: Feature['id'][],
session: Session
) {
const deleteFeatureTags = ({
projectId,
featureId,
const deleteCostSurfaceFromProject = ({
pid,
csid,
}: {
projectId: Project['id'];
featureId: Feature['id'];
pid: Project['id'];
csid: CostSurface['id'];
}) => {
return PROJECTS.delete(`/${projectId}/features/${featureId}/tags`, {
return PROJECTS.delete(`/${pid}/cost-surfaces/${csid}`, {
headers: {
Authorization: `Bearer ${session.accessToken}`,
},
});
};

return Promise.all(featureIds.map((featureId) => deleteFeatureTags({ projectId, featureId })));
return Promise.all(csids.map((csid) => deleteCostSurfaceFromProject({ pid, csid })));
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ import { useToasts } from 'hooks/toast';
import { Button } from 'components/button/component';
import Icon from 'components/icon/component';
import { ModalProps } from 'components/modal';
import { bulkDeleteFeatureFromProject } from 'layout/project/sidebar/project/inventory-panel/features/bulk-action-menu/utils';
import { bulkDeleteCostSurfaceFromProject } from 'layout/project/sidebar/project/inventory-panel/cost-surfaces/bulk-action-menu/utils';
import { CostSurface } from 'types/api/cost-surface';
import { Pagination } from 'types/api/meta';

import ALERT_SVG from 'svgs/ui/new-layout/alert.svg?sprite';

Expand Down Expand Up @@ -48,7 +47,7 @@ const DeleteModal = ({
const handleBulkDelete = useCallback(() => {
const deletableFeatureIds = selectedCostSurfaces.map(({ id }) => id);

bulkDeleteFeatureFromProject(pid, deletableFeatureIds, session)
bulkDeleteCostSurfaceFromProject(pid, deletableFeatureIds, session)
.then(async () => {
await queryClient.invalidateQueries(['cost-surfaces', pid]);

Expand Down

0 comments on commit c282800

Please sign in to comment.