mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-17 08:31:47 +03:00
parent
8bb4071f09
commit
2b3e96b9ea
@ -31,6 +31,7 @@ import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousH
|
||||
import { useContextScopeId } from '@/ui/utilities/recoil-scope/hooks/useContextScopeId';
|
||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||
import { assertNotNull } from '~/utils/assert';
|
||||
|
||||
import { TableRecoilScopeContext } from '../../states/recoil-scope-contexts/TableRecoilScopeContext';
|
||||
import { savedTableColumnsScopedState } from '../../states/savedTableColumnsScopedState';
|
||||
@ -184,12 +185,16 @@ export const TableViewsDropdownButton = ({
|
||||
onClick={(event) => handleEditViewButtonClick(event, view.id)}
|
||||
icon={<IconPencil size={theme.icon.size.sm} />}
|
||||
/>,
|
||||
<IconButton
|
||||
key="delete"
|
||||
onClick={(event) => handleDeleteViewButtonClick(event, view.id)}
|
||||
icon={<IconTrash size={theme.icon.size.sm} />}
|
||||
/>,
|
||||
]}
|
||||
views.length > 1 ? (
|
||||
<IconButton
|
||||
key="delete"
|
||||
onClick={(event) =>
|
||||
handleDeleteViewButtonClick(event, view.id)
|
||||
}
|
||||
icon={<IconTrash size={theme.icon.size.sm} />}
|
||||
/>
|
||||
) : null,
|
||||
].filter(assertNotNull)}
|
||||
onClick={() => handleViewSelect(view.id)}
|
||||
>
|
||||
<IconList size={theme.icon.size.md} />
|
||||
|
@ -1,4 +1,8 @@
|
||||
import { UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
BadRequestException,
|
||||
ForbiddenException,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||
|
||||
import { accessibleBy } from '@casl/prisma';
|
||||
@ -94,7 +98,35 @@ export class ViewResolver {
|
||||
@CheckAbilities(DeleteViewAbilityHandler)
|
||||
async deleteManyView(
|
||||
@Args() args: DeleteManyViewArgs,
|
||||
@AuthWorkspace() workspace: Workspace,
|
||||
): Promise<AffectedRows> {
|
||||
const viewsToDelete = await this.viewService.findMany({
|
||||
where: args.where,
|
||||
});
|
||||
|
||||
if (!viewsToDelete.length) return { count: 0 };
|
||||
|
||||
const { objectId } = viewsToDelete[0];
|
||||
|
||||
if (viewsToDelete.some((view) => view.objectId !== objectId)) {
|
||||
throw new BadRequestException(
|
||||
`Views must have the same objectId '${objectId}'`,
|
||||
);
|
||||
}
|
||||
|
||||
const viewsNb = await this.viewService.count({
|
||||
where: {
|
||||
objectId: { equals: objectId },
|
||||
workspaceId: { equals: workspace.id },
|
||||
},
|
||||
});
|
||||
|
||||
if (viewsNb - viewsToDelete.length <= 0) {
|
||||
throw new ForbiddenException(
|
||||
`Deleting last '${objectId}' view is not allowed`,
|
||||
);
|
||||
}
|
||||
|
||||
return this.viewService.deleteMany({
|
||||
where: args.where,
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user