Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

fix(group): run filters, ordering and pagination in backend (#6114)

Matheus Nogueira904cc9ddc2fc
diff --git a/backend/src/server/routes/v1/organization-memberships-router.ts b/backend/src/server/routes/v1/organization-memberships-router.ts
index 34e4519630..e64831ec0d 100644
--- a/backend/src/server/routes/v1/organization-memberships-router.ts
+++ b/backend/src/server/routes/v1/organization-memberships-router.ts
@@ -3,9 +3,11 @@ import { z } from "zod";
import { AccessScope, GroupsSchema, TemporaryPermissionMode } from "@app/db/schemas";
import { ApiDocsTags } from "@app/lib/api-docs";
import { ms } from "@app/lib/ms";
+import { OrderByDirection } from "@app/lib/types";
import { readLimit, writeLimit } from "@app/server/config/rateLimiter";
import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type";
+import { OrgGroupsOrderBy } from "@app/services/membership-group/membership-group-types";
/**
* Organization group memberships.
@@ -54,7 +56,14 @@ export const registerOrganizationMembershipsRouter = async (server: FastifyZodPr
security: [{ bearerAuth: [] }],
querystring: z.object({
limit: z.coerce.number().min(1).max(100).default(100).optional(),
- offset: z.coerce.number().min(0).default(0).optional()
+ offset: z.coerce.number().min(0).default(0).optional(),
+ search: z.string().optional(),
+ roles: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (typeof v === "string" ? [v] : v))
+ .optional(),
+ orderBy: z.nativeEnum(OrgGroupsOrderBy).optional(),
+ orderDirection: z.nativeEnum(OrderByDirection).optional()
}),
response: {
200: z.object({
@@ -72,7 +81,11 @@ export const registerOrganizationMembershipsRouter = async (server: FastifyZodPr
},
data: {
limit: req.query.limit,
- offset: req.query.offset
+ offset: req.query.offset,
+ search: req.query.search,
+ roles: req.query.roles,
+ orderBy: req.query.orderBy,
+ orderDirection: req.query.orderDirection
}
});
diff --git a/backend/src/services/membership-group/membership-group-dal.ts b/backend/src/services/membership-group/membership-group-dal.ts
index 121596c74a..8c266c0a27 100644
--- a/backend/src/services/membership-group/membership-group-dal.ts
+++ b/backend/src/services/membership-group/membership-group-dal.ts
@@ -6,6 +6,9 @@ import { BadRequestError, DatabaseError } from "@app/lib/errors";
import { ormify, selectAllTableCols, sqlNestRelationships } from "@app/lib/knex";
import { buildKnexFilterForSearchResource } from "@app/lib/search-resource/db";
import { TSearchResourceOperator } from "@app/lib/search-resource/search";
+import { OrderByDirection } from "@app/lib/types";
+
+import { OrgGroupsOrderBy } from "./membership-group-types";
export type TMembershipGroupDALFactory = ReturnType<typeof membershipGroupDALFactory>;
@@ -18,6 +21,8 @@ type TFindGroupArg = {
groupId: string;
name: Omit<TSearchResourceOperator, "number">;
role: Omit<TSearchResourceOperator, "number">;
+ orderBy: OrgGroupsOrderBy;
+ orderDirection: OrderByDirection;
}>;
};
@@ -132,12 +137,12 @@ export const membershipGroupDALFactory = (db: TDbClient) => {
const findGroups = async ({ scopeData, tx, filter }: TFindGroupArg) => {
try {
- const paginatedGroups = (tx || db.replicaNode())(TableName.Membership)
+ // Base filtered query (no pagination) — shared for count and ID subquery
+ const baseFilterQuery = (tx || db.replicaNode())(TableName.Membership)
.whereNotNull(`${TableName.Membership}.actorGroupId`)
.join(TableName.Groups, `${TableName.Groups}.id`, `${TableName.Membership}.actorGroupId`)
.join(TableName.MembershipRole, `${TableName.Membership}.id`, `${TableName.MembershipRole}.membershipId`)
.leftJoin(TableName.Role, `${TableName.MembershipRole}.customRoleId`, `${TableName.Role}.id`)
- .distinct(`${TableName.Membership}.id`)
.where(`${TableName.Membership}.scopeOrgId`, scopeData.orgId)
.where((qb) => {
if (filter.groupId) {
@@ -153,15 +158,12 @@ export const membershipGroupDALFactory = (db: TDbClient) => {
}
});
- if (filter.limit) void paginatedGroups.limit(filter.limit);
- if (filter.offset) void paginatedGroups.offset(filter.offset);
-
if (filter.name || filter.role) {
buildKnexFilterForSearchResource(
- paginatedGroups,
+ baseFilterQuery,
{
- name: filter.name!,
- role: filter.role!
+ ...(filter.name && { name: filter.name }),
+ ...(filter.role && { role: filter.role })
},
(attr) => {
switch (attr) {
@@ -176,14 +178,53 @@ export const membershipGroupDALFactory = (db: TDbClient) => {
);
}
+ // Count total matching groups (without pagination)
+ const [countResult] = (await baseFilterQuery.clone().countDistinct(`${TableName.Membership}.id as count`)) as [
+ { count: string | number }?
+ ];
+ const totalCount = Number(countResult?.count ?? 0);
+
+ const dir = filter.orderDirection === OrderByDirection.DESC ? "DESC" : "ASC";
+
+ const paginatedGroupByColumns = [`${TableName.Membership}.id`, `${TableName.Groups}.name`];
+ let paginatedOrderByRaw: string;
+ let outerOrderByRaw: string;
+
+ switch (filter.orderBy) {
+ case OrgGroupsOrderBy.Slug:
+ paginatedGroupByColumns.push(`${TableName.Groups}.slug`);
+ paginatedOrderByRaw = `LOWER("${TableName.Groups}"."slug") ${dir}`;
+ outerOrderByRaw = `LOWER("${TableName.Groups}"."slug") ${dir}`;
+ break;
+ case OrgGroupsOrderBy.Role:
+ paginatedOrderByRaw = `MIN(LOWER(COALESCE("${TableName.Role}"."slug", "${TableName.MembershipRole}"."role"))) ${dir}`;
+ outerOrderByRaw = `LOWER(COALESCE("${TableName.Role}"."slug", "${TableName.MembershipRole}"."role")) ${dir}`;
+ break;
+ default:
+ paginatedOrderByRaw = `LOWER("${TableName.Groups}"."name") ${dir}`;
+ outerOrderByRaw = `LOWER("${TableName.Groups}"."name") ${dir}`;
+ }
+
+ // Paginated IDs subquery
+ const paginatedGroups = baseFilterQuery
+ .clone()
+ .clearSelect()
+ .select(`${TableName.Membership}.id`)
+ .groupBy(...paginatedGroupByColumns)
+ .orderByRaw(paginatedOrderByRaw)
+ .orderBy(`${TableName.Membership}.id`, "asc");
+ if (filter.limit) void paginatedGroups.limit(filter.limit);
+ if (filter.offset) void paginatedGroups.offset(filter.offset);
+
const docs = await (tx || db.replicaNode())(TableName.Membership)
.whereNotNull(`${TableName.Membership}.actorGroupId`)
.join(TableName.Groups, `${TableName.Groups}.id`, `${TableName.Membership}.actorGroupId`)
.join(TableName.MembershipRole, `${TableName.Membership}.id`, `${TableName.MembershipRole}.membershipId`)
.leftJoin(TableName.Role, `${TableName.MembershipRole}.customRoleId`, `${TableName.Role}.id`)
- .distinct(`${TableName.Membership}.id`)
.where(`${TableName.Membership}.scopeOrgId`, scopeData.orgId)
.whereIn(`${TableName.Membership}.id`, paginatedGroups)
+ .orderByRaw(outerOrderByRaw)
+ .orderBy(`${TableName.Membership}.id`, "asc")
.select(selectAllTableCols(TableName.Membership))
.select(
db.ref("name").withSchema(TableName.Groups).as("groupName"),
@@ -208,11 +249,6 @@ export const membershipGroupDALFactory = (db: TDbClient) => {
.as("membershipRoleTemporaryAccessEndTime"),
db.ref("createdAt").withSchema(TableName.MembershipRole).as("membershipRoleCreatedAt"),
db.ref("updatedAt").withSchema(TableName.MembershipRole).as("membershipRoleUpdatedAt")
- )
- .select(
- db.raw(
- `count(${TableName.Membership}."actorGroupId") OVER(PARTITION BY ${TableName.Membership}."scopeOrgId") as total`
- )
);
const data = sqlNestRelationships({
@@ -262,7 +298,7 @@ export const membershipGroupDALFactory = (db: TDbClient) => {
}
]
});
- return { data, totalCount: Number((data?.[0] as unknown as { total: number })?.total ?? 0) };
+ return { data, totalCount };
} catch (error) {
throw new DatabaseError({ error, name: "MembershipfindGroup" });
}
diff --git a/backend/src/services/membership-group/membership-group-service.ts b/backend/src/services/membership-group/membership-group-service.ts
index 67cf525632..372ec3f344 100644
--- a/backend/src/services/membership-group/membership-group-service.ts
+++ b/backend/src/services/membership-group/membership-group-service.ts
@@ -384,9 +384,11 @@ export const membershipGroupServiceFactory = ({
filter: {
limit: dto.data.limit,
offset: dto.data.offset,
- name: dto.data.groupName
+ orderBy: dto.data.orderBy,
+ orderDirection: dto.data.orderDirection,
+ name: dto.data.search
? {
- [SearchResourceOperators.$contains]: dto.data.groupName
+ [SearchResourceOperators.$contains]: dto.data.search
}
: undefined,
role: dto.data.roles?.length
diff --git a/backend/src/services/membership-group/membership-group-types.ts b/backend/src/services/membership-group/membership-group-types.ts
index 05093ab402..89b0a58396 100644
--- a/backend/src/services/membership-group/membership-group-types.ts
+++ b/backend/src/services/membership-group/membership-group-types.ts
@@ -1,5 +1,11 @@
import { AccessScopeData, TemporaryPermissionMode } from "@app/db/schemas";
-import { OrgServiceActor } from "@app/lib/types";
+import { OrderByDirection, OrgServiceActor } from "@app/lib/types";
+
+export enum OrgGroupsOrderBy {
+ Name = "name",
+ Slug = "slug",
+ Role = "role"
+}
export interface TMembershipGroupScopeFactory {
onCreateMembershipGroupGuard: (arg: TCreateMembershipGroupDTO) => Promise<void>;
@@ -56,8 +62,10 @@ export type TListMembershipGroupDTO = {
data: {
limit?: number;
offset?: number;
- groupName?: string;
+ search?: string;
roles?: string[];
+ orderBy?: OrgGroupsOrderBy;
+ orderDirection?: OrderByDirection;
};
};
diff --git a/frontend/src/hooks/api/organization/index.ts b/frontend/src/hooks/api/organization/index.ts
index 1506a5777f..bd6c6a3cf8 100644
--- a/frontend/src/hooks/api/organization/index.ts
+++ b/frontend/src/hooks/api/organization/index.ts
@@ -23,6 +23,7 @@ export {
useGetOrgPmtMethods,
useGetOrgTaxIds,
useGetOrgTrialUrl,
+ useSearchOrganizationGroups,
useUpdateOrg,
useUpdateOrgBillingDetails,
useUpgradePrivilegeSystem
diff --git a/frontend/src/hooks/api/organization/queries.tsx b/frontend/src/hooks/api/organization/queries.tsx
index a8f78ac01e..1905348a6b 100644
--- a/frontend/src/hooks/api/organization/queries.tsx
+++ b/frontend/src/hooks/api/organization/queries.tsx
@@ -49,6 +49,17 @@ export const organizationKeys = {
}: TListOrgIdentitiesDTO) =>
[...organizationKeys.getOrgIdentityMemberships(orgId), params] as const,
getOrgGroups: (orgId: string) => [{ orgId }, "organization-groups"] as const,
+ getOrgGroupsWithParams: (
+ orgId: string,
+ params: {
+ offset?: number;
+ limit?: number;
+ search?: string;
+ roles?: string[];
+ orderBy?: string;
+ orderDirection?: string;
+ }
+ ) => [...organizationKeys.getOrgGroups(orgId), params] as const,
getOrgIntegrationAuths: (orgId: string) => [{ orgId }, "integration-auths"] as const,
getOrgById: (orgId: string) => ["organization", { orgId }],
getAvailableIdentities: () => ["available-identities"],
@@ -643,6 +654,55 @@ export const useGetOrganizationGroups = (organizationId: string) => {
});
};
+export const useSearchOrganizationGroups = ({
+ organizationId,
+ offset,
+ limit,
+ search,
+ roles,
+ orderBy,
+ orderDirection
+}: {
+ organizationId: string;
+ offset?: number;
+ limit?: number;
+ search?: string;
+ roles?: string[];
+ orderBy?: string;
+ orderDirection?: string;
+}) => {
+ return useQuery({
+ queryKey: organizationKeys.getOrgGroupsWithParams(organizationId, {
+ offset,
+ limit,
+ search,
+ roles,
+ orderBy,
+ orderDirection
+ }),
+ enabled: Boolean(organizationId),
+ placeholderData: (prev) => prev,
+ queryFn: async () => {
+ const {
+ data: { groupMemberships, totalCount }
+ } = await apiRequest.get<OrgGroupMembershipResponse>(
+ "/api/v1/organizations/memberships/groups",
+ {
+ params: {
+ limit,
+ offset,
+ search: search || undefined,
+ roles: roles?.length ? roles : undefined,
+ orderBy,
+ orderDirection
+ }
+ }
+ );
+ return { groups: groupMemberships.map(mapOrgMembershipToGroup), totalCount };
+ }
+ });
+};
+
export const useGetOrgIntegrationAuths = <TData = IntegrationAuth[],>(
organizationId: string,
select?: (data: IntegrationAuth[]) => TData
diff --git a/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupsTable.tsx b/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupsTable.tsx
index 446173ad9f..25d0a18fbe 100644
--- a/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupsTable.tsx
+++ b/frontend/src/pages/organization/AccessManagementPage/components/OrgGroupsTab/components/OrgGroupsSection/OrgGroupsTable.tsx
@@ -1,4 +1,4 @@
-import { useCallback, useMemo, useState } from "react";
+import { useCallback, useState } from "react";
import { useNavigate } from "@tanstack/react-router";
import {
ChevronDownIcon,
@@ -53,7 +53,7 @@ import {
setUserTablePreference
} from "@app/helpers/userTablePreferences";
import { usePagination, useResetPageHelper } from "@app/hooks";
-import { useGetOrganizationGroups, useGetOrgRoles, useUpdateGroup } from "@app/hooks/api";
+import { useGetOrgRoles, useSearchOrganizationGroups, useUpdateGroup } from "@app/hooks/api";
import { OrderByDirection } from "@app/hooks/api/generic/types";
import { UsePopUpState } from "@app/hooks/usePopUp";
@@ -88,7 +88,6 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
const navigate = useNavigate();
const { currentOrg, isSubOrganization } = useOrganization();
const orgId = currentOrg?.id || "";
- const { isPending, data: groups = [] } = useGetOrganizationGroups(orgId);
const { mutateAsync: updateMutateAsync } = useUpdateGroup();
const { data: roles } = useGetOrgRoles(orgId);
@@ -118,7 +117,8 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
orderBy,
setOrderBy,
setOrderDirection,
- toggleOrderDirection
+ toggleOrderDirection,
+ debouncedSearch
} = usePagination<GroupsOrderBy>(GroupsOrderBy.Name, {
initPerPage: getUserTablePreference("orgGroupsTable", PreferenceKey.PerPage, 20)
});
@@ -147,39 +147,17 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
const isTableFiltered = Boolean(filter.roles.length);
- const filteredGroups = useMemo(() => {
- const filtered = groups?.filter(({ name, slug, role, customRole }) => {
- if (filter.roles.length) {
- const effectiveRole = role === "custom" ? customRole?.slug : role;
- if (!effectiveRole || !filter.roles.includes(effectiveRole)) {
- return false;
- }
- }
-
- if (search) {
- return (
- name.toLowerCase().includes(search.toLowerCase()) ||
- slug.toLowerCase().includes(search.toLowerCase())
- );
- }
- return true;
- });
-
- const ordered = filtered?.sort((a, b) => {
- switch (orderBy) {
- case GroupsOrderBy.Role: {
- const aValue = a.role === "custom" ? (a.customRole?.name as string) : a.role;
- const bValue = b.role === "custom" ? (b.customRole?.name as string) : b.role;
-
- return aValue.toLowerCase().localeCompare(bValue.toLowerCase());
- }
- default:
- return a[orderBy].toLowerCase().localeCompare(b[orderBy].toLowerCase());
- }
- });
+ const { isPending, data } = useSearchOrganizationGroups({
+ organizationId: orgId,
+ offset,
+ limit: perPage,
+ search: debouncedSearch,
+ roles: filter.roles.length ? filter.roles : undefined,
+ orderBy,
+ orderDirection
+ });
- return orderDirection === OrderByDirection.ASC ? ordered : ordered?.reverse();
- }, [search, groups, orderBy, orderDirection, filter]);
+ const { groups: sortedGroups = [], totalCount = 0 } = data ?? {};
const handleSort = (column: GroupsOrderBy) => {
if (column === orderBy) {
@@ -192,13 +170,11 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
};
useResetPageHelper({
- totalCount: filteredGroups.length,
+ totalCount,
offset,
setPage
});
- const filteredGroupsPage = filteredGroups.slice(offset, perPage * page);
-
return (
<div>
<div className="mb-4 flex gap-2">
@@ -243,16 +219,16 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
</DropdownMenuContent>
</DropdownMenu>
</div>
- {!isPending && !filteredGroups?.length ? (
+ {!isPending && !sortedGroups.length ? (
<Empty className="border">
<EmptyHeader>
<EmptyTitle>
- {groups.length
- ? `No ${isSubOrganization ? "sub-" : ""}organization groups match ${search ? "search" : "filter criteria"}`
+ {debouncedSearch || isTableFiltered
+ ? `No ${isSubOrganization ? "sub-" : ""}organization groups match ${debouncedSearch ? "search" : "filter criteria"}`
: `No ${isSubOrganization ? "sub-" : ""}organization groups found`}
</EmptyTitle>
<EmptyDescription>
- {groups.length
+ {debouncedSearch || isTableFiltered
? "Adjust your search or filter criteria."
: "Create a group to get started."}
</EmptyDescription>
@@ -330,185 +306,183 @@ export const OrgGroupsTable = ({ handlePopUpOpen }: Props) => {
</TableRow>
))}
{!isPending &&
- filteredGroupsPage.map(
- ({ id, name, slug, role, customRole, orgId: groupOrgId }) => {
- const isLinkedGroup = currentOrg ? groupOrgId !== currentOrg.id : false;
- const isManagedBySubOrg = currentOrg ? groupOrgId === currentOrg.id : false;
- return (
- <TableRow
- key={`org-group-${id}`}
- className="cursor-pointer"
- onClick={() =>
- navigate({
- to: "/organizations/$orgId/groups/$groupId",
- params: {
- orgId,
- groupId: id
- }
- })
- }
- >
- <TableCell isTruncatable>{name}</TableCell>
- <TableCell isTruncatable>{slug}</TableCell>
- <TableCell>
- <OrgPermissionCan
- I={OrgPermissionGroupActions.Edit}
- a={OrgPermissionSubjects.Groups}
- >
- {(isAllowed) => (
- <Select
- value={role === "custom" ? (customRole?.slug as string) : role}
- disabled={!isAllowed}
- onValueChange={(selectedRole) =>
- handleChangeRole({
- id,
- role: selectedRole
- })
- }
+ sortedGroups.map(({ id, name, slug, role, customRole, orgId: groupOrgId }) => {
+ const isLinkedGroup = currentOrg ? groupOrgId !== currentOrg.id : false;
+ const isManagedBySubOrg = currentOrg ? groupOrgId === currentOrg.id : false;
+ return (
+ <TableRow
+ key={`org-group-${id}`}
+ className="cursor-pointer"
+ onClick={() =>
+ navigate({
+ to: "/organizations/$orgId/groups/$groupId",
+ params: {
+ orgId,
+ groupId: id
+ }
+ })
+ }
+ >
+ <TableCell isTruncatable>{name}</TableCell>
+ <TableCell isTruncatable>{slug}</TableCell>
+ <TableCell>
+ <OrgPermissionCan
+ I={OrgPermissionGroupActions.Edit}
+ a={OrgPermissionSubjects.Groups}
+ >
+ {(isAllowed) => (
+ <Select
+ value={role === "custom" ? (customRole?.slug as string) : role}
+ disabled={!isAllowed}
+ onValueChange={(selectedRole) =>
+ handleChangeRole({
+ id,
+ role: selectedRole
+ })
+ }
+ >
+ <SelectTrigger
+ size="sm"
+ className="w-full max-w-32 lg:max-w-64"
+ onClick={(e) => e.stopPropagation()}
>
- <SelectTrigger
- size="sm"
- className="w-full max-w-32 lg:max-w-64"
- onClick={(e) => e.stopPropagation()}
- >
- <SelectValue />
- </SelectTrigger>
- <SelectContent className="max-w-32 lg:max-w-64">
- {(roles || []).map(({ slug: roleSlug, name: roleName }) => (
- <SelectItem value={roleSlug} key={`role-option-${roleSlug}`}>
- {roleName}
- </SelectItem>
- ))}
- </SelectContent>
- </Select>
+ <SelectValue />
+ </SelectTrigger>
+ <SelectContent className="max-w-32 lg:max-w-64">
+ {(roles || []).map(({ slug: roleSlug, name: roleName }) => (
+ <SelectItem value={roleSlug} key={`role-option-${roleSlug}`}>
+ {roleName}
+ </SelectItem>
+ ))}
+ </SelectContent>
+ </Select>
+ )}
+ </OrgPermissionCan>
+ </TableCell>
+ {isSubOrganization && (
+ <TableCell>
+ <Badge variant={isManagedBySubOrg ? "sub-org" : "org"}>
+ {isManagedBySubOrg ? (
+ <>
+ <SubOrgIcon />
+ Sub-Organization
+ </>
+ ) : (
+ <>
+ <OrgIcon />
+ Root Organization
+ </>
)}
- </OrgPermissionCan>
+ </Badge>
</TableCell>
- {isSubOrganization && (
- <TableCell>
- <Badge variant={isManagedBySubOrg ? "sub-org" : "org"}>
- {isManagedBySubOrg ? (
- <>
- <SubOrgIcon />
- Sub-Organization
- </>
- ) : (
- <>
- <OrgIcon />
- Root Organization
- </>
- )}
- </Badge>
- </TableCell>
- )}
- <TableCell>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <IconButton
- variant="ghost"
- size="xs"
- onClick={(e) => e.stopPropagation()}
- >
- <MoreHorizontalIcon />
- </IconButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent sideOffset={2} align="end">
- <DropdownMenuItem
- onClick={(e) => {
- e.stopPropagation();
- navigator.clipboard.writeText(id);
- createNotification({
- text: "Copied group ID to clipboard",
- type: "info"
- });
- }}
- >
- <CopyIcon />
- Copy Group ID
- </DropdownMenuItem>
- {!isLinkedGroup && (
- <OrgPermissionCan
- I={OrgPermissionGroupActions.Edit}
- a={OrgPermissionSubjects.Groups}
- >
- {(isAllowed) => (
- <DropdownMenuItem
- onClick={(e) => {
- e.stopPropagation();
- handlePopUpOpen("group", {
- groupId: id,
- name,
- slug,
- role,
- customRole
- });
- }}
- isDisabled={!isAllowed}
- >
- <PencilIcon />
- Edit Group
- </DropdownMenuItem>
- )}
- </OrgPermissionCan>
- )}
- {!isLinkedGroup && (
- <OrgPermissionCan
- I={OrgPermissionGroupActions.Edit}
- a={OrgPermissionSubjects.Groups}
- >
- {(isAllowed) => (
- <DropdownMenuItem
- onClick={() =>
- navigate({
- to: "/organizations/$orgId/groups/$groupId",
- params: {
- orgId,
- groupId: id
- }
- })
- }
- isDisabled={!isAllowed}
- >
- <UsersIcon />
- Manage Members
- </DropdownMenuItem>
- )}
- </OrgPermissionCan>
- )}
+ )}
+ <TableCell>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <IconButton
+ variant="ghost"
+ size="xs"
+ onClick={(e) => e.stopPropagation()}
+ >
+ <MoreHorizontalIcon />
+ </IconButton>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent sideOffset={2} align="end">
+ <DropdownMenuItem
+ onClick={(e) => {
+ e.stopPropagation();
+ navigator.clipboard.writeText(id);
+ createNotification({
+ text: "Copied group ID to clipboard",
+ type: "info"
+ });
+ }}
+ >
+ <CopyIcon />
+ Copy Group ID
+ </DropdownMenuItem>
+ {!isLinkedGroup && (
<OrgPermissionCan
- I={OrgPermissionGroupActions.Delete}
+ I={OrgPermissionGroupActions.Edit}
a={OrgPermissionSubjects.Groups}
>
{(isAllowed) => (
<DropdownMenuItem
- variant="danger"
onClick={(e) => {
e.stopPropagation();
- handlePopUpOpen("deleteGroup", {
+ handlePopUpOpen("group", {
groupId: id,
name,
- isLinkedGroup
+ slug,
+ role,
+ customRole
});
}}
isDisabled={!isAllowed}
>
- <TrashIcon />
- {isLinkedGroup ? "Unlink Group" : "Delete Group"}
+ <PencilIcon />
+ Edit Group
</DropdownMenuItem>
)}
</OrgPermissionCan>
- </DropdownMenuContent>
- </DropdownMenu>
- </TableCell>
- </TableRow>
- );
- }
- )}
+ )}
+ {!isLinkedGroup && (
+ <OrgPermissionCan
+ I={OrgPermissionGroupActions.Edit}
+ a={OrgPermissionSubjects.Groups}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ onClick={() =>
+ navigate({
+ to: "/organizations/$orgId/groups/$groupId",
+ params: {
+ orgId,
+ groupId: id
+ }
+ })
+ }
+ isDisabled={!isAllowed}
+ >
+ <UsersIcon />
+ Manage Members
+ </DropdownMenuItem>
+ )}
+ </OrgPermissionCan>
+ )}
+ <OrgPermissionCan
+ I={OrgPermissionGroupActions.Delete}
+ a={OrgPermissionSubjects.Groups}
+ >
+ {(isAllowed) => (
+ <DropdownMenuItem
+ variant="danger"
+ onClick={(e) => {
+ e.stopPropagation();
+ handlePopUpOpen("deleteGroup", {
+ groupId: id,
+ name,
+ isLinkedGroup
+ });
+ }}
+ isDisabled={!isAllowed}
+ >
+ <TrashIcon />
+ {isLinkedGroup ? "Unlink Group" : "Delete Group"}
+ </DropdownMenuItem>
+ )}
+ </OrgPermissionCan>
+ </DropdownMenuContent>
+ </DropdownMenu>
+ </TableCell>
+ </TableRow>
+ );
+ })}
</TableBody>
</Table>
- {Boolean(filteredGroups.length) && (
+ {Boolean(totalCount) && (
<Pagination
- count={filteredGroups.length}
+ count={totalCount}
page={page}
perPage={perPage}
onChangePage={setPage}