Skip to content

Commit

Permalink
fix(frontend): percentage identation
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrofars committed Nov 7, 2023
1 parent 414d1a3 commit b4a4dc2
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions frontend/src/pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const Page = () => {
const [vendorValues, setVendorValues] = useState([0])

const fetchGeneralInfo = async () => {

var myHeaders = new Headers();
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Authorization", localStorage.getItem("token"));
Expand All @@ -48,11 +49,18 @@ const Page = () => {

let onlinePercentage = ((content.StatusCount.Online * 100)/totalDevices)
console.log("ONLINE AND OFFLINE:",onlinePercentage,100 - onlinePercentage)
setDevicesStatus([onlinePercentage, 100 - onlinePercentage])

if(Number.isInteger(onlinePercentage)){
setDevicesStatus([onlinePercentage, 100 - onlinePercentage])
}else{
onlinePercentage = Number(onlinePercentage.toFixed(1))
setDevicesStatus([onlinePercentage, 100 - onlinePercentage])
}

let prodClassLabels = []
let prodClassValues = []
let prodClassValue = 0

content.ProductClassCount?.map((p)=>{
if (p.productClass === ""){
prodClassLabels.push("unknown")
Expand All @@ -63,7 +71,12 @@ const Page = () => {
})

content.ProductClassCount?.map((p)=>{
prodClassValues.push(p.count * 100 / prodClassValue)
let percentageValue = p.count * 100 / prodClassValue
if (Number.isInteger(percentageValue)){
prodClassValues.push(percentageValue)
}else{
prodClassValues.push(Number(percentageValue.toFixed(1)))
}
})

setProductClassLabels(prodClassLabels)
Expand All @@ -84,13 +97,19 @@ const Page = () => {
})

content.VendorsCount?.map((p)=>{
vValues.push(p.count * 100 / vValue)
let percentageValue = p.count * 100 / vValue
if (Number.isInteger(percentageValue)){
vValues.push(percentageValue)
}else{
vValues.push(Number(percentageValue.toFixed(1)))
}
})

setVendorLabels(vLabels)
setVendorValues(vValues)

console.log("vendorLabels:", vLabels)
console.log("vendorValues:", vendorValues)
console.log("vendorValues:", vValues)

setGeneralInfo(content)
}
Expand Down

0 comments on commit b4a4dc2

Please sign in to comment.