forked from KelvinTegelaar/CIPP
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'KelvinTegelaar:main' into main
- Loading branch information
Showing
53 changed files
with
45,964 additions
and
29,110 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
4.9.1 | ||
5.2.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.