|
| 1 | +import React, { useState } from 'react' |
| 2 | +import { useSelector } from 'react-redux' |
| 3 | +import { CButton } from '@coreui/react' |
| 4 | +import { |
| 5 | + faBook, |
| 6 | + faEdit, |
| 7 | + faEllipsisV, |
| 8 | + faGlobeEurope, |
| 9 | + faPager, |
| 10 | + faTrashAlt, |
| 11 | + faUser, |
| 12 | +} from '@fortawesome/free-solid-svg-icons' |
| 13 | +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' |
| 14 | +import { CippPageList } from 'src/components/layout' |
| 15 | +import { Link } from 'react-router-dom' |
| 16 | +import { CippActionsOffcanvas, CippCodeBlock } from 'src/components/utilities' |
| 17 | +import { TitleButton } from 'src/components/buttons' |
| 18 | +import { cellBooleanFormatter, cellDateFormatter } from 'src/components/tables' |
| 19 | + |
| 20 | +const Actions = (row, rowIndex, formatExtraData) => { |
| 21 | + const [ocVisible, setOCVisible] = useState(false) |
| 22 | + console.log(row) |
| 23 | + const tenant = useSelector((state) => state.app.currentTenant) |
| 24 | + return ( |
| 25 | + <> |
| 26 | + <CButton size="sm" color="link" onClick={() => setOCVisible(true)}> |
| 27 | + <FontAwesomeIcon icon={faEllipsisV} /> |
| 28 | + </CButton> |
| 29 | + <CippActionsOffcanvas |
| 30 | + title="Policy Information" |
| 31 | + extendedInfo={[ |
| 32 | + { label: 'Created on', value: `${row.createdDateTime}` }, |
| 33 | + { label: 'Display Name', value: `${row.displayName}` }, |
| 34 | + { label: 'Last Modified', value: `${row.lastModifiedDateTime}` }, |
| 35 | + { label: 'Type', value: `${row.PolicyTypeName}` }, |
| 36 | + ]} |
| 37 | + actions={[ |
| 38 | + { |
| 39 | + label: 'Create template based on policy (beta)', |
| 40 | + color: 'info', |
| 41 | + modal: true, |
| 42 | + icon: <FontAwesomeIcon icon={faBook} className="me-2" />, |
| 43 | + modalUrl: `/api/AddIntuneTemplate?TenantFilter=${tenant.defaultDomainName}&ID=${row.id}&URLName=deviceCompliancePolicies`, |
| 44 | + modalMessage: 'Are you sure you want to create a template based on this policy?', |
| 45 | + }, |
| 46 | + { |
| 47 | + icon: <FontAwesomeIcon icon={faUser} />, |
| 48 | + label: ' Assign to All Users', |
| 49 | + color: 'info', |
| 50 | + modal: true, |
| 51 | + modalUrl: `/api/ExecAssignPolicy?AssignTo=allLicensedUsers&TenantFilter=${tenant.defaultDomainName}&ID=${row.id}&type=deviceCompliancePolicies`, |
| 52 | + modalMessage: `Are you sure you want to assign ${row.displayName} to all users?`, |
| 53 | + }, |
| 54 | + { |
| 55 | + icon: <FontAwesomeIcon icon={faPager} />, |
| 56 | + label: ' Assign to All Devices', |
| 57 | + color: 'info', |
| 58 | + modal: true, |
| 59 | + modalUrl: `/api/ExecAssignPolicy?AssignTo=AllDevices&TenantFilter=${tenant.defaultDomainName}&ID=${row.id}&type=deviceCompliancePolicies`, |
| 60 | + modalMessage: `Are you sure you want to assign ${row.displayName} to all devices?`, |
| 61 | + }, |
| 62 | + { |
| 63 | + icon: <FontAwesomeIcon icon={faGlobeEurope} />, |
| 64 | + label: ' Assign Globally (All Users / All Devices)', |
| 65 | + color: 'info', |
| 66 | + modal: true, |
| 67 | + modalUrl: `/api/ExecAssignPolicy?AssignTo=AllDevicesAndUsers&TenantFilter=${tenant.defaultDomainName}&ID=${row.id}&type=deviceCompliancePolicies`, |
| 68 | + modalMessage: `Are you sure you want to assign ${row.displayName} to all users and devices?`, |
| 69 | + }, |
| 70 | + { |
| 71 | + label: 'Delete Policy', |
| 72 | + color: 'danger', |
| 73 | + modal: true, |
| 74 | + icon: <FontAwesomeIcon icon={faTrashAlt} className="me-2" />, |
| 75 | + modalUrl: `/api/RemovePolicy?TenantFilter=${tenant.defaultDomainName}&ID=${row.id}&URLName=${row.URLName}`, |
| 76 | + modalMessage: 'Are you sure you want to delete this policy?', |
| 77 | + }, |
| 78 | + ]} |
| 79 | + placement="end" |
| 80 | + visible={ocVisible} |
| 81 | + id={row.id} |
| 82 | + hideFunction={() => setOCVisible(false)} |
| 83 | + /> |
| 84 | + </> |
| 85 | + ) |
| 86 | +} |
| 87 | + |
| 88 | +const columns = [ |
| 89 | + { |
| 90 | + selector: (row) => row['displayName'], |
| 91 | + name: 'Name', |
| 92 | + sortable: true, |
| 93 | + exportSelector: 'displayName', |
| 94 | + }, |
| 95 | + { |
| 96 | + selector: (row) => row['description'], |
| 97 | + name: 'Description', |
| 98 | + sortable: true, |
| 99 | + exportSelector: 'description', |
| 100 | + }, |
| 101 | + { |
| 102 | + selector: (row) => row['lastModifiedDateTime'], |
| 103 | + name: 'Last Modified', |
| 104 | + exportSelector: 'lastModifiedDateTime', |
| 105 | + cell: cellDateFormatter({ format: 'relative' }), |
| 106 | + }, |
| 107 | + { |
| 108 | + name: 'Actions', |
| 109 | + cell: Actions, |
| 110 | + maxWidth: '80px', |
| 111 | + }, |
| 112 | +] |
| 113 | + |
| 114 | +const ComplianceList = () => { |
| 115 | + const tenant = useSelector((state) => state.app.currentTenant) |
| 116 | + |
| 117 | + // eslint-disable-next-line react/prop-types |
| 118 | + const ExpandedComponent = ({ data }) => ( |
| 119 | + // eslint-disable-next-line react/prop-types |
| 120 | + <CippCodeBlock code={JSON.stringify(data, null, 2)} language="json" /> |
| 121 | + ) |
| 122 | + |
| 123 | + return ( |
| 124 | + <CippPageList |
| 125 | + title="Intune Compliance Policies" |
| 126 | + titleButton={ |
| 127 | + <> |
| 128 | + <TitleButton |
| 129 | + href={`/endpoint/MEM/add-policy?customerId=${tenant?.customerId}&tableFilter=${tenant?.defaultDomainName}`} |
| 130 | + title="Deploy MEM Policy" |
| 131 | + /> |
| 132 | + </> |
| 133 | + } |
| 134 | + tenantSelector={true} |
| 135 | + datatable={{ |
| 136 | + path: '/api/ListGraphRequest', |
| 137 | + params: { |
| 138 | + TenantFilter: tenant?.defaultDomainName, |
| 139 | + Endpoint: 'deviceManagement/deviceCompliancePolicies', |
| 140 | + $orderby: 'displayName', |
| 141 | + $count: true, |
| 142 | + }, |
| 143 | + columns, |
| 144 | + reportName: `${tenant?.defaultDomainName}-MEMPolicies-List`, |
| 145 | + tableProps: { |
| 146 | + expandableRows: true, |
| 147 | + expandableRowsComponent: ExpandedComponent, |
| 148 | + expandOnRowClicked: true, |
| 149 | + }, |
| 150 | + }} |
| 151 | + /> |
| 152 | + ) |
| 153 | +} |
| 154 | + |
| 155 | +export default ComplianceList |
0 commit comments