Skip to content

Commit

Permalink
Merge branch 'KelvinTegelaar:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
psreekumarinfx authored Jan 21, 2024
2 parents d53d784 + be0ef04 commit 216862e
Show file tree
Hide file tree
Showing 23 changed files with 4,624 additions and 2,528 deletions.
6,379 changes: 3,952 additions & 2,427 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/version_latest.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.9.1
5.0.1
5 changes: 5 additions & 0 deletions src/_nav.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,11 @@ const _nav = [
name: 'Deploy CA Policies',
to: '/tenant/conditional/deploy',
},
{
component: CNavItem,
name: 'CA Vacation Mode',
to: '/tenant/conditional/deploy-vacation',
},
{
component: CNavItem,
name: 'CA Templates',
Expand Down
8 changes: 8 additions & 0 deletions src/components/forms/RFFComponents.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,17 @@ export const RFFCFormInput = ({
disabled = false,
spellCheck = true,
autoFocus = false,
onChange,
}) => {
return (
<Field name={name} validate={validate}>
{({ input, meta }) => {
const handleChange = onChange
? (e) => {
input.onChange(e)
onChange(e)
}
: input.onChange
return (
<div className={className}>
{label && <CFormLabel htmlFor={name}>{label}</CFormLabel>}
Expand All @@ -155,6 +162,7 @@ export const RFFCFormInput = ({
placeholder={placeholder}
spellCheck={spellCheck}
autoFocus={autoFocus}
onChange={handleChange}
/>
<RFFCFormFeedback meta={meta} />
</div>
Expand Down
11 changes: 1 addition & 10 deletions src/components/layout/AppHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,8 @@ import {
} from '@coreui/react'
import { AppHeaderSearch } from 'src/components/header'
import { TenantSelector } from '../utilities'
import cyberdrainlogolight from 'src/assets/images/CIPP.png'
import cyberdrainlogodark from 'src/assets/images/CIPP_Dark.png'

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import {
faBars,
faCaretSquareLeft,
faCaretSquareRight,
faHamburger,
faStroopwafel,
} from '@fortawesome/free-solid-svg-icons'
import { faBars } from '@fortawesome/free-solid-svg-icons'
import { setCurrentTheme, setUserSettings, toggleSidebarShow } from 'src/store/features/app'
import { useMediaPredicate } from 'react-media-hook'
import { useGenericGetRequestQuery, useLoadAlertsDashQuery } from 'src/store/api/app'
Expand Down
13 changes: 7 additions & 6 deletions src/components/layout/AppSidebar.jsx

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions src/components/tables/CellMathFormatter.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react'
import { CBadge, CTooltip } from '@coreui/react'
import CellBoolean from 'src/components/tables/CellBoolean.jsx'
import cellTable from './CellTable'

export function CellTip(cell, overflow = false) {
return (
<CTooltip content={String(cell)}>
<div className="celltip-content-nowrap">{String(cell)}</div>
</CTooltip>
)
}
export const cellMathFormatter =
({ col } = {}) =>
(row) => {
const evaluateCalculation = (calculation, row) => {
try {
const formattedCalculation = calculation.replace(/\b\w+(\.\w+|\[\d+\])*\b/g, (key) => {
if (!isNaN(key)) {
return parseFloat(key)
}

const path = key.split(/\.|\[(\d+)\]/).filter(Boolean) // Splits keys and array indices
let currentObject = row
for (const prop of path) {
if (currentObject && prop in currentObject) {
currentObject = currentObject[prop]
} else if (!isNaN(prop)) {
// Checks if the prop is an array index
currentObject = currentObject[parseInt(prop, 10)]
} else {
throw new Error(`Property '${prop}' not found in row`)
}
}

return parseFloat(currentObject)
})

return Number(eval(formattedCalculation))
} catch (e) {
console.error(e)
return null
}
}

const result = evaluateCalculation(col.value, row)

if (result === null) {
return 'N/A'
}

if (col.showAs === 'percentage') {
return `${result.toFixed(2)}%`
} else {
return result.toFixed(2)
}
}

export default cellMathFormatter
36 changes: 29 additions & 7 deletions src/components/utilities/CippActionsOffcanvas.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,34 @@ export default function CippActionsOffcanvas(props) {
}
const handleModal = useCallback(
(modalMessage, modalUrl, modalType = 'GET', modalBody, modalInput, modalDropdown) => {
const handlePostConfirm = () => {
const selectedValue = inputRef.current.value
console.log(inputRef)
let additionalFields = {}

if (inputRef.current.nodeName === 'SELECT') {
const selectedItem = dropDownInfo.data.find(
(item) => item[modalDropdown.valueField] === selectedValue,
)
if (selectedItem && modalDropdown.addedField) {
Object.keys(modalDropdown.addedField).forEach((key) => {
additionalFields[key] = selectedItem[modalDropdown.addedField[key]]
})
}
}
const postRequestBody = {
...modalBody,
...additionalFields,
input: selectedValue,
}
// Send the POST request
genericPostRequest({
path: modalUrl,
values: postRequestBody,
})
}

// Modal setup for GET, codeblock, and other types
if (modalType === 'GET') {
ModalService.confirm({
body: (
Expand Down Expand Up @@ -82,12 +110,7 @@ export default function CippActionsOffcanvas(props) {
</div>
),
title: 'Confirm',
onConfirm: () => [
genericPostRequest({
path: modalUrl,
values: { ...modalBody, ...{ input: inputRef.current.value } },
}),
],
onConfirm: handlePostConfirm,
})
}
},
Expand All @@ -99,7 +122,6 @@ export default function CippActionsOffcanvas(props) {
modalContent,
],
)

useEffect(() => {
if (dropDownInfo.isFetching) {
handleModal(
Expand Down
4 changes: 4 additions & 0 deletions src/data/BPAField.schema.v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@
{
"const": "number",
"title": "Displays as a numerical value"
},
{
"const": "math",
"title": "Displays as a calculated value"
}
]
}
Expand Down
Loading

0 comments on commit 216862e

Please sign in to comment.