|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { CButton, CCardBody, CSpinner, CCard, CCardHeader, CCardTitle } from '@coreui/react' |
| 3 | +import { useSelector } from 'react-redux' |
| 4 | +import { faEllipsisV } from '@fortawesome/free-solid-svg-icons' |
| 5 | +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' |
| 6 | +import { CippPageList, CippPage } from 'src/components/layout' |
| 7 | +import { TitleButton } from 'src/components/buttons' |
| 8 | +import { CippActionsOffcanvas } from 'src/components/utilities' |
| 9 | +import { useGenericGetRequestQuery } from 'src/store/api/app' |
| 10 | +import { CippTable, cellBooleanFormatter } from 'src/components/tables' |
| 11 | +import { CellTip, cellGenericFormatter } from 'src/components/tables/CellGenericFormat' |
| 12 | + |
| 13 | +const Offcanvas = (row, rowIndex, formatExtraData) => { |
| 14 | + const tenant = useSelector((state) => state.app.currentTenant) |
| 15 | + const [ocVisible, setOCVisible] = useState(false) |
| 16 | + const formatTargets = (targets) => { |
| 17 | + if (Array.isArray(targets)) { |
| 18 | + return targets.map((target) => JSON.stringify(target)).join(', ') |
| 19 | + } |
| 20 | + return targets |
| 21 | + } |
| 22 | + |
| 23 | + return ( |
| 24 | + <> |
| 25 | + <CButton size="sm" color="link" onClick={() => setOCVisible(true)}> |
| 26 | + <FontAwesomeIcon icon={faEllipsisV} /> |
| 27 | + </CButton> |
| 28 | + <CippActionsOffcanvas |
| 29 | + title="Extended Information" |
| 30 | + extendedInfo={[ |
| 31 | + { label: 'id', value: `${row.id}` }, |
| 32 | + { label: 'state', value: `${row.state}` }, |
| 33 | + { label: 'includeTargets', value: formatTargets(row.includeTargets) }, |
| 34 | + { label: 'excludeTargets', value: formatTargets(row.excludeTargets) }, |
| 35 | + ]} |
| 36 | + actions={[ |
| 37 | + { |
| 38 | + label: 'Enable Policy', |
| 39 | + color: 'info', |
| 40 | + modal: true, |
| 41 | + modalType: 'POST', |
| 42 | + modalBody: { |
| 43 | + id: row.id, |
| 44 | + state: 'enabled', |
| 45 | + TenantFilter: tenant.defaultDomainName, |
| 46 | + }, |
| 47 | + modalUrl: `/api/SetAuthMethod`, |
| 48 | + modalMessage: 'Are you sure you want to enable this policy?', |
| 49 | + }, |
| 50 | + { |
| 51 | + label: 'Disable Policy', |
| 52 | + color: 'info', |
| 53 | + modal: true, |
| 54 | + modalType: 'POST', |
| 55 | + modalBody: { |
| 56 | + id: row.id, |
| 57 | + state: 'disabled', |
| 58 | + TenantFilter: tenant.defaultDomainName, |
| 59 | + }, |
| 60 | + modalUrl: `/api/SetAuthMethod`, |
| 61 | + modalMessage: 'Are you sure you want to enable this policy?', |
| 62 | + }, |
| 63 | + ]} |
| 64 | + placement="end" |
| 65 | + visible={ocVisible} |
| 66 | + id={row.id} |
| 67 | + hideFunction={() => setOCVisible(false)} |
| 68 | + /> |
| 69 | + </> |
| 70 | + ) |
| 71 | +} |
| 72 | + |
| 73 | +const columns = [ |
| 74 | + { |
| 75 | + name: 'id', |
| 76 | + selector: (row) => row['id'], |
| 77 | + sortable: true, |
| 78 | + exportSelector: 'id', |
| 79 | + }, |
| 80 | + { |
| 81 | + name: 'state', |
| 82 | + selector: (row) => row['state'], |
| 83 | + cell: cellBooleanFormatter({ colourless: false }), |
| 84 | + sortable: true, |
| 85 | + exportSelector: 'state', |
| 86 | + minWidth: '100px', |
| 87 | + }, |
| 88 | + { |
| 89 | + name: 'includeTargets', |
| 90 | + selector: (row) => row['includeTargets'], |
| 91 | + sortable: true, |
| 92 | + cell: cellGenericFormatter(), |
| 93 | + exportSelector: 'includeTargets', |
| 94 | + }, |
| 95 | + { |
| 96 | + name: 'excludeTargets', |
| 97 | + selector: (row) => row['excludeTargets'], |
| 98 | + sortable: true, |
| 99 | + cell: cellGenericFormatter(), |
| 100 | + exportSelector: 'excludeTargets', |
| 101 | + }, |
| 102 | + { |
| 103 | + name: 'Actions', |
| 104 | + cell: Offcanvas, |
| 105 | + }, |
| 106 | +] |
| 107 | + |
| 108 | +const AuthenticationMethods = () => { |
| 109 | + const tenant = useSelector((state) => state.app.currentTenant) |
| 110 | + const { data, isFetching, error, isSuccess, refetch } = useGenericGetRequestQuery({ |
| 111 | + path: 'api/ListGraphRequest', |
| 112 | + params: { |
| 113 | + Endpoint: 'authenticationMethodsPolicy', |
| 114 | + TenantFilter: tenant?.defaultDomainName, |
| 115 | + }, |
| 116 | + }) |
| 117 | + return ( |
| 118 | + <> |
| 119 | + <CippPage title="Auth Methods" tenantSelector={true}> |
| 120 | + <CCard className="content-card"> |
| 121 | + <CCardHeader className="d-flex justify-content-between align-items-center"> |
| 122 | + <CCardTitle>Auth Methods</CCardTitle> |
| 123 | + </CCardHeader> |
| 124 | + <CCardBody> |
| 125 | + {isFetching && <CSpinner />} |
| 126 | + {isSuccess && ( |
| 127 | + <CippTable |
| 128 | + reportName={`Auth Methods`} |
| 129 | + data={data?.Results[0]?.authenticationMethodConfigurations} |
| 130 | + columns={columns} |
| 131 | + refreshFunction={() => refetch()} |
| 132 | + /> |
| 133 | + )} |
| 134 | + </CCardBody> |
| 135 | + </CCard> |
| 136 | + </CippPage> |
| 137 | + </> |
| 138 | + ) |
| 139 | +} |
| 140 | + |
| 141 | +export default AuthenticationMethods |
0 commit comments