Skip to content

Commit

Permalink
Merge pull request #1634 from akto-api-security/temp/temp_fixed_dashb…
Browse files Browse the repository at this point in the history
…oard

Fixing numbers in dashboard
  • Loading branch information
notshivansh authored Oct 16, 2024
2 parents f0331b4 + bbb5971 commit ac0c091
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function CollectionComponent(props) {
const { condition, index, dispatch, operatorComponent } = props
const [apiEndpoints, setApiEndpoints] = useState({})
const initialRegexText = (condition && condition?.type === 'REGEX') ? (condition?.data?.regex || '') : ''
const initialHostRegexText = (condition && condition?.type === 'HOST_REGEX') ? (condition?.data?.host_regex || '') : ''
const initialHostRegexText = (condition && condition?.type === 'HOST_REGEX') ? (condition?.data?.regex || '') : ''
const [regexText, setRegexText] = useState(initialRegexText)
const [hostRegexText, setHostRegexText] = useState(initialHostRegexText)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ function TitleWithInfo({titleComp, textProps, titleText, tooltipContent, docsUrl
{content}
</div>
</div>
</Popover> : <Tooltip content={tooltipContent} dismissOnMouseOut><div className='reduce-size'>
</Popover> : tooltipContent ? <Tooltip content={tooltipContent} dismissOnMouseOut><div className='reduce-size'>
<Avatar shape="round" size="extraSmall" source='/public/info_filled_icon.svg'/>
</div> </Tooltip>
</div> </Tooltip> : null
}
</HorizontalStack>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import CriticalFindingsGraph from '../issues/IssuesPage/CriticalFindingsGraph';
function HomeDashboard() {

const [loading, setLoading] = useState(true);
const [skip, setSkip] = useState(0)
const [showBannerComponent, setShowBannerComponent] = useState(false)
const [testSummaryInfo, setTestSummaryInfo] = useState([])

Expand All @@ -52,6 +51,7 @@ function HomeDashboard() {
const initialStartTimestamp = func.timeNow() - 60 * 60 * 24
const initialEndTimestamp = func.timeNow()
const [showTestingComponents, setShowTestingComponents] = useState(false)
const [customRiskScoreAvg, setCustomRiskScoreAvg] = useState(0)

const tempVal = { alias: "custom", title: "Custom", period: { since: new Date(initialStartTimestamp * 1000), until: new Date(initialEndTimestamp * 1000) } }

Expand Down Expand Up @@ -332,6 +332,21 @@ function HomeDashboard() {
function buildSetRiskScoreData(apiStats) {
const totalApisCount = apiStats.totalAPIs

let tempScore = 0, tempTotal = 0
Object.keys(apiStats.riskScoreMap).forEach((x) => {
if(x > 1){
const apisVal = apiStats.riskScoreMap[x]
tempScore += (x * apisVal)
tempTotal += apisVal
}
})
if(tempScore > 0 && tempTotal > 0){
let val = (tempScore * 1.0)/tempTotal
if(val >= 2){
setCustomRiskScoreAvg(val)
}
}

const sumOfRiskScores = Object.values(apiStats.riskScoreMap).reduce((acc, value) => acc + value, 0);

// Calculate the additional APIs that should be added to risk score "0"
Expand Down Expand Up @@ -395,15 +410,17 @@ function HomeDashboard() {
variant: 'heading2xl',
color: 'critical',
byLineComponent: observeFunc.generateByLineComponent((totalIssuesCount - oldIssueCount), func.timeDifference(startTimestamp, endTimestamp)),
smoothChartComponent: (<SmoothAreaChart tickPositions={[oldIssueCount, totalIssuesCount]} />)
smoothChartComponent: (<SmoothAreaChart tickPositions={[oldIssueCount, totalIssuesCount]} />),
},
{
title: 'API Risk Score',
data: apiRiskScore,
data: customRiskScoreAvg !== 0 ? customRiskScoreAvg : apiRiskScore,
variant: 'heading2xl',
color: apiRiskScore > 2.5 ? 'critical' : 'warning',
color: (customRiskScoreAvg > 2.5 || apiRiskScore > 2.5) ? 'critical' : 'warning',
byLineComponent: observeFunc.generateByLineComponent((apiRiskScore - oldRiskScore).toFixed(2), func.timeDifference(startTimestamp, endTimestamp)),
smoothChartComponent: (<SmoothAreaChart tickPositions={[oldRiskScore, apiRiskScore]} />)
smoothChartComponent: (<SmoothAreaChart tickPositions={[oldRiskScore, apiRiskScore]} />),
tooltipContent: 'This represents a cumulative risk score for the whole dashboard',
docsUrl: 'https://docs.akto.io/api-discovery/concepts/risk-score'
},
{
title: 'Test Coverage',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Box, Card, HorizontalGrid, HorizontalStack, Text, VerticalStack } from '@shopify/polaris'
import React from 'react'
import TitleWithInfo from '../../../components/shared/TitleWithInfo'

function SummaryCard({ summaryItems }) {
return (
Expand All @@ -10,9 +11,15 @@ function SummaryCard({ summaryItems }) {
<Box borderInlineEndWidth={index < (summaryItems.length - 1) ? "1" : ""} key={index} borderColor="transparent">
<HorizontalStack>
<VerticalStack gap="4">
<Text variant="headingMd">
{item.title}
</Text>
<TitleWithInfo
titleComp={
<Text variant="headingMd">
{item.title}
</Text>
}
docsUrl={item?.docsUrl}
tooltipContent={item?.tooltipContent}
/>
<HorizontalGrid gap={1} columns={2}>
<VerticalStack gap={4}>
{item?.isComp ? item.data :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ const CriticalFindingsGraph = ({ linkText, linkUrl }) => {
const [showTestingComponents, setShowTestingComponents] = useState(false)

function convertSubCategoryInfo(tempSubCategoryMap) {
const entries = Object.values(tempSubCategoryMap);
const entries = Object.keys(tempSubCategoryMap).map((x) => {
let tempObj = tempSubCategoryMap[x];
tempObj.key = x
return tempObj
})
entries.sort((a, b) => b.text - a.text);
const topEntries = entries.slice(0, 5);
const data = topEntries.map(entry => {return {text: entry.filterKey, value: entry.text, color: entry.color}});
const data = topEntries.map(entry => {return {text: entry.key, value: entry.text, color: entry.color}});
setCriticalFindingsData(data)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ function APIQuery() {
const getApiCollection = () => {
collectionsApi.getCollection(collectionId).then((res) => {
(res[0].conditions || []).forEach((x, index) => {
const tempEmptyCondition = getEmptyCondition(x.type)
let tempKey = x.type
if(x.actualType && x?.actualType !== undefined){
tempKey = x.actualType
}
const tempEmptyCondition = getEmptyCondition(tempKey)
dispatchConditions({ type: "add", obj: tempEmptyCondition })
dispatchConditions({ type: "updateKey", index: index, key: "operator", obj: x.operator })
if(x.type === 'CUSTOM'){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.akto.dto.ApiInfo;
import com.akto.dto.type.SingleTypeInfo;
import com.mongodb.client.model.Filters;

import org.apache.commons.lang3.NotImplementedException;
import org.apache.commons.lang3.StringUtils;
import org.bson.codecs.pojo.annotations.BsonIgnore;
Expand Down Expand Up @@ -35,6 +36,18 @@ public HostRegexTestingEndpoints() {
super(Type.REGEX, Operator.OR);
}


@BsonIgnore
Type actualType;

public Type getActualType() {
return Type.HOST_REGEX;
}

public void setActualType(Type actualType) {
this.actualType = Type.HOST_REGEX;
}

@Override
public List<ApiInfo.ApiInfoKey> returnApis() {
throw new NotImplementedException();
Expand Down

0 comments on commit ac0c091

Please sign in to comment.