Skip to content

Commit

Permalink
use seperate summary object
Browse files Browse the repository at this point in the history
  • Loading branch information
notshivansh committed Sep 22, 2023
1 parent a88c665 commit d7ba8cc
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,10 @@ function SingleTestRunPage() {
});
clearInterval(refreshId.current);
setSelectedTestRun((prev) => {
prev['severity'] = func.getSeverity(summary.countIssues)
prev['severityStatus'] = func.getSeverityStatus(summary.countIssues)
prev['metadata'] = func.flattenObject(summary.metadata)
let tmp = {...summary};
tmp.countIssues = transform.prepareCountIssues(tmp.countIssues);
prev['summary'] = {...transform.prepareSummary(tmp)}
prev['testingRunResultSummaryHexId'] = summary?.hexId;
prev['endTimestamp'] = summary?.endTimestamp;
prev['startTimestamp'] = summary?.startTimestamp;

return {...prev};
});
Expand Down Expand Up @@ -245,7 +243,7 @@ function SingleTestRunPage() {
const refreshSummaries = () => {
let intervalId = setInterval(async() => {
let localSelectedTestRun = await fetchData(false);
if(localSelectedTestRun.hexId){
if(localSelectedTestRun.id){
if(localSelectedTestRun.orderPriority !== 1){
setSelectedTestRun(localSelectedTestRun);
setTempLoading((prev) => {
Expand Down Expand Up @@ -289,14 +287,14 @@ const promotedBulkActions = (selectedDataHexIds) => {

function getHeadingStatus(selectedTestRun) {

switch (selectedTestRun.state) {
switch (selectedTestRun?.state) {
case "RUNNING":
return "Test is running";
case "SCHEDULED":
return "Test has been scheduled";
case "STOPPED":
case "COMPLETED":
return `Scanned ${func.prettifyEpoch(selectedTestRun.endTimestamp)} for a duration of
return `Scanned ${func.prettifyEpoch(selectedTestRun.startTimestamp)} for a duration of
${func.getTimeTakenByTest(selectedTestRun.startTimestamp, selectedTestRun.endTimestamp)}`;
default:
return "";
Expand Down Expand Up @@ -366,17 +364,17 @@ const promotedBulkActions = (selectedDataHexIds) => {

const metadataComponent = () => {

if(!selectedTestRun.metadata){
if(!selectedTestRun?.summary?.metadata){
return undefined
}

return (
<LegacyCard title="Metadata" sectioned key="metadata">
{
selectedTestRun.metadata ? Object.keys(selectedTestRun.metadata).map((key) => {
selectedTestRun.summary.metadata ? Object.keys(selectedTestRun.summary.metadata).map((key) => {
return (
<HorizontalStack key={key} spacing="tight">
<Text>{key} : {selectedTestRun.metadata[key]}</Text>
<Text>{key} : {selectedTestRun.summary.metadata[key]}</Text>
</HorizontalStack>
)
}) : ""
Expand All @@ -392,7 +390,6 @@ const promotedBulkActions = (selectedDataHexIds) => {
const rerunTest = (hexId) =>{
api.rerunTest(hexId).then((resp) => {
func.setToast(true, false, "Test re-run")
setStopRefresh(false);
setTimeout(() => {
refreshSummaries();
}, 2000)
Expand All @@ -406,8 +403,8 @@ const promotedBulkActions = (selectedDataHexIds) => {
title={
<VerticalStack gap="3">
<HorizontalStack gap="2" align="start">
{ selectedTestRun?.icon && <Box>
<Icon color={selectedTestRun.iconColor} source={selectedTestRun.icon }></Icon>
{ selectedTestRun?.summary?.icon && <Box>
<Icon color={selectedTestRun.summary.iconColor} source={selectedTestRun.summary.icon }></Icon>
</Box>
}
<Box maxWidth="50vw">
Expand All @@ -417,8 +414,8 @@ const promotedBulkActions = (selectedDataHexIds) => {
textProps={{variant:"headingLg"}}/>
</Box>
{
selectedTestRun?.severity &&
selectedTestRun.severity
selectedTestRun?.summary?.severity &&
selectedTestRun.summary.severity
.map((item) =>
<Badge key={item} status={func.getTestResultStatus(item)}>
<Text fontWeight="regular">
Expand All @@ -432,7 +429,7 @@ const promotedBulkActions = (selectedDataHexIds) => {
</HorizontalStack>
<Text color="subdued" fontWeight="regular" variant="bodyMd">
{
getHeadingStatus(selectedTestRun)
getHeadingStatus(selectedTestRun?.summary)
}
</Text>
</VerticalStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,17 @@ function getRuntime(scheduleTimestamp ,endTimestamp, startTimestamp, state){
if(status==='RUNNING'){
return "Currently running";
}

const currTime = Date.now();
if(endTimestamp <= 0 ){
if(startTimestamp > scheduleTimestamp){
if(startTimestamp >= scheduleTimestamp){
return "Was started " + func.prettifyEpoch(startTimestamp)
} else if(currTime > scheduleTimestamp){
return "Was scheduled for " + func.prettifyEpoch(scheduleTimestamp)
} else {
return "Next run in " + func.prettifyEpoch(scheduleTimestamp)
}
}
return 'Last run ' + func.prettifyEpoch(endTimestamp);
return 'Last run ' + func.prettifyEpoch(startTimestamp);
}

function getAlternateTestsInfo(state){
Expand Down Expand Up @@ -112,48 +114,55 @@ function minimizeTagList(items){
}

const transform = {
prepareSummary : (data) => {
let obj={};
obj['id'] = data?.hexId;
obj['orderPriority'] = getOrderPriority(data?.state)
obj['icon'] = func.getTestingRunIcon(data?.state);
obj['iconColor'] = func.getTestingRunIconColor(data?.state)
obj['startTimestamp'] = data?.startTimestamp
obj['endTimestamp'] = data?.endTimestamp
obj['state'] = getStatus(data?.state)
obj['severity'] = func.getSeverity(data?.countIssues)
obj['severityStatus'] = func.getSeverityStatus(data?.countIssues)
obj['metadata'] = func.flattenObject(data?.metadata)
return obj;
},
prepareCountIssues : (data) => {
let obj={
'High': data['HIGH'] || 0,
'Medium': data['MEDIUM'] || 0,
'Low': data['LOW'] || 0
};
return obj;
},
prepareTestRun : (data, testingRunResultSummary, cicd) => {
let obj={};
if(testingRunResultSummary==null){
testingRunResultSummary = {};
}
if(testingRunResultSummary.countIssues!=null){
testingRunResultSummary.countIssues['High'] = testingRunResultSummary.countIssues['HIGH']
testingRunResultSummary.countIssues['Medium'] = testingRunResultSummary.countIssues['MEDIUM']
testingRunResultSummary.countIssues['Low'] = testingRunResultSummary.countIssues['LOW']
delete testingRunResultSummary.countIssues['HIGH']
delete testingRunResultSummary.countIssues['MEDIUM']
delete testingRunResultSummary.countIssues['LOW']
testingRunResultSummary.countIssues = transform.prepareCountIssues(testingRunResultSummary.countIssues);
}

let state = testingRunResultSummary.state ? testingRunResultSummary.state : data.state;
let startTimestamp = testingRunResultSummary.startTimestamp ? testingRunResultSummary.startTimestamp : data.startTimestamp;
let endTimestamp = testingRunResultSummary.endTimestamp ? testingRunResultSummary.endTimestamp : data.endTimestamp;

obj['hexId']= data.hexId;
obj['id'] = data.hexId;
obj['testingRunResultSummaryHexId'] = testingRunResultSummary?.hexId;
obj['orderPriority'] = getOrderPriority(state)
obj['icon'] = func.getTestingRunIcon(state);
obj['iconColor'] = func.getTestingRunIconColor(state)
obj['orderPriority'] = getOrderPriority(data.state)
obj['icon'] = func.getTestingRunIcon(data.state);
obj['iconColor'] = func.getTestingRunIconColor(data.state)
obj['name'] = data.name || "Test"
obj['number_of_tests_str'] = getTestsInfo(testingRunResultSummary?.testResultsCount, state)
obj['number_of_tests_str'] = getTestsInfo(testingRunResultSummary?.testResultsCount, data.state)
obj['run_type'] = getTestingRunType(data, testingRunResultSummary, cicd);
obj['run_time_epoch'] = Math.max(data.scheduleTimestamp,endTimestamp)
obj['run_time_epoch'] = Math.max(data.scheduleTimestamp,data.endTimestamp)
obj['scheduleTimestamp'] = data.scheduleTimestamp
obj['pickedUpTimestamp'] = data.pickedUpTimestamp
obj['startTimestamp'] = startTimestamp
obj['endTimestamp'] = endTimestamp
obj['state'] = getStatus(state)
obj['run_time'] = getRuntime(data.scheduleTimestamp ,endTimestamp, startTimestamp, state)
obj['run_time'] = getRuntime(data.scheduleTimestamp ,data.endTimestamp, data.startTimestamp, data.state)
obj['severity'] = func.getSeverity(testingRunResultSummary.countIssues)
obj['total_severity'] = getTotalSeverity(testingRunResultSummary.countIssues);
obj['severityStatus'] = func.getSeverityStatus(testingRunResultSummary.countIssues)
obj['runTypeStatus'] = [obj['run_type']]
obj['nextUrl'] = "/dashboard/testing/"+data.hexId
obj['metadata'] = func.flattenObject(testingRunResultSummary.metadata)
obj['repository'] = [obj?.metadata?.repository]
obj['branch'] = [obj?.metadata?.branch]
obj['summary'] = transform.prepareSummary(testingRunResultSummary)
return obj;
},
prepareTestRuns : (testingRuns, latestTestingRunResultSummaries, cicd) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/web/polaris_web/web/src/util/func.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ const func = {
return result;
},
getSeverityStatus(countIssues) {
if(countIssues==null){
if(countIssues==null || countIssues==undefined){
return [];
}
return Object.keys(countIssues).filter((key) => {
Expand Down

0 comments on commit d7ba8cc

Please sign in to comment.