1- import type {
2- Location as SarifLogLocation ,
3- ReportingDescriptorReference ,
4- ThreadFlowLocation ,
5- Run ,
6- PhysicalLocation ,
7- ArtifactLocation ,
8- ToolComponent ,
9- } from "sarif" ;
1+ import type { ThreadFlowLocation , Run } from "sarif" ;
102import type {
113 PathNode ,
124 Result as ResultKeysResult ,
@@ -18,150 +10,7 @@ import { selectableZebraStripe } from "./result-table-utils";
1810import { useCallback , useMemo } from "react" ;
1911import { VerticalRule } from "../common/VerticalRule" ;
2012import type { UserSettings } from "../../common/interface-types" ;
21-
22- /** The definition of a taxon for a data extension model row. */
23- interface ModelTaxon {
24- location : SarifLogLocation ;
25- }
26-
27- /** Resolve an `ArtifactLocation` that might contain a relative reference instead of an absolute
28- * URI.
29- */
30- function resolveArtifactLocation (
31- location : ArtifactLocation ,
32- baseUri : URL ,
33- ) : ArtifactLocation {
34- if ( location . uri === undefined ) {
35- // No URI at all. Just return the original location.
36- return location ;
37- }
38- return {
39- ...location ,
40- uri : new URL ( location . uri , baseUri ) . toString ( ) ,
41- } ;
42- }
43-
44- /** Get the URI of the pack's local root directory, if available. */
45- function getLocalPackUri ( extension : ToolComponent ) : URL | undefined {
46- if ( extension . locations === undefined ) {
47- return undefined ;
48- }
49-
50- const localPackLocation = extension . locations . find (
51- ( loc ) =>
52- loc . properties !== undefined &&
53- loc . properties . tags !== undefined &&
54- loc . properties . tags . includes ( "CodeQL/LocalPackRoot" ) ,
55- ) ;
56- if ( localPackLocation === undefined || localPackLocation . uri === undefined ) {
57- return undefined ;
58- }
59-
60- return new URL ( localPackLocation . uri ) ;
61- }
62-
63- /** Resolve a `ReportingDescriptorReference` to the `ReportingDescriptor` for the taxon that it
64- * refers to.
65- */
66- function resolveTaxonDefinition (
67- run : Run ,
68- taxonRef : ReportingDescriptorReference ,
69- ) : ModelTaxon | undefined {
70- const extensions = run . tool . extensions ;
71- if ( extensions === undefined ) {
72- return undefined ;
73- }
74-
75- const extensionIndex = taxonRef . toolComponent ?. index ;
76- if (
77- extensionIndex === undefined ||
78- extensionIndex < 0 ||
79- extensionIndex >= extensions . length
80- ) {
81- return undefined ;
82- }
83-
84- const extension = extensions [ extensionIndex ] ;
85- if ( extension . taxa === undefined ) {
86- return undefined ;
87- }
88-
89- const localPackUri = getLocalPackUri ( extension ) ;
90- if ( localPackUri === undefined ) {
91- return undefined ;
92- }
93-
94- const taxonIndex = taxonRef . index ;
95- if (
96- taxonIndex === undefined ||
97- taxonIndex < 0 ||
98- taxonIndex >= extension . taxa . length
99- ) {
100- return undefined ;
101- }
102-
103- const taxonDef = extension . taxa [ taxonIndex ] ;
104- if ( taxonDef . properties === undefined ) {
105- return undefined ;
106- }
107-
108- const location : PhysicalLocation =
109- taxonDef . properties [ "CodeQL/DataExtensionLocation" ] ;
110- if ( location === undefined || location . artifactLocation === undefined ) {
111- return undefined ;
112- }
113-
114- return {
115- location : {
116- physicalLocation : {
117- ...location ,
118- artifactLocation : resolveArtifactLocation (
119- location . artifactLocation ,
120- localPackUri ,
121- ) ,
122- } ,
123- } ,
124- } ;
125- }
126-
127- /** Generate the React elements for each taxon. */
128- function taxaLocations (
129- taxa : ReportingDescriptorReference [ ] | undefined ,
130- run : Run | undefined ,
131- onClick : ( ) => void ,
132- ) {
133- if ( taxa === undefined || taxa . length === 0 || run === undefined ) {
134- return [ ] ;
135- }
136-
137- return taxa . flatMap ( ( taxonRef , index ) => {
138- if ( taxonRef . properties === undefined ) {
139- return [ ] ;
140- }
141-
142- const role = taxonRef . properties [ "CodeQL/DataflowRole" ] ;
143- if ( typeof role !== "string" ) {
144- return [ ] ;
145- }
146-
147- const taxonDef = resolveTaxonDefinition ( run , taxonRef ) ;
148- if ( taxonDef === undefined ) {
149- return [ ] ;
150- }
151-
152- return (
153- < div key = { index } >
154- { `(${ role } ) ` }
155- < SarifLocation
156- loc = { taxonDef . location }
157- databaseUri = { undefined }
158- sourceLocationPrefix = ""
159- onClick = { onClick }
160- />
161- </ div >
162- ) ;
163- } ) ;
164- }
13+ import { TaxaLocations } from "./locations/TaxaLocations" ;
16514
16615interface Props {
16716 step : ThreadFlowLocation ;
@@ -252,11 +101,13 @@ export function AlertTablePathNodeRow(props: Props) {
252101 >
253102 { userSettings . shouldShowProvenance ? (
254103 < div className = "vscode-codeql__taxa-cell-div" >
255- { taxaLocations ( step . taxa , run , handleSarifLocationClicked ) }
104+ < TaxaLocations
105+ taxa = { step . taxa }
106+ run = { run }
107+ onClick = { handleSarifLocationClicked }
108+ />
256109 </ div >
257- ) : (
258- [ ]
259- ) }
110+ ) : null }
260111 </ td >
261112 < td
262113 { ...selectableZebraStripe (
0 commit comments