mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 04:27:29 +00:00
improvement: filterable role selection on create/edit group
This commit is contained in:
@@ -33,7 +33,7 @@ export const getDefaultOnPremFeatures = (): TFeatureSet => ({
|
|||||||
oidcSSO: false,
|
oidcSSO: false,
|
||||||
scim: false,
|
scim: false,
|
||||||
ldap: false,
|
ldap: false,
|
||||||
groups: false,
|
groups: true,
|
||||||
status: null,
|
status: null,
|
||||||
trial_end: null,
|
trial_end: null,
|
||||||
has_used_trial: true,
|
has_used_trial: true,
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { ProjectMembershipRole } from "@app/hooks/api/roles/types";
|
import { ProjectMembershipRole, TOrgRole } from "@app/hooks/api/roles/types";
|
||||||
|
|
||||||
enum OrgMembershipRole {
|
enum OrgMembershipRole {
|
||||||
Admin = "admin",
|
Admin = "admin",
|
||||||
@@ -23,3 +23,6 @@ export const formatProjectRoleName = (name: string) => {
|
|||||||
|
|
||||||
export const isCustomProjectRole = (slug: string) =>
|
export const isCustomProjectRole = (slug: string) =>
|
||||||
!Object.values(ProjectMembershipRole).includes(slug as ProjectMembershipRole);
|
!Object.values(ProjectMembershipRole).includes(slug as ProjectMembershipRole);
|
||||||
|
|
||||||
|
export const findOrgMembershipRole = (roles: TOrgRole[], role: string) =>
|
||||||
|
isCustomOrgRole(role) ? roles.find((r) => r.id === role) : roles.find((r) => r.slug === role);
|
||||||
|
|||||||
+21
-23
@@ -6,14 +6,14 @@ import { z } from "zod";
|
|||||||
import { createNotification } from "@app/components/notifications";
|
import { createNotification } from "@app/components/notifications";
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
FilterableSelect,
|
||||||
FormControl,
|
FormControl,
|
||||||
Input,
|
Input,
|
||||||
Modal,
|
Modal,
|
||||||
ModalContent,
|
ModalContent
|
||||||
Select,
|
|
||||||
SelectItem
|
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { useOrganization } from "@app/context";
|
import { useOrganization } from "@app/context";
|
||||||
|
import { findOrgMembershipRole } from "@app/helpers/roles";
|
||||||
import { useCreateGroup, useGetOrgRoles, useUpdateGroup } from "@app/hooks/api";
|
import { useCreateGroup, useGetOrgRoles, useUpdateGroup } from "@app/hooks/api";
|
||||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
@@ -23,7 +23,7 @@ const GroupFormSchema = z.object({
|
|||||||
.string()
|
.string()
|
||||||
.min(5, "Slug must be at least 5 characters long")
|
.min(5, "Slug must be at least 5 characters long")
|
||||||
.max(36, "Slug must be 36 characters or fewer"),
|
.max(36, "Slug must be 36 characters or fewer"),
|
||||||
role: z.string()
|
role: z.object({ name: z.string(), slug: z.string() })
|
||||||
});
|
});
|
||||||
|
|
||||||
export type TGroupFormData = z.infer<typeof GroupFormSchema>;
|
export type TGroupFormData = z.infer<typeof GroupFormSchema>;
|
||||||
@@ -62,13 +62,13 @@ export const OrgGroupModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Pr
|
|||||||
reset({
|
reset({
|
||||||
name: group.name,
|
name: group.name,
|
||||||
slug: group.slug,
|
slug: group.slug,
|
||||||
role: group?.customRole?.slug ?? group.role
|
role: group?.customRole ?? findOrgMembershipRole(roles, group.role)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reset({
|
reset({
|
||||||
name: "",
|
name: "",
|
||||||
slug: "",
|
slug: "",
|
||||||
role: roles[0].slug
|
role: findOrgMembershipRole(roles, currentOrg!.defaultMembershipRole)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [popUp?.group?.data, roles]);
|
}, [popUp?.group?.data, roles]);
|
||||||
@@ -88,14 +88,14 @@ export const OrgGroupModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Pr
|
|||||||
id: group.groupId,
|
id: group.groupId,
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
role: role || undefined
|
role: role.slug || undefined
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await createMutateAsync({
|
await createMutateAsync({
|
||||||
name,
|
name,
|
||||||
slug,
|
slug,
|
||||||
organizationId: currentOrg.id,
|
organizationId: currentOrg.id,
|
||||||
role: role || undefined
|
role: role.slug || undefined
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handlePopUpToggle("group", false);
|
handlePopUpToggle("group", false);
|
||||||
@@ -121,7 +121,10 @@ export const OrgGroupModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Pr
|
|||||||
reset();
|
reset();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<ModalContent title={`${popUp?.group?.data ? "Update" : "Create"} Group`}>
|
<ModalContent
|
||||||
|
bodyClassName="overflow-visible"
|
||||||
|
title={`${popUp?.group?.data ? "Update" : "Create"} Group`}
|
||||||
|
>
|
||||||
<form onSubmit={handleSubmit(onGroupModalSubmit)}>
|
<form onSubmit={handleSubmit(onGroupModalSubmit)}>
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
@@ -144,26 +147,21 @@ export const OrgGroupModal = ({ popUp, handlePopUpClose, handlePopUpToggle }: Pr
|
|||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
name="role"
|
name="role"
|
||||||
defaultValue=""
|
render={({ field: { onChange, value }, fieldState: { error } }) => (
|
||||||
render={({ field: { onChange, ...field }, fieldState: { error } }) => (
|
|
||||||
<FormControl
|
<FormControl
|
||||||
label={`${popUp?.group?.data ? "Update" : ""} Role`}
|
label={`${popUp?.group?.data ? "Update" : ""} Role`}
|
||||||
errorText={error?.message}
|
errorText={error?.message}
|
||||||
isError={Boolean(error)}
|
isError={Boolean(error)}
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
>
|
>
|
||||||
<Select
|
<FilterableSelect
|
||||||
defaultValue={field.value}
|
options={roles}
|
||||||
{...field}
|
placeholder="Select role..."
|
||||||
onValueChange={(e) => onChange(e)}
|
onChange={onChange}
|
||||||
className="w-full"
|
value={value}
|
||||||
>
|
getOptionValue={(option) => option.slug}
|
||||||
{(roles || []).map(({ name, slug }) => (
|
getOptionLabel={(option) => option.name}
|
||||||
<SelectItem value={slug} key={`org-group-role-${slug}`}>
|
/>
|
||||||
{name}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
|||||||
+3
-5
@@ -18,7 +18,7 @@ import {
|
|||||||
ModalContent
|
ModalContent
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { useOrganization } from "@app/context";
|
import { useOrganization } from "@app/context";
|
||||||
import { isCustomOrgRole } from "@app/helpers/roles";
|
import { findOrgMembershipRole } from "@app/helpers/roles";
|
||||||
import { useCreateIdentity, useGetOrgRoles, useUpdateIdentity } from "@app/hooks/api";
|
import { useCreateIdentity, useGetOrgRoles, useUpdateIdentity } from "@app/hooks/api";
|
||||||
import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
|
import { useAddIdentityUniversalAuth } from "@app/hooks/api/identities";
|
||||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
@@ -98,15 +98,13 @@ export const IdentityModal = ({ popUp, handlePopUpToggle }: Props) => {
|
|||||||
if (identity) {
|
if (identity) {
|
||||||
reset({
|
reset({
|
||||||
name: identity.name,
|
name: identity.name,
|
||||||
role: identity?.customRole ?? roles.find((role) => role.slug === identity.role),
|
role: identity.customRole ?? findOrgMembershipRole(roles, identity.role),
|
||||||
metadata: identity.metadata
|
metadata: identity.metadata
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reset({
|
reset({
|
||||||
name: "",
|
name: "",
|
||||||
role: isCustomOrgRole(currentOrg?.defaultMembershipRole!)
|
role: findOrgMembershipRole(roles, currentOrg!.defaultMembershipRole)
|
||||||
? roles?.find((role) => role.id === currentOrg?.defaultMembershipRole)
|
|
||||||
: roles?.find((role) => role.slug === currentOrg?.defaultMembershipRole)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [popUp?.identity?.data, roles]);
|
}, [popUp?.identity?.data, roles]);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import {
|
|||||||
ModalContent
|
ModalContent
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { useOrganization, useSubscription } from "@app/context";
|
import { useOrganization, useSubscription } from "@app/context";
|
||||||
import { isCustomOrgRole } from "@app/helpers/roles";
|
import { findOrgMembershipRole, isCustomOrgRole } from "@app/helpers/roles";
|
||||||
import { useGetOrgRoles, useUpdateOrgMembership } from "@app/hooks/api";
|
import { useGetOrgRoles, useUpdateOrgMembership } from "@app/hooks/api";
|
||||||
import { UsePopUpState } from "@app/hooks/usePopUp";
|
import { UsePopUpState } from "@app/hooks/usePopUp";
|
||||||
|
|
||||||
@@ -75,18 +75,13 @@ export const UserOrgMembershipModal = ({ popUp, handlePopUpOpen, handlePopUpTogg
|
|||||||
if (!roles?.length) return;
|
if (!roles?.length) return;
|
||||||
|
|
||||||
if (popUpData) {
|
if (popUpData) {
|
||||||
console.log("roles", roles, popUpData.roleId);
|
|
||||||
reset({
|
reset({
|
||||||
role: popUpData.roleId
|
role: findOrgMembershipRole(roles, popUpData.roleId ?? popUpData.role),
|
||||||
? roles?.find((role) => role.id === popUpData.roleId)
|
|
||||||
: roles?.find((role) => role.slug === popUpData.role),
|
|
||||||
metadata: popUpData.metadata
|
metadata: popUpData.metadata
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reset({
|
reset({
|
||||||
role: isCustomOrgRole(currentOrg?.defaultMembershipRole!)
|
role: findOrgMembershipRole(roles, currentOrg!.defaultMembershipRole!)
|
||||||
? roles?.find((role) => role.id === currentOrg?.defaultMembershipRole)
|
|
||||||
: roles?.find((role) => role.slug === currentOrg?.defaultMembershipRole)
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}, [popUp?.orgMembership?.data, roles]);
|
}, [popUp?.orgMembership?.data, roles]);
|
||||||
|
|||||||
Reference in New Issue
Block a user