mirror of
https://github.com/twentyhq/twenty.git
synced 2024-12-17 16:42:31 +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 { useContextScopeId } from '@/ui/utilities/recoil-scope/hooks/useContextScopeId';
|
||||||
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
import { useRecoilScopedState } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedState';
|
||||||
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
import { useRecoilScopedValue } from '@/ui/utilities/recoil-scope/hooks/useRecoilScopedValue';
|
||||||
|
import { assertNotNull } from '~/utils/assert';
|
||||||
|
|
||||||
import { TableRecoilScopeContext } from '../../states/recoil-scope-contexts/TableRecoilScopeContext';
|
import { TableRecoilScopeContext } from '../../states/recoil-scope-contexts/TableRecoilScopeContext';
|
||||||
import { savedTableColumnsScopedState } from '../../states/savedTableColumnsScopedState';
|
import { savedTableColumnsScopedState } from '../../states/savedTableColumnsScopedState';
|
||||||
@ -184,12 +185,16 @@ export const TableViewsDropdownButton = ({
|
|||||||
onClick={(event) => handleEditViewButtonClick(event, view.id)}
|
onClick={(event) => handleEditViewButtonClick(event, view.id)}
|
||||||
icon={<IconPencil size={theme.icon.size.sm} />}
|
icon={<IconPencil size={theme.icon.size.sm} />}
|
||||||
/>,
|
/>,
|
||||||
<IconButton
|
views.length > 1 ? (
|
||||||
key="delete"
|
<IconButton
|
||||||
onClick={(event) => handleDeleteViewButtonClick(event, view.id)}
|
key="delete"
|
||||||
icon={<IconTrash size={theme.icon.size.sm} />}
|
onClick={(event) =>
|
||||||
/>,
|
handleDeleteViewButtonClick(event, view.id)
|
||||||
]}
|
}
|
||||||
|
icon={<IconTrash size={theme.icon.size.sm} />}
|
||||||
|
/>
|
||||||
|
) : null,
|
||||||
|
].filter(assertNotNull)}
|
||||||
onClick={() => handleViewSelect(view.id)}
|
onClick={() => handleViewSelect(view.id)}
|
||||||
>
|
>
|
||||||
<IconList size={theme.icon.size.md} />
|
<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 { Args, Mutation, Query, Resolver } from '@nestjs/graphql';
|
||||||
|
|
||||||
import { accessibleBy } from '@casl/prisma';
|
import { accessibleBy } from '@casl/prisma';
|
||||||
@ -94,7 +98,35 @@ export class ViewResolver {
|
|||||||
@CheckAbilities(DeleteViewAbilityHandler)
|
@CheckAbilities(DeleteViewAbilityHandler)
|
||||||
async deleteManyView(
|
async deleteManyView(
|
||||||
@Args() args: DeleteManyViewArgs,
|
@Args() args: DeleteManyViewArgs,
|
||||||
|
@AuthWorkspace() workspace: Workspace,
|
||||||
): Promise<AffectedRows> {
|
): 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({
|
return this.viewService.deleteMany({
|
||||||
where: args.where,
|
where: args.where,
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user