Skip to content

Commit

Permalink
feat(admin-ui): list OIDC according to ticket 204
Browse files Browse the repository at this point in the history
  • Loading branch information
mjatin-dev committed May 6, 2022
1 parent 54a3eef commit f341b7f
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 14 deletions.
69 changes: 55 additions & 14 deletions admin-ui/plugins/auth-server/components/Clients/ClientListPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useHistory } from 'react-router-dom'
import { connect } from 'react-redux'
import { Paper } from '@material-ui/core'
import { Card, CardBody, FormGroup, Badge } from '../../../../app/components'
import { getScopes } from '../../redux/actions/ScopeActions'
import GluuRibbon from '../../../../app/routes/Apps/Gluu/GluuRibbon'
import GluuDialog from '../../../../app/routes/Apps/Gluu/GluuDialog'
import ClientDetailPage from '../Clients/ClientDetailPage'
Expand Down Expand Up @@ -34,6 +35,7 @@ import {
CLIENT_READ,
CLIENT_DELETE,
} from '../../../../app/utils/PermChecker'
import ClientShowScopes from './ClientShowScopes'

function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
const { t } = useTranslation()
Expand All @@ -43,6 +45,10 @@ function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
const history = useHistory()
const pageSize = localStorage.getItem('paggingSize') || 10

const [scopesModal, setScopesModal] = useState({
data: [],
show: false,
})
const [limit, setLimit] = useState(200)
const [pattern, setPattern] = useState(null)
const [item, setItem] = useState({})
Expand All @@ -52,6 +58,18 @@ function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
let memoLimit = limit
let memoPattern = pattern

const handler = () => {
setScopesModal({
data: [],
show: false,
})
}
const setScopeData = (data) => {
setScopesModal({
data: data,
show: true,
})
}
const tableColumns = [
{
title: `${t('fields.inum')}`,
Expand All @@ -60,21 +78,35 @@ function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
sorting: true,
searchable: true,
},
{ title: `${t('fields.client_id')}`, field: 'inum' },
{ title: `${t('fields.client_name')}`, field: 'displayName' },
{
title: `${t('fields.application_type')}`,
field: 'applicationType',
title: `${t('fields.grant_types')}`,
field: 'grantTypes',
render: (rowData) => {
return rowData.grantTypes.map((data) => {
return (
<div style={{ maxWidth: 120, overflow: 'auto' }}>
<Badge color="primary">{data}</Badge>
</div>
)
})
},
},
{ title: `${t('fields.subject_type')}`, field: 'subjectType' },
{
title: `${t('fields.status')}`,
field: 'disabled',
type: 'boolean',
render: (rowData) => (
<Badge color={getBadgeTheme(rowData.disabled)}>
{getClientStatus(rowData.disabled)}
</Badge>
),
title: `${t('fields.scopes')}`,
field: 'scopes',
render: (rowData) => {
return (
<Badge
color="primary"
role={'button'}
onClick={() => setScopeData(rowData.scopes)}
>
{rowData.scopes?.length || '0'}
</Badge>
)
},
},
{
title: `${t('fields.is_trusted_client')}`,
Expand All @@ -92,6 +124,10 @@ function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
buildPayload(userAction, FETCHING_OIDC_CLIENTS, options)
dispatch(getOpenidClients(userAction))
}, [])
useEffect(() => {
buildPayload(userAction, '', options)
dispatch(getScopes(userAction))
}, [])
function handleOptionsChange(event) {
if (event.target.name == 'limit') {
memoLimit = event.target.value
Expand Down Expand Up @@ -162,8 +198,6 @@ function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
iconProps: { color: 'primary' },
isFreeAction: true,
onClick: () => {
// setLimit(memoLimit)
// setPattern(memoLimit)
makeOptions()
buildPayload(userAction, SEARCHING_OIDC_CLIENTS, options)
dispatch(searchClients(userAction))
Expand Down Expand Up @@ -204,7 +238,7 @@ function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
onClick: () => handleGoToClientAddPage(),
})
}

//ToDo to be deleted
function getBadgeTheme(status) {
if (!status) {
return 'primary'
Expand All @@ -220,15 +254,22 @@ function ClientListPage({ clients, permissions, scopes, loading, dispatch }) {
return 'info'
}
}
//ToDo to be deleted
function getClientStatus(status) {
if (!status) {
return t('options.enabled')
} else {
return t('options.disabled')
}
}

return (
<Card>
<ClientShowScopes
handler={handler}
isOpen={scopesModal.show}
data={scopesModal.data}
/>
<GluuRibbon title={t('titles.oidc_clients')} fromLeft />
<CardBody>
<FormGroup row />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react'
import { Button, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap'
import { Badge } from '../../../../app/components'
import { useSelector } from 'react-redux'

function ClientShowScopes({ handler, data, isOpen }) {
const scopes = useSelector((state) => state.scopeReducer.items)
const clientScopes = scopes
.filter((item) => data.includes(item.dn, 0))
.map((item) => item.id)
return (
<Modal isOpen={isOpen} toggle={handler} className="modal-outline-primary">
<ModalHeader>Scopes</ModalHeader>
<ModalBody>
{clientScopes.map((scope, key) => {
return (
<div>
<Badge color="primary" key={key}>
{scope}
</Badge>
</div>
)
})}
</ModalBody>
<ModalFooter>
<Button color="secondary" onClick={handler}>
Close
</Button>
</ModalFooter>
</Modal>
)
}
export default ClientShowScopes

0 comments on commit f341b7f

Please sign in to comment.