Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(console): use correct array for checking enterprise sso #6135

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ function JitSettings({ form }: Props) {
{ initialSize: Number.POSITIVE_INFINITY }
);
const allSsoConnectors = useMemo(() => ssoConnectorMatrix?.flat(), [ssoConnectorMatrix]);
const filteredSsoConnectors = useMemo(
() => allSsoConnectors?.filter(({ id }) => !ssoConnectorIds.includes(id)),
[allSsoConnectors, ssoConnectorIds]
);
const hasSsoEnabled = useCallback(
(domain: string) => allSsoConnectors?.some(({ domains }) => domains.includes(domain)),
[allSsoConnectors]
Expand All @@ -65,6 +69,7 @@ function JitSettings({ form }: Props) {
description="organization_details.jit.description"
>
<FormField
className={styles.jitFormField}
title="organization_details.jit.enterprise_sso"
description={
<Trans
Expand All @@ -81,73 +86,74 @@ function JitSettings({ form }: Props) {
}
descriptionPosition="top"
>
{ssoConnectorIds.length === 0 && (
{!allSsoConnectors?.length && (
<InlineNotification>
<Trans
i18nKey="admin_console.organization_details.jit.no_enterprise_connector_set"
components={{ a: <TextLink to={'/' + enterpriseSso.path} /> }}
/>
</InlineNotification>
)}
{ssoConnectorIds.length > 0 && (
<Controller
name="jitSsoConnectorIds"
control={control}
render={({ field: { onChange, value } }) => (
<div className={styles.ssoConnectorList}>
{value.map((id) => {
const connector = allSsoConnectors?.find(
({ id: connectorId }) => id === connectorId
);
return (
connector && (
<div key={connector.id} className={styles.ssoConnector}>
<div className={styles.info}>
<SsoConnectorLogo className={styles.icon} data={connector} />
<span>
{connector.connectorName} - {connector.providerName}
</span>
<Controller
name="jitSsoConnectorIds"
control={control}
render={({ field: { onChange, value } }) => (
<>
{value.length > 0 && (
<div className={styles.ssoConnectorList}>
{value.map((id) => {
const connector = allSsoConnectors?.find(
({ id: connectorId }) => id === connectorId
);
return (
connector && (
<div key={connector.id} className={styles.ssoConnector}>
<div className={styles.info}>
<SsoConnectorLogo className={styles.icon} data={connector} />
<span>
{connector.connectorName} - {connector.providerName}
</span>
</div>
<IconButton
onClick={() => {
onChange(value.filter((value) => value !== id));
}}
>
<Minus />
</IconButton>
</div>
<IconButton
onClick={() => {
onChange(value.filter((value) => value !== id));
}}
>
<Minus />
</IconButton>
</div>
)
);
})}
)
);
})}
</div>
)}
{Boolean(filteredSsoConnectors?.length) && (
<ActionMenu
buttonProps={{
type: 'default',
size: 'medium',
title: 'organization_details.jit.add_enterprise_connector',
icon: <Plus />,
className: styles.addSsoConnectorButton,
}}
dropdownHorizontalAlign="start"
>
{allSsoConnectors
?.filter(({ id }) => !value.includes(id))
.map((connector) => (
<DropdownItem
key={connector.id}
className={styles.dropdownItem}
onClick={() => {
onChange([...value, connector.id]);
}}
>
<SsoConnectorLogo className={styles.icon} data={connector} />
<span>{connector.connectorName}</span>
</DropdownItem>
))}
{filteredSsoConnectors?.map((connector) => (
<DropdownItem
key={connector.id}
className={styles.dropdownItem}
onClick={() => {
onChange([...value, connector.id]);
}}
>
<SsoConnectorLogo className={styles.icon} data={connector} />
<span>{connector.connectorName}</span>
</DropdownItem>
))}
</ActionMenu>
</div>
)}
/>
)}
)}
</>
)}
/>
</FormField>
<FormField
title="organization_details.jit.email_domain"
Expand Down Expand Up @@ -208,7 +214,7 @@ function JitSettings({ form }: Props) {
)}
/>
{hasSsoEnabledEmailDomain && (
<InlineNotification severity="alert" className={styles.warning}>
<InlineNotification severity="alert">
{t('organization_details.jit.sso_enabled_domain_warning')}
</InlineNotification>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
}
}


.warning {
margin-top: _.unit(3);
.jitFormField {
display: flex;
flex-direction: column;
gap: _.unit(3);
}

.addSsoConnectorButton {
.mfaWarning {
margin-top: _.unit(3);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function Settings() {
{...register('isMfaRequired')}
/>
{isMfaRequired && signInExperience?.mfa.factors.length === 0 && (
<InlineNotification severity="alert" className={styles.warning}>
<InlineNotification severity="alert" className={styles.mfaWarning}>
<Trans
i18nKey="admin_console.organization_details.mfa.no_mfa_warning"
components={{
Expand Down
Loading