Skip to content

Commit

Permalink
fixing triage refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobcx committed Nov 2, 2023
1 parent 756fa27 commit c1351c2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/utils/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ export const constants = {
gptEngineKey: "model",
// Documentation & Feedback
feedback: "Send us enhancement request or report a bug",
documentation: "Documentation"
documentation: "Documentation",

// TRIAGE
triageUpdate: "ast-result-triage"
};

export enum GroupBy {
Expand Down
9 changes: 6 additions & 3 deletions src/utils/triage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as fs from "fs";
import { AstResult } from "../models/results";
import { getResultsFilePath } from "./utils";
import { cx } from "../cx";
import { getFromState } from "./common/globalState";
import { getFromState, updateState } from "./common/globalState";
import { constants } from "./common/constants";
import { Logs } from "../models/logs";
import { AstDetailsDetached } from "../views/resultsView/astDetailsView";
Expand All @@ -29,7 +29,9 @@ export async function updateResults(
resultsProvider.loadedResults.forEach((element: AstResult, index: number) => {
// Update the result in the array
if (element.data.resultHash === resultHash || element.id === resultHash) {
resultsProvider.loadedResults[index] = result;
resultsProvider.loadedResults[index].severity = result.severity;
resultsProvider.loadedResults[index].state = result.state;
resultsProvider.loadedResults[index].status = result.status;
return;
}
});
Expand Down Expand Up @@ -100,7 +102,8 @@ export async function triageSubmit(
// Change the results locally
try {
await updateResults(result, context, data.comment, resultsProvider);
vscode.commands.executeCommand(commands.refreshTree);
updateState(context, constants.triageUpdate, { id: true, name: constants.triageUpdate });
await vscode.commands.executeCommand(commands.refreshTree);
if (result.type === "sast" || result.type === "kics") {
await getChanges(logs, context, result, detailsPanel);
}
Expand Down
21 changes: 15 additions & 6 deletions src/views/resultsView/astResultsProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,25 @@ export class AstResultsProvider extends ResultsProvider {
this.diagnosticCollection.clear();
// createBaseItems
let treeItems = this.createRootItems();
// get para getFromState
// get scanID from state
this.scan = getFromState(this.context, constants.scanIdKey)?.id;
// in case we scanId, it is needed to load them from the json file
if (this.scan) {
this.loadedResults = readResultsFromFile(resultJsonPath, this.scan);
const fromTriage = getFromState(this.context, constants.triageUpdate)?.id;
// Case we come from triage we want to use the loaded results wich were modified in triage
if (fromTriage === undefined || !fromTriage) {
// in case we scanId, it is needed to load them from the json file
if (this.scan) {
this.loadedResults = readResultsFromFile(resultJsonPath, this.scan);
}
// otherwise the results must be cleared
else {
this.loadedResults = undefined;
}
}
// otherwise the results must be cleared
// Case we come from triage we must update the state to load results from the correct place
else {
this.loadedResults = undefined;
updateState(this.context, "ast-result-triage", { id: false, name: "ast-result-triage" });
}

// if there are results loaded, the tree needs to be recreated
if (this.loadedResults !== undefined) {
treeItems = treeItems.concat(this.createSummaryItem(this.loadedResults));
Expand Down

0 comments on commit c1351c2

Please sign in to comment.