Skip to content

Commit

Permalink
Merge pull request #26 from KelvinTegelaar/dev
Browse files Browse the repository at this point in the history
[pull] dev from KelvinTegelaar:dev
  • Loading branch information
kris6673 authored Apr 25, 2024
2 parents 732bbf1 + c7794c1 commit 83733b9
Show file tree
Hide file tree
Showing 12 changed files with 489 additions and 166 deletions.
1 change: 1 addition & 0 deletions src/components/contentcards/DatatableContentCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function DatatableContentCard({
path={path}
columns={columns}
params={params}
sortable
{...rest}
/>
)}
Expand Down
1 change: 1 addition & 0 deletions src/components/layout/AppHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const AppHeader = () => {
timestamp: job.Timestamp,
percent: job.PercentComplete,
progressText: `${job.PercentComplete}%`,
detailsObject: job.Tasks,
})),
)
} else {
Expand Down
96 changes: 67 additions & 29 deletions src/components/utilities/CippActionsOffcanvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import {
CRow,
CSpinner,
} from '@coreui/react'
import { CippCodeBlock, CippOffcanvas, ModalService } from 'src/components/utilities'
import {
CippCodeBlock,
CippOffcanvas,
CippTableOffcanvas,
ModalService,
} from 'src/components/utilities'
import { CippOffcanvasPropTypes } from 'src/components/utilities/CippOffcanvas'
import { CippOffcanvasTable } from 'src/components/tables'
import { useLazyGenericGetRequestQuery, useLazyGenericPostRequestQuery } from 'src/store/api/app'
Expand All @@ -31,6 +36,65 @@ import ReactTimeAgo from 'react-time-ago'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faGlobe } from '@fortawesome/free-solid-svg-icons'

const CippOffcanvasCard = ({ action, key }) => {
const [offcanvasVisible, setOffcanvasVisible] = useState(false)
return (
<>
<CCard key={key} className="border-top-dark border-top-3 mb-3">
<CCardHeader className="d-flex justify-content-between align-items-center">
<CCardTitle>Report Name: {action.label}</CCardTitle>
</CCardHeader>
<CCardBody>
<CCardText>
{action.value && (
<>
{action?.link ? (
<Link to={action.link}>Status: {action.value}</Link>
) : (
<span>Status: {action.value}</span>
)}
</>
)}
</CCardText>
{Array.isArray(action?.detailsObject) && (
<CButton size="sm" onClick={() => setOffcanvasVisible(true)}>
Details
</CButton>
)}
{Array.isArray(action?.detailsObject) && (
<CippTableOffcanvas
data={action.detailsObject}
title={`${action.label} - Details`}
state={offcanvasVisible}
hideFunction={() => setOffcanvasVisible(false)}
/>
)}
</CCardBody>
<CCardFooter className="text-end">
<CRow>
{action?.percent > 0 && (
<CCol xs="8">
<div className="mt-1">
<CProgress>
<CProgressBar value={action.percent}>{action?.progressText}</CProgressBar>
</CProgress>
</div>
</CCol>
)}
<CCol xs={action?.percent ? '4' : '12'}>
<small>{action.timestamp && <ReactTimeAgo date={action.timestamp} />}</small>
</CCol>
</CRow>
</CCardFooter>
</CCard>
</>
)
}
CippOffcanvasCard.propTypes = {
action: PropTypes.object,
key: PropTypes.object,
}

export default function CippActionsOffcanvas(props) {
const inputRef = useRef('')
const [genericGetRequest, getResults] = useLazyGenericGetRequestQuery()
Expand Down Expand Up @@ -219,34 +283,7 @@ export default function CippActionsOffcanvas(props) {
let cardContent
try {
cardContent = props.cards.map((action, index) => (
<>
<CCard key={index} className="border-top-dark border-top-3 mb-3">
<CCardHeader className="d-flex justify-content-between align-items-center">
<CCardTitle>Report Name: {action.label}</CCardTitle>
</CCardHeader>
<CCardBody>
<CCardText>
{action.value && <Link to={action.link}>Status: {action.value}</Link>}
</CCardText>
</CCardBody>
<CCardFooter className="text-end">
<CRow>
{action?.percent > 0 && (
<CCol xs="8">
<div className="mt-1">
<CProgress>
<CProgressBar value={action.percent}>{action?.progressText}</CProgressBar>
</CProgress>
</div>
</CCol>
)}
<CCol xs={action?.percent ? '4' : '12'}>
<small>{action.timestamp && <ReactTimeAgo date={action.timestamp} />}</small>
</CCol>
</CRow>
</CCardFooter>
</CCard>
</>
<CippOffcanvasCard action={action} key={index} />
))
} catch (error) {
// swallow error
Expand Down Expand Up @@ -343,6 +380,7 @@ export default function CippActionsOffcanvas(props) {
<CippCodeBlock
code={getResults.data?.Results}
callout={true}
calloutDismissible={true}
calloutColour={getResults.data?.colour ? getResults.data?.colour : 'info'}
calloutCopyValue={getResults.data?.Results}
/>
Expand Down
37 changes: 22 additions & 15 deletions src/components/utilities/CippCodeBlock.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React, { useState } from 'react'
import PropTypes from 'prop-types'
import { CopyToClipboard } from 'react-copy-to-clipboard'
import { CButton, CCallout } from '@coreui/react'
import { CButton } from '@coreui/react'
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import { faCopy, faClipboard } from '@fortawesome/free-regular-svg-icons'
import SyntaxHighlighter from 'react-syntax-highlighter'
import { atomOneDark } from 'react-syntax-highlighter/dist/esm/styles/hljs'
import { CippCallout } from '../layout'

function CippCodeBlock({
code,
Expand All @@ -16,7 +17,7 @@ function CippCodeBlock({
callout = false,
calloutColour = 'info',
calloutCopyValue = false,
dismissable = false,
calloutDismissible = false,
}) {
const [codeCopied, setCodeCopied] = useState(false)

Expand All @@ -27,20 +28,26 @@ function CippCodeBlock({

return (
<div className="cipp-code">
<CopyToClipboard text={calloutCopyValue || code} onCopy={() => onCodeCopied()}>
<CButton
color={codeCopied ? 'success' : 'info'}
className="cipp-code-copy-button"
size="sm"
variant="ghost"
>
{codeCopied ? <FontAwesomeIcon icon={faClipboard} /> : <FontAwesomeIcon icon={faCopy} />}
</CButton>
</CopyToClipboard>
{!calloutDismissible && (
<CopyToClipboard text={calloutCopyValue || code} onCopy={() => onCodeCopied()}>
<CButton
color={codeCopied ? 'success' : 'info'}
className="cipp-code-copy-button"
size="sm"
variant="ghost"
>
{codeCopied ? (
<FontAwesomeIcon icon={faClipboard} />
) : (
<FontAwesomeIcon icon={faCopy} />
)}
</CButton>
</CopyToClipboard>
)}
{callout && (
<CCallout color={calloutColour} dismissable={dismissable}>
<CippCallout color={calloutColour} dismissible={calloutDismissible}>
{code}
</CCallout>
</CippCallout>
)}
{!callout && (
<SyntaxHighlighter
Expand Down Expand Up @@ -70,5 +77,5 @@ CippCodeBlock.propTypes = {
callout: PropTypes.bool,
calloutColour: PropTypes.string,
calloutCopyValue: PropTypes.string,
dismissable: PropTypes.bool,
calloutDismissible: PropTypes.bool,
}
42 changes: 40 additions & 2 deletions src/components/utilities/CippTableOffcanvas.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react'
import { CippOffcanvas } from 'src/components/utilities'
import PropTypes from 'prop-types'
import { CippDatatable } from '../tables'
import { CippDatatable, CippTable } from '../tables'
import { cellGenericFormatter } from '../tables/CellGenericFormat'

function CippTableOffcanvas({
state: visible,
Expand All @@ -11,7 +12,37 @@ function CippTableOffcanvas({
params,
columns,
tableProps,
data = null,
}) {
if (data !== null && data !== undefined) {
if (!Array.isArray(data) && typeof data === 'object') {
data = Object.keys(data).map((key) => {
return {
Key: key,
Value: data[key],
}
})
} else {
if (Array.isArray(data) && typeof data[0] !== 'object') {
data = data.map((row) => {
return {
Value: row,
}
})
}
}
columns = []
Object.keys(data[0]).map((key) => {
columns.push({
name: key,
selector: (row) => row[key],
sortable: true,
exportSelector: key,
cell: cellGenericFormatter(),
})
})
}

return (
<>
<CippOffcanvas
Expand All @@ -21,7 +52,13 @@ function CippTableOffcanvas({
visible={visible}
hideFunction={hideFunction}
>
<CippDatatable path={path} params={params} columns={columns} tableProps={tableProps} />
<>
{data !== null && data !== undefined ? (
<CippTable data={data} columns={columns} />
) : (
<CippDatatable path={path} params={params} columns={columns} tableProps={tableProps} />
)}
</>
</CippOffcanvas>
</>
)
Expand All @@ -35,6 +72,7 @@ CippTableOffcanvas.propTypes = {
params: PropTypes.object,
columns: PropTypes.object,
tableProps: PropTypes.object,
data: PropTypes.object,
}

export default CippTableOffcanvas
33 changes: 25 additions & 8 deletions src/components/utilities/ModalRoot.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useEffect, useState } from 'react'
import { SharedModal } from 'src/components/utilities'

export const ModalService = {
on(event, callback) {
document.addEventListener(event, (e) => callback(e.detail))
Expand All @@ -21,7 +20,7 @@ export const ModalService = {
detail: {
componentType,
componentProps,
body,
body: typeof body === 'function' ? body() : body,
data,
title,
size,
Expand All @@ -33,9 +32,9 @@ export const ModalService = {
)
},
confirm({ body, title, size, onConfirm, confirmLabel, cancelLabel }) {
ModalService.open({
this.open({
componentType: 'confirm',
body,
body: typeof body === 'function' ? body : body,
title,
size,
onConfirm,
Expand All @@ -47,19 +46,37 @@ export const ModalService = {

export function ModalRoot() {
const [modal, setModal] = useState({})
const [version, setVersion] = useState(0) // used to force re-render

useEffect(() => {
ModalService.on('open', (props) => {
const handleOpen = (props) => {
setModal({
...props,
close: () => {
setModal({})
},
})
})
setVersion((v) => v + 1) // Increment version to force update
}

ModalService.on('open', handleOpen)
return () => {
document.removeEventListener('open', handleOpen)
}
}, [])

const ModalComponent = modal.body || modal.data ? SharedModal : null
const ModalComponent = modal.componentType ? SharedModal : null

return <>{ModalComponent && <ModalComponent {...modal} visible close={modal.close} />}</>
return (
<>
{ModalComponent && (
<ModalComponent
key={version} // Use key to force re-render on changes
{...modal}
visible
close={modal.close}
/>
)}
</>
)
}
16 changes: 16 additions & 0 deletions src/data/standards.json
Original file line number Diff line number Diff line change
Expand Up @@ -1188,5 +1188,21 @@
"label": "Only allow users to sync OneDrive from AAD joined devices",
"impact": "High Impact",
"impactColour": "danger"
},
{
"name": "standards.TenantDefaultTimezone",
"cat": "SharePoint Standards",
"tag": ["lowimpact"],
"helpText": "Sets the default timezone for the tenant. This will be used for all new users and sites.",
"addedComponent": [
{
"type": "input",
"name": "standards.TenantDefaultTimezone.Timezone",
"label": "Timezone"
}
],
"label": "Set Default Timezone for Tenant",
"impact": "Low Impact",
"impactColour": "info"
}
]
Loading

0 comments on commit 83733b9

Please sign in to comment.