Skip to content

Commit

Permalink
feature: functionality + UI to limit max path steps in MRVA results
Browse files Browse the repository at this point in the history
  • Loading branch information
p- committed Jul 5, 2024
1 parent 75ab23b commit 7f6f9c9
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 5 deletions.
44 changes: 44 additions & 0 deletions extensions/ql-vscode/src/view/common/MaxThreadFlowStepsBox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { useCallback } from "react";
import { styled } from "styled-components";
import { VSCodeTextField } from "@vscode/webview-ui-toolkit/react";
import { Codicon } from "./icon";

const TextField = styled(VSCodeTextField)`
width: 100%;
`;

type Props = {
value: string;
placeholder: string;
onChange: (value: string) => void;

className?: string;
};

export const MaxThreadFlowStepsBox = ({
value,
placeholder,
onChange,
className,
}: Props) => {
const handleInput = useCallback(
(e: InputEvent) => {
const target = e.target as HTMLInputElement;

onChange(target.value);
},
[onChange],
);

return (
<TextField
placeholder={placeholder}
value={value}
type="number"
onInput={handleInput}
className={className}
>
<Codicon name="list-selection" label="Limit" slot="start" />
</TextField>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ export type AnalyzedRepoItemContentProps = {
rawResults?: AnalysisRawResults;

resultFormat: ResultFormat;

maxThreadFlowSteps: number;
};

export const AnalyzedRepoItemContent = ({
Expand All @@ -67,6 +69,7 @@ export const AnalyzedRepoItemContent = ({
interpretedResults,
rawResults,
resultFormat,
maxThreadFlowSteps,
}: AnalyzedRepoItemContentProps) => {
const chosenResultFormat = chooseResultFormat(
interpretedResults,
Expand Down Expand Up @@ -114,11 +117,17 @@ export const AnalyzedRepoItemContent = ({
)}
{interpretedResults && chosenResultFormat === ResultFormat.Alerts && (
<InterpretedResultsContainer>
{interpretedResults.map((r, i) => (
<InterpretedResultItem key={i}>
<AnalysisAlertResult alert={r} />
</InterpretedResultItem>
))}
{interpretedResults
.filter((r) =>
r.codeFlows.some(
(cf) => cf.threadFlows.length <= maxThreadFlowSteps,
),
)
.map((r, i) => (
<InterpretedResultItem key={i}>
<AnalysisAlertResult alert={r} />
</InterpretedResultItem>
))}
</InterpretedResultsContainer>
)}
{rawResults && chosenResultFormat === ResultFormat.RawResults && (
Expand Down
4 changes: 4 additions & 0 deletions extensions/ql-vscode/src/view/variant-analysis/RepoRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export type RepoRowProps = {

resultFormat?: ResultFormat;

maxThreadFlowSteps?: number;

selected?: boolean;
onSelectedChange?: (repositoryId: number, selected: boolean) => void;
};
Expand Down Expand Up @@ -172,6 +174,7 @@ export const RepoRow = ({
interpretedResults,
rawResults,
resultFormat = ResultFormat.Alerts,
maxThreadFlowSteps = 1000, // don't know if value is needed here
selected,
onSelectedChange,
}: RepoRowProps) => {
Expand Down Expand Up @@ -309,6 +312,7 @@ export const RepoRow = ({
interpretedResults={interpretedResults}
rawResults={rawResults}
resultFormat={resultFormat}
maxThreadFlowSteps={maxThreadFlowSteps}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import type {
SortKey,
} from "../../variant-analysis/shared/variant-analysis-filter-sort";
import { SearchBox } from "../common/SearchBox";
import { MaxThreadFlowStepsBox } from "../common/MaxThreadFlowStepsBox";
import { RepositoriesSort } from "./RepositoriesSort";
import { RepositoriesFilter } from "./RepositoriesFilter";
import { RepositoriesResultFormat } from "./RepositoriesResultFormat";
Expand All @@ -16,8 +17,10 @@ import { isSarifResultsQueryKind } from "../../common/query-metadata";
type Props = {
filterSortValue: RepositoriesFilterSortState;
resultFormatValue: ResultFormat;
maxThreadFlowStepsValue: number;
onFilterSortChange: Dispatch<SetStateAction<RepositoriesFilterSortState>>;
onResultFormatChange: Dispatch<SetStateAction<ResultFormat>>;
onMaxThreadFlowStepsChange: Dispatch<SetStateAction<number>>;
variantAnalysisQueryKind: string | undefined;
};

Expand All @@ -41,6 +44,10 @@ const RepositoriesSortColumn = styled(RepositoriesSort)`
flex: 1;
`;

const RepositoriesMaxThreadFlowStepsColumn = styled(MaxThreadFlowStepsBox)`
flex: 1;
`;

const RepositoriesResultFormatColumn = styled(RepositoriesResultFormat)`
flex: 1;
`;
Expand All @@ -54,8 +61,10 @@ function showResultFormatColumn(
export const RepositoriesSearchSortRow = ({
filterSortValue,
resultFormatValue,
maxThreadFlowStepsValue,
onFilterSortChange,
onResultFormatChange,
onMaxThreadFlowStepsChange,
variantAnalysisQueryKind,
}: Props) => {
const handleSearchValueChange = useCallback(
Expand Down Expand Up @@ -95,6 +104,13 @@ export const RepositoriesSearchSortRow = ({
[onResultFormatChange],
);

const handleMaxThreadFlowStepsValueChange = useCallback(
(maxThreadFlowSteps: number) => {
onMaxThreadFlowStepsChange(maxThreadFlowSteps);
},
[onMaxThreadFlowStepsChange],
);

return (
<Container>
<RepositoriesSearchColumn
Expand All @@ -110,6 +126,11 @@ export const RepositoriesSearchSortRow = ({
value={filterSortValue.sortKey}
onChange={handleSortKeyChange}
/>
<RepositoriesMaxThreadFlowStepsColumn
value={maxThreadFlowStepsValue}
placeholder="Max number of steps in a thread flow"
onChange={handleMaxThreadFlowStepsValueChange}
/>
{showResultFormatColumn(variantAnalysisQueryKind) && (
<RepositoriesResultFormatColumn
value={resultFormatValue}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export type VariantAnalysisAnalyzedReposProps = {

resultFormat: ResultFormat;

maxThreadFlowSteps: number;

selectedRepositoryIds?: number[];
setSelectedRepositoryIds?: Dispatch<SetStateAction<number[]>>;
};
Expand All @@ -37,6 +39,7 @@ export const VariantAnalysisAnalyzedRepos = ({
repositoryResults,
filterSortState,
resultFormat,
maxThreadFlowSteps,
selectedRepositoryIds,
setSelectedRepositoryIds,
}: VariantAnalysisAnalyzedReposProps) => {
Expand Down Expand Up @@ -96,6 +99,7 @@ export const VariantAnalysisAnalyzedRepos = ({
interpretedResults={results?.interpretedResults}
rawResults={results?.rawResults}
resultFormat={resultFormat}
maxThreadFlowSteps={maxThreadFlowSteps}
selected={selectedRepositoryIds?.includes(repository.repository.id)}
onSelectedChange={onSelectedChange}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const VariantAnalysisOutcomePanels = ({
variantAnalysis.skippedRepos?.accessMismatchRepos?.repositoryCount ?? 0;

const [resultFormat, setResultFormat] = useState(ResultFormat.Alerts);
const [maxThreadFlowSteps, setMaxThreadFlowSteps] = useState(1337);
const warnings = (
<WarningsContainer>
{variantAnalysis.status === VariantAnalysisStatus.Canceled && (
Expand Down Expand Up @@ -127,8 +128,10 @@ export const VariantAnalysisOutcomePanels = ({
<RepositoriesSearchSortRow
filterSortValue={filterSortState}
resultFormatValue={resultFormat}
maxThreadFlowStepsValue={maxThreadFlowSteps}
onFilterSortChange={setFilterSortState}
onResultFormatChange={setResultFormat}
onMaxThreadFlowStepsChange={setMaxThreadFlowSteps}
variantAnalysisQueryKind={variantAnalysis.query.kind}
/>
<VariantAnalysisAnalyzedRepos
Expand All @@ -137,6 +140,7 @@ export const VariantAnalysisOutcomePanels = ({
repositoryResults={repositoryResults}
filterSortState={filterSortState}
resultFormat={resultFormat}
maxThreadFlowSteps={maxThreadFlowSteps}
selectedRepositoryIds={selectedRepositoryIds}
setSelectedRepositoryIds={setSelectedRepositoryIds}
/>
Expand All @@ -150,8 +154,10 @@ export const VariantAnalysisOutcomePanels = ({
<RepositoriesSearchSortRow
filterSortValue={filterSortState}
resultFormatValue={resultFormat}
maxThreadFlowStepsValue={maxThreadFlowSteps}
onFilterSortChange={setFilterSortState}
onResultFormatChange={setResultFormat}
onMaxThreadFlowStepsChange={setMaxThreadFlowSteps}
variantAnalysisQueryKind={variantAnalysis.query.kind}
/>
<VSCodePanels>
Expand Down Expand Up @@ -187,6 +193,7 @@ export const VariantAnalysisOutcomePanels = ({
repositoryResults={repositoryResults}
filterSortState={filterSortState}
resultFormat={resultFormat}
maxThreadFlowSteps={maxThreadFlowSteps}
selectedRepositoryIds={selectedRepositoryIds}
setSelectedRepositoryIds={setSelectedRepositoryIds}
/>
Expand Down

0 comments on commit 7f6f9c9

Please sign in to comment.