1
1
import { AbstractParseTreeVisitor } from 'antlr4ts/tree/AbstractParseTreeVisitor' ;
2
2
import escapeRegExp from 'lodash/escapeRegExp' ;
3
- import { SupplementaryInformation } from 'shared/asset-graph/useAssetGraphSupplementaryData.oss' ;
4
3
5
- import { getFunctionName , getTraversalDepth , getValue } from './util' ;
4
+ import { SupplementaryInformation } from './types' ;
5
+ import {
6
+ getAssetsByKey ,
7
+ getFunctionName ,
8
+ getSupplementaryDataKey ,
9
+ getTraversalDepth ,
10
+ getValue ,
11
+ } from './util' ;
6
12
import { GraphTraverser } from '../app/GraphQueryImpl' ;
7
- import { AssetGraphQueryItem } from '../asset-graph/useAssetGraphData' ;
13
+ import { tokenForAssetKey } from '../asset-graph/Utils' ;
14
+ import { AssetGraphQueryItem } from '../asset-graph/types' ;
8
15
import { buildRepoPathForHuman } from '../workspace/buildRepoAddress' ;
9
16
import {
10
17
AllExpressionContext ,
@@ -21,6 +28,7 @@ import {
21
28
OwnerAttributeExprContext ,
22
29
ParenthesizedExpressionContext ,
23
30
StartContext ,
31
+ StatusAttributeExprContext ,
24
32
TagAttributeExprContext ,
25
33
TraversalAllowedExpressionContext ,
26
34
UpAndDownTraversalExpressionContext ,
@@ -32,20 +40,24 @@ export class AntlrAssetSelectionVisitor
32
40
extends AbstractParseTreeVisitor < Set < AssetGraphQueryItem > >
33
41
implements AssetSelectionVisitor < Set < AssetGraphQueryItem > >
34
42
{
35
- all_assets : Set < AssetGraphQueryItem > ;
36
- focus_assets : Set < AssetGraphQueryItem > ;
37
- traverser : GraphTraverser < AssetGraphQueryItem > ;
43
+ protected all_assets : Set < AssetGraphQueryItem > ;
44
+ public focus_assets : Set < AssetGraphQueryItem > ;
45
+ protected traverser : GraphTraverser < AssetGraphQueryItem > ;
46
+ protected supplementaryData : SupplementaryInformation ;
47
+ protected allAssetsByKey : Map < string , AssetGraphQueryItem > ;
38
48
39
49
protected defaultResult ( ) {
40
50
return new Set < AssetGraphQueryItem > ( ) ;
41
51
}
42
52
43
53
// Supplementary data is not used in oss
44
- constructor ( all_assets : AssetGraphQueryItem [ ] , _supplementaryData ? : SupplementaryInformation ) {
54
+ constructor ( all_assets : AssetGraphQueryItem [ ] , supplementaryData : SupplementaryInformation ) {
45
55
super ( ) ;
46
56
this . all_assets = new Set ( all_assets ) ;
47
57
this . focus_assets = new Set ( ) ;
48
58
this . traverser = new GraphTraverser ( all_assets ) ;
59
+ this . supplementaryData = supplementaryData ;
60
+ this . allAssetsByKey = getAssetsByKey ( all_assets ) ;
49
61
}
50
62
51
63
visitStart ( ctx : StartContext ) {
@@ -208,4 +220,21 @@ export class AntlrAssetSelectionVisitor
208
220
}
209
221
return selection ;
210
222
}
223
+
224
+ visitStatusAttributeExpr ( ctx : StatusAttributeExprContext ) {
225
+ const statusName : string = getValue ( ctx . value ( ) ) ;
226
+ const supplementaryDataKey = getSupplementaryDataKey ( {
227
+ field : 'status' ,
228
+ value : statusName ,
229
+ } ) ;
230
+ const matchingAssetKeys = this . supplementaryData ?. [ supplementaryDataKey ] ;
231
+ if ( ! matchingAssetKeys ) {
232
+ return new Set < AssetGraphQueryItem > ( ) ;
233
+ }
234
+ return new Set (
235
+ matchingAssetKeys
236
+ . map ( ( key ) => this . allAssetsByKey . get ( tokenForAssetKey ( key ) ) ! )
237
+ . filter ( Boolean ) ,
238
+ ) ;
239
+ }
211
240
}
0 commit comments