feat: Okta(SCIM2.0) -> Attributes Sync and Group Option support (#17805)
This commit is contained in:
1 parent
d5ef3e1d72
commit
7e76770ba6
46 files changed
+3688
-307
No files matched your search
@@ -283,6 +283,8 @@ function MassAssignAttributesBulkActionComponent({ table, filters }: Props) {
|
||||
attributeId: value.attributeId,
|
||||
value: value.value,
|
||||
slug: value.slug,
|
||||
contains: value.contains,
|
||||
isGroup: value.isGroup,
|
||||
}));
|
||||
newAttributes.push(...newAttributeValues);
|
||||
} else {
|
||||
@@ -292,6 +294,8 @@ function MassAssignAttributesBulkActionComponent({ table, filters }: Props) {
|
||||
attributeId: foundAttributeInCache?.id ?? "-1",
|
||||
value: selectedAttributeOptions[0],
|
||||
slug: slugify(selectedAttributeOptions[0]),
|
||||
contains: [],
|
||||
isGroup: false,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -40,7 +40,15 @@ const stringOrNumber = z.string().or(z.number());
|
||||
|
||||
const attributeSchema = z.object({
|
||||
id: z.string(),
|
||||
options: z.array(z.object({ label: z.string().optional(), value: stringOrNumber.optional() })).optional(),
|
||||
options: z
|
||||
.array(
|
||||
z.object({
|
||||
label: z.string().optional(),
|
||||
value: stringOrNumber.optional(),
|
||||
createdByDSyncId: z.string().nullable().optional(),
|
||||
})
|
||||
)
|
||||
.optional(),
|
||||
value: stringOrNumber.optional(),
|
||||
});
|
||||
|
||||
@@ -228,10 +236,10 @@ export function EditForm({
|
||||
);
|
||||
}
|
||||
|
||||
type AttributeType = z.infer<typeof attributeSchema>;
|
||||
type Attribute = z.infer<typeof attributeSchema>;
|
||||
|
||||
type DefaultValueType = {
|
||||
[key: `attributes.${number}`]: AttributeType;
|
||||
[key: `attributes.${number}`]: Attribute;
|
||||
};
|
||||
|
||||
function AttributesList(props: { selectedUserId: number }) {
|
||||
@@ -267,12 +275,22 @@ function AttributesList(props: { selectedUserId: number }) {
|
||||
} else if (attr.type === "MULTI_SELECT") {
|
||||
acc[key] = {
|
||||
id: attr.id,
|
||||
options: attr.options.map((option) => ({ label: option.value, value: option.id })),
|
||||
options: attr.options.map((option) => ({
|
||||
label: option.value,
|
||||
value: option.id,
|
||||
createdByDSyncId: option.createdByDSyncId,
|
||||
})),
|
||||
};
|
||||
} else if (attr.type === "SINGLE_SELECT") {
|
||||
acc[key] = {
|
||||
id: attr.id,
|
||||
options: [{ label: attr.options[0]?.value, value: attr.options[0]?.id }],
|
||||
options: [
|
||||
{
|
||||
label: attr.options[0]?.value,
|
||||
value: attr.options[0]?.id,
|
||||
createdByDSyncId: attr.options[0]?.createdByDSyncId ?? null,
|
||||
},
|
||||
],
|
||||
};
|
||||
} else {
|
||||
acc[key] = {
|
||||
@@ -302,7 +320,8 @@ function AttributesList(props: { selectedUserId: number }) {
|
||||
control={control}
|
||||
key={attr.id}
|
||||
defaultValue={defaultValues[`attributes.${index}`]}
|
||||
render={({ field }) => {
|
||||
render={({ field: { value, ...field } }) => {
|
||||
const fieldValue = value as Attribute | undefined | null;
|
||||
return (
|
||||
<div className="flex w-full items-center justify-center gap-2" key={attr.id}>
|
||||
{["TEXT", "NUMBER"].includes(attr.type) && (
|
||||
@@ -312,7 +331,7 @@ function AttributesList(props: { selectedUserId: number }) {
|
||||
labelClassName="text-emphasis mb-2 block text-sm font-medium leading-none"
|
||||
label={attr.name}
|
||||
type={attr.type === "TEXT" ? "text" : "number"}
|
||||
value={field.value?.value || ""}
|
||||
value={fieldValue?.value || ""}
|
||||
onChange={(e) => {
|
||||
field.onChange({
|
||||
id: attr.id,
|
||||
@@ -323,6 +342,7 @@ function AttributesList(props: { selectedUserId: number }) {
|
||||
)}
|
||||
{["SINGLE_SELECT", "MULTI_SELECT"].includes(attr.type) && (
|
||||
<SelectField
|
||||
isDisabled={attr.isLocked}
|
||||
name={field.name}
|
||||
containerClassName="w-full"
|
||||
isMulti={attr.type === "MULTI_SELECT"}
|
||||
@@ -331,19 +351,24 @@ function AttributesList(props: { selectedUserId: number }) {
|
||||
}}
|
||||
label={attr.name}
|
||||
options={getOptionsByAttributeId(attr.id)}
|
||||
value={attr.type === "MULTI_SELECT" ? field.value?.options : field.value?.options[0]}
|
||||
value={attr.type === "MULTI_SELECT" ? fieldValue?.options : fieldValue?.options?.[0]}
|
||||
onChange={(value) => {
|
||||
if (attr.type === "MULTI_SELECT") {
|
||||
field.onChange({
|
||||
id: attr.id,
|
||||
options: value.map((v: any) => ({ label: v.label, value: v.value })),
|
||||
});
|
||||
} else {
|
||||
field.onChange({
|
||||
id: attr.id,
|
||||
options: [{ label: value.label, value: value.value }],
|
||||
});
|
||||
}
|
||||
if (!value) return;
|
||||
const valueAsArray = value instanceof Array ? value : [value];
|
||||
|
||||
const updatedOptions =
|
||||
attr.type === "MULTI_SELECT"
|
||||
? valueAsArray.map((v) => ({ label: v.label, value: v.value }))
|
||||
: [{ label: valueAsArray[0].label, value: valueAsArray[0].value }];
|
||||
|
||||
field.onChange({
|
||||
id: attr.id,
|
||||
// It is also ensured in the backend that the options not owned by cal.com are not removed
|
||||
options: getOptionsEnsuringNotOwnedByCalcomNotRemoved({
|
||||
earlierOptions: fieldValue?.options || [],
|
||||
updatedOptions,
|
||||
}),
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
@@ -356,3 +381,31 @@ function AttributesList(props: { selectedUserId: number }) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that options that are not owned by cal.com are not removed
|
||||
* Such options are created by dsync and removed only through corresponding dsync
|
||||
*/
|
||||
function getOptionsEnsuringNotOwnedByCalcomNotRemoved<
|
||||
// Before assigning this option it can't have createdByDSyncId set
|
||||
TOptionToChoose extends { value: string | number | undefined },
|
||||
// Already set option can have createdByDSyncId set
|
||||
TOptionAlreadySet extends {
|
||||
value?: string | number | undefined;
|
||||
createdByDSyncId?: string | null | undefined;
|
||||
}
|
||||
>({
|
||||
earlierOptions,
|
||||
updatedOptions,
|
||||
}: {
|
||||
earlierOptions: TOptionAlreadySet[];
|
||||
updatedOptions: TOptionToChoose[];
|
||||
}) {
|
||||
const optionsNotOwnedByCalcom = earlierOptions.filter((option) => !!option.createdByDSyncId);
|
||||
|
||||
const newUniqueOptionsPlusNotOwnedByCalcom = [...optionsNotOwnedByCalcom, ...updatedOptions].filter(
|
||||
(option, index, self) => index === self.findIndex((o) => o.value === option.value && o.value)
|
||||
);
|
||||
|
||||
return newUniqueOptionsPlusNotOwnedByCalcom;
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { keepPreviousData } from "@tanstack/react-query";
|
||||
import {
|
||||
getCoreRowModel,
|
||||
getFilteredRowModel,
|
||||
getSortedRowModel,
|
||||
useReactTable,
|
||||
type ColumnDef,
|
||||
} from "@tanstack/react-table";
|
||||
import { getCoreRowModel, getSortedRowModel, useReactTable, type ColumnDef } from "@tanstack/react-table";
|
||||
import { useSession } from "next-auth/react";
|
||||
import { useQueryState, parseAsBoolean } from "nuqs";
|
||||
import { useMemo, useReducer, useRef, useState } from "react";
|
||||
@@ -185,11 +179,14 @@ export function UserListTable() {
|
||||
if (attributeValues.length === 0) return null;
|
||||
return (
|
||||
<div className={classNames(attribute.type === "NUMBER" ? "flex w-full justify-center" : "")}>
|
||||
{attributeValues.map((attributeValue, index) => (
|
||||
<Badge key={index} variant="gray" className="mr-1">
|
||||
{attributeValue.value}
|
||||
</Badge>
|
||||
))}
|
||||
{attributeValues.map((attributeValue, index) => {
|
||||
const isAGroupOption = attributeValue.contains?.length > 0;
|
||||
return (
|
||||
<Badge key={index} variant={isAGroupOption ? "orange" : "gray"} className="mr-1">
|
||||
{attributeValue.value}
|
||||
</Badge>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
@@ -405,8 +402,6 @@ export function UserListTable() {
|
||||
rowSelection,
|
||||
},
|
||||
getCoreRowModel: getCoreRowModel(),
|
||||
// TODO(SEAN): We need to move filter state to the server so we can fetch more data when the filters change if theyre not in client cache
|
||||
getFilteredRowModel: getFilteredRowModel(),
|
||||
getSortedRowModel: getSortedRowModel(),
|
||||
onRowSelectionChange: setRowSelection,
|
||||
getRowId: (row) => `${row.id}`,
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface UserTableUser {
|
||||
attributeId: string;
|
||||
value: string;
|
||||
slug: string;
|
||||
contains: string[];
|
||||
}[];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user