Skip to content

Commit

Permalink
Extract color determining logic to function
Browse files Browse the repository at this point in the history
The color determination logic based on diagnostic values has been extracted into a separate function called `getColour`. This function is then utilized in two different places, which enhances code readability and maintainability.
  • Loading branch information
Dialpuri committed Mar 13, 2024
1 parent cca8ae5 commit 19de3b7
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions webapp/src/data/Constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,17 @@ export const DatabaseColumns = [
},
];


function getColour(diagnostic) {
return diagnostic !== "yes" ? "text-red-400" : (diagnostic === "check" ? "text-yellow-600" : "")
}


function extracted(props, accessor) {
const typeValue = props.row.original[accessor];
const diagnostic = props.row.original.diagnostic;

const colour = diagnostic === "yes" ? "text-red-600" : (diagnostic === "check" ? "text-yellow-600": "")
const colour = getColour(diagnostic)
return (
<span
className={colour}>
Expand All @@ -166,7 +172,7 @@ export const SugarListColumns = [
}) => {
const typeValue = props.row.original.conformation;
const diagnostic = props.row.original.diagnostic;
const colour = diagnostic === "yes" ? "text-red-400" : (diagnostic === "check" ? "text-yellow-600": "")
const colour = getColour(diagnostic)

const regex = /([a-zA-Z]*?\d*)([a-zA-Z])(\d*)/;
const formattedString = typeValue.replace(
Expand Down

0 comments on commit 19de3b7

Please sign in to comment.