@@ -12,8 +12,11 @@ const elementName = "custom-mapping-property-editor";
12
12
export class CustomMappingPropertyUiElement extends UmbLitElement implements UmbPropertyEditorUiElement {
13
13
#activeCampaignContext! : typeof ACTIVECAMPAIGN_CONTEXT_TOKEN . TYPE ;
14
14
15
- @property ( { attribute : false } )
16
- public customMapping : Array < CustomMappingValue > = [ ] ;
15
+ @property ( { type : String } )
16
+ public value = "" ;
17
+
18
+ @state ( )
19
+ public customMappingArray : Array < CustomMappingValue > = [ ] ;
17
20
18
21
@state ( )
19
22
private selectedCustomField : string = "" ;
@@ -38,6 +41,10 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
38
41
async connectedCallback ( ) {
39
42
super . connectedCallback ( ) ;
40
43
44
+ if ( this . value ) {
45
+ this . customMappingArray = JSON . parse ( this . value ) ;
46
+ }
47
+
41
48
await this . #getCustomFields( ) ;
42
49
await this . #getFormFields( ) ;
43
50
}
@@ -50,7 +57,8 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
50
57
}
51
58
52
59
async #getFormFields( ) {
53
- var result = await this . #activeCampaignContext. getFormFields ( "f595361a-37f9-44da-80ca-6a22d699d923" ) ;
60
+ var formId = window . location . pathname . split ( "/" ) [ 7 ] ; //Get the formid based on current url.
61
+ var result = await this . #activeCampaignContext. getFormFields ( formId ) ;
54
62
55
63
if ( ! result ) return ;
56
64
@@ -66,29 +74,38 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
66
74
}
67
75
68
76
#addButtonClick( ) {
69
- this . customMapping . push ( {
70
- customField : this . selectedCustomField ,
77
+ this . customMappingArray . push ( {
78
+ customField : {
79
+ id : this . selectedCustomField ,
80
+ title : this . getSelectedCustomFieldCaption ( ) !
81
+ } ,
71
82
formField : {
72
83
id : this . selectedFormField ,
73
- value : this . getSelectedFieldCaption ( ) !
84
+ value : this . getSelectedFormFieldCaption ( ) !
74
85
}
75
86
} ) ;
76
87
88
+ this . value = JSON . stringify ( this . customMappingArray ) ;
77
89
this . requestUpdate ( ) ;
78
90
this . dispatchEvent ( new CustomEvent ( 'property-value-change' ) ) ;
79
91
}
80
92
81
- getSelectedFieldCaption ( ) {
93
+ getSelectedFormFieldCaption ( ) {
82
94
return this . formdFields ?. find ( f => f . id == this . selectedFormField ) ?. caption ;
83
95
}
84
96
97
+ getSelectedCustomFieldCaption ( ) {
98
+ return this . customFields ?. find ( f => f . id == this . selectedCustomField ) ?. title ;
99
+ }
100
+
85
101
isDisabled ( ) {
86
102
return ! this . selectedCustomField || ! this . selectedFormField ;
87
103
}
88
104
89
105
#onDeleteClick( idx : number ) {
90
- this . customMapping . splice ( idx , 1 ) ;
106
+ this . customMappingArray . splice ( idx , 1 ) ;
91
107
108
+ this . value = JSON . stringify ( this . customMappingArray ) ;
92
109
this . requestUpdate ( ) ;
93
110
this . dispatchEvent ( new CustomEvent ( 'property-value-change' ) ) ;
94
111
}
@@ -97,7 +114,7 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
97
114
return html `
98
115
<div>
99
116
<uui- select
100
- placeholder= "Select contact field"
117
+ placeholder= ${ this . localize . term ( "formProviderWorkflows_SelectCustomField" ) }
101
118
@change = ${ ( e : UUISelectEvent ) => this . #onCustomSelectChange( e ) }
102
119
.options = ${
103
120
this . customFields ?. map ( ( ft ) => ( {
@@ -106,7 +123,7 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
106
123
selected : ft . id === this . selectedCustomField ,
107
124
} ) ) ?? [ ] } > </ uui- select>
108
125
<uui- select
109
- placeholder= "Select form field"
126
+ placeholder= ${ this . localize . term ( "formProviderWorkflows_SelectFormField" ) }
110
127
@change = ${ ( e : UUISelectEvent ) => this . #onFormFieldSelectChange( e ) }
111
128
.options = ${
112
129
this . formdFields ?. map ( ( ft ) => ( {
@@ -117,36 +134,40 @@ export class CustomMappingPropertyUiElement extends UmbLitElement implements Umb
117
134
</ div>
118
135
119
136
<div class= "activecampaign-wf-button" >
120
- <uui- butto n look= "primary" ?dis abled= ${ this . isDisabled ( ) } label= "Add mapping" @click = ${ this . #addButtonClick} > </ uui- butto n>
137
+ <uui- butto n look= "primary" ?dis abled= ${ this . isDisabled ( ) } label= ${ this . localize . term ( "formProviderWorkflows_AddMapping" ) } @click = ${ this . #addButtonClick} > </ uui- butto n>
121
138
</ div>
122
139
123
140
<div class= "activecampaign-wf-table" >
124
- <table>
125
- <thead>
126
- <tr>
127
- <th> Custom Field </ th>
128
- <th> Form Field </ th>
129
- <th> </ th>
130
- </ tr>
131
- </ thead>
132
- <tbody>
133
- ${ map ( this . customMapping , ( mapping , idx ) => html `
134
- <tr>
135
- <td> ${ mapping . customField } </ td>
136
- <td> ${ mapping . formField ?. value } </ td>
137
- <td>
138
- <uui- butto n
139
- label= ${ this . localize . term ( "formProviderWorkflows_delete" ) }
140
- look= "secondary"
141
- color = "default"
142
- @click = ${ ( ) => this . #onDeleteClick( idx ) } >
143
- <uui- icon name= "delete" > </ uui- icon>
144
- </ uui- butto n>
145
- </ td>
146
- </ tr>
147
- ` ) }
148
- </ tbody>
149
- </ table>
141
+ ${ this . customMappingArray . length > 0
142
+ ? html `
143
+ <table>
144
+ <thead>
145
+ <tr>
146
+ <th> ${ this . localize . term ( "formProviderWorkflows_CustomField" ) } </ th>
147
+ <th> ${ this . localize . term ( "formProviderWorkflows_FormField" ) } </ th>
148
+ <th> </ th>
149
+ </ tr>
150
+ </ thead>
151
+ <tbody>
152
+ ${ map ( this . customMappingArray , ( mapping , idx ) => html `
153
+ <tr>
154
+ <td> ${ mapping . customField ?. title } </ td>
155
+ <td> ${ mapping . formField ?. value } </ td>
156
+ <td>
157
+ <uui- butto n
158
+ label= ${ this . localize . term ( "formProviderWorkflows_delete" ) }
159
+ look= "secondary"
160
+ color = "default"
161
+ @click = ${ ( ) => this . #onDeleteClick( idx ) } >
162
+ <uui- icon name= "delete" > </ uui- icon>
163
+ </ uui- butto n>
164
+ </ td>
165
+ </ tr>
166
+ ` ) }
167
+ </ tbody>
168
+ </ table>
169
+ `
170
+ : html `` }
150
171
</ div>
151
172
` ;
152
173
}
0 commit comments