@@ -10,6 +10,11 @@ class Action {
10
10
// We're using map, to overwrite existing keys. for example:
11
11
// addParam(w_100).addQualifier(w_200) should result in w_200. and not w_100,w_200
12
12
qualifiers : Map < string , Qualifier > = new Map ( ) ;
13
+
14
+ // Unlike regular qualifiers, there can be multiple flags in each url component /fl_1,fl_2/
15
+ // If the falgs are added to the qualifiers map, only a single flag could exist in a component (it's a map)
16
+ // So flags are stored separately until the very end because of that reason
17
+ flags : FlagQualifier [ ] = [ ] ;
13
18
private delimiter = ',' ; // {qualifier}{delimiter}{qualifier} for example: `${'w_100'}${','}${'c_fill'}`
14
19
protected prepareQualifiers ( ) :void { }
15
20
private actionTag = '' ; // A custom name tag to identify this action in the future
@@ -37,16 +42,33 @@ class Action {
37
42
*/
38
43
toString ( ) : string {
39
44
this . prepareQualifiers ( ) ;
40
- return mapToSortedArray ( this . qualifiers ) . join ( this . delimiter ) ;
45
+ return mapToSortedArray ( this . qualifiers , this . flags ) . join ( this . delimiter ) ;
41
46
}
42
47
43
48
/**
44
49
* @description Adds the parameter to the action.
45
50
* @param {SDK.Qualifier } qualifier
46
51
* @return {this }
47
52
*/
48
- addQualifier ( qualifier : Qualifier ) : this {
49
- this . qualifiers . set ( qualifier . key , qualifier ) ;
53
+ addQualifier ( qualifier : Qualifier | string ) : this {
54
+ // if string, find the key and value
55
+ if ( typeof qualifier === 'string' ) {
56
+ const [ key , value ] = qualifier . toLowerCase ( ) . split ( '_' ) ;
57
+
58
+
59
+ if ( key === 'fl' ) {
60
+ // if string qualifier is a flag, store it in the flags arrays
61
+ this . flags . push ( new FlagQualifier ( value ) ) ;
62
+ } else {
63
+ // if the string qualifier is not a flag, create a new qualifier from it
64
+ this . qualifiers . set ( key , new Qualifier ( key , value ) ) ;
65
+ }
66
+
67
+ } else {
68
+ // if a qualifier object, insert to the qualifiers map
69
+ this . qualifiers . set ( qualifier . key , qualifier ) ;
70
+ }
71
+
50
72
return this ;
51
73
}
52
74
@@ -55,14 +77,11 @@ class Action {
55
77
* @param {Values.Flag } flag
56
78
* @return {this }
57
79
*/
58
- addFlag ( flag : FlagQualifier ) : this {
59
- const existingFlag = this . qualifiers . get ( 'fl_' ) ;
60
- flag . qualifierValue . setDelimiter ( '.' ) ;
61
-
62
- if ( existingFlag ) {
63
- existingFlag . addValue ( flag . qualifierValue ) ;
80
+ addFlag ( flag : FlagQualifier | string ) : this {
81
+ if ( typeof flag === 'string' ) {
82
+ this . flags . push ( new FlagQualifier ( flag ) ) ;
64
83
} else {
65
- this . qualifiers . set ( 'fl_' , flag ) ;
84
+ this . flags . push ( flag ) ;
66
85
}
67
86
68
87
return this ;
0 commit comments