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

fix(ui): correct credentials display when only LDAP provider exists #3665

Merged
merged 1 commit into from
Jan 14, 2025
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
@@ -1,13 +1,14 @@
'use client'

import React from 'react'
import React, { useMemo } from 'react'
import Link from 'next/link'
import { useRouter } from 'next/navigation'
import { compact, find } from 'lodash-es'
import { useQuery } from 'urql'

import { graphql } from '@/lib/gql/generates'
import {
AuthProviderKind,
LdapCredentialQuery,
LicenseType,
OAuthCredentialQuery,
Expand Down Expand Up @@ -40,6 +41,10 @@ export const oauthCredential = graphql(/* GraphQL */ `
`)

export const CredentialList = () => {
const authProviderKindCount = useMemo(() => {
return Object.keys(AuthProviderKind).length
}, [])

const [{ data: githubData, fetching: fetchingGithub }] = useQuery({
query: oauthCredential,
variables: { provider: OAuthProvider.Github }
Expand All @@ -59,13 +64,15 @@ export const CredentialList = () => {

const isLoading =
fetchingGithub || fetchingGoogle || fetchingGitlab || fetchingLdap

const credentialList = React.useMemo(() => {
return compact([
githubData?.oauthCredential,
googleData?.oauthCredential,
gitlabData?.oauthCredential
gitlabData?.oauthCredential,
ldapData?.ldapCredential
])
}, [githubData, googleData, gitlabData])
}, [githubData, googleData, gitlabData, ldapData])

const router = useRouter()
const createButton = (
Expand Down Expand Up @@ -113,13 +120,19 @@ export const CredentialList = () => {
<div>
<div className="flex flex-col gap-8">
{credentialList.map(credential => {
return (
<OauthCredentialCard key={credential.provider} data={credential} />
)
if ('provider' in credential) {
return (
<OauthCredentialCard
key={credential.provider}
data={credential}
/>
)
} else {
return <LDAPCredentialCard key="ldap" data={credential} />
}
})}
<LDAPCredentialCard data={ldapData?.ldapCredential} />
</div>
{credentialList.length < 3 && (
{credentialList.length < authProviderKindCount && (
<div className="mt-4 flex justify-end">{createButton}</div>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,24 @@ export function NewPage() {
const [type, setType] = useState<SSOType>('oauth')
const router = useRouter()

const onCreateSuccess = () => {
router.replace('/settings/sso')
}

return (
<div>
<SSOTypeRadio value={type} onChange={setType} />
{type === 'oauth' ? (
<OAuthCredentialForm provider={OAuthProvider.Github} isNew />
<OAuthCredentialForm
provider={OAuthProvider.Github}
isNew
onSuccess={onCreateSuccess}
/>
) : (
<LDAPCredentialForm
isNew
defaultValues={{ skipTlsVerify: false }}
onSuccess={() => {
router.replace('/settings/sso')
}}
onSuccess={onCreateSuccess}
/>
)}
</div>
Expand Down
Loading