@@ -3,6 +3,7 @@ import getRelatedList from '@salesforce/apex/TAG_RelatedListController.getRelate
3
3
import { NavigationMixin } from 'lightning/navigation' ;
4
4
import { getRecord } from 'lightning/uiRecordApi' ;
5
5
import { getObjectInfo } from 'lightning/uiObjectInfoApi' ;
6
+ import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils' ;
6
7
7
8
export default class TagRelatedList extends NavigationMixin ( LightningElement ) {
8
9
@@ -102,12 +103,19 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
102
103
handleNewRecord ( event ) {
103
104
// Prevent the header's onclick from firing
104
105
event . stopPropagation ( ) ;
106
+
107
+ const defaultValues = encodeDefaultFieldValues ( {
108
+ [ this . relationField ] : this . recordId
109
+ } ) ;
105
110
this [ NavigationMixin . Navigate ] ( {
106
111
type : 'standard__objectPage' ,
107
112
attributes : {
108
113
objectApiName : this . relatedObjectApiName ,
109
114
actionName : 'new'
110
- }
115
+ } ,
116
+ state : {
117
+ defaultFieldValues : defaultValues
118
+ }
111
119
} ) ;
112
120
}
113
121
@@ -130,11 +138,16 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
130
138
if ( this . relatedRecords ) {
131
139
// Parse the inactive filter if provided
132
140
let filterField = null ;
141
+ let filterOperator = null ;
133
142
let filterValue = null ;
134
- if ( this . inactiveRecordFilter && this . inactiveRecordFilter . includes ( '=' ) ) {
135
- let parts = this . inactiveRecordFilter . split ( '=' ) ;
136
- filterField = parts [ 0 ] . trim ( ) ;
137
- filterValue = parts [ 1 ] . trim ( ) . toLowerCase ( ) ;
143
+ if ( this . inactiveRecordFilter ) {
144
+ let regex = / ^ ( [ ^ ! < > = ] + ) \s * ( = | ! = ) \s * ( .* ) $ / ;
145
+ let match = this . inactiveRecordFilter . match ( regex ) ;
146
+ if ( match ) {
147
+ filterField = match [ 1 ] . trim ( ) ;
148
+ filterOperator = match [ 2 ] . trim ( ) ;
149
+ filterValue = match [ 3 ] . trim ( ) . toLowerCase ( ) ;
150
+ }
138
151
}
139
152
140
153
this . relatedRecords . forEach ( ( dataRecord ) => {
@@ -148,17 +161,18 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
148
161
}
149
162
} ) ;
150
163
151
- // Determine if the record is inactive
152
164
let isInactive = false ;
153
- if ( filterField && filterValue !== null ) {
165
+ if ( filterField ) {
154
166
let fieldVal = this . resolve ( filterField , dataRecord ) ;
155
- // Convert the field value to string (if boolean, true/false will be 'true'/'false')
156
- if ( fieldVal !== null && String ( fieldVal ) . toLowerCase ( ) === filterValue ) {
157
- isInactive = true ;
167
+ let recordValue = fieldVal !== null ? String ( fieldVal ) . toLowerCase ( ) : null ;
168
+
169
+ if ( filterOperator === "=" ) {
170
+ isInactive = ( recordValue === filterValue ) ;
171
+ } else if ( filterOperator === "!=" ) {
172
+ isInactive = ( recordValue !== filterValue && recordValue !== null ) ;
158
173
}
159
174
}
160
175
161
- // Set rowClass based on whether the record is inactive.
162
176
let rowClass = 'slds-hint-parent' ;
163
177
if ( isInactive ) {
164
178
rowClass += ' inactiveRow' ;
@@ -203,7 +217,7 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
203
217
: [ ] ;
204
218
return labels . map ( ( label , index , arr ) => {
205
219
// Base style for every header cell.
206
- let style = 'vertical-align: middle; text-align: left; padding: 4px 8px;' ;
220
+ let style = 'vertical-align: middle; text-align: left; padding: 4px 8px; max-width: 33% ' ;
207
221
// Padding for the first cell.
208
222
if ( index === 0 ) {
209
223
style += 'padding-left: 1rem;' ;
@@ -225,10 +239,14 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
225
239
let combined = Array . from ( new Set ( [ ...displayed , ...popover ] ) ) ;
226
240
227
241
// extract the field name and add it to the list if not already present.
228
- if ( this . inactiveRecordFilter && this . inactiveRecordFilter . includes ( '=' ) ) {
229
- let filterField = this . inactiveRecordFilter . split ( '=' ) [ 0 ] . trim ( ) ;
230
- if ( ! combined . includes ( filterField ) ) {
231
- combined . push ( filterField ) ;
242
+ if ( this . inactiveRecordFilter ) {
243
+ let regex = / ^ ( [ ^ ! < > = ] + ) \s * ( = | ! = ) \s * ( .* ) $ / ;
244
+ let match = this . inactiveRecordFilter . match ( regex ) ;
245
+ if ( match ) {
246
+ let filterField = match [ 1 ] . trim ( ) ;
247
+ if ( ! combined . includes ( filterField ) ) {
248
+ combined . push ( filterField ) ;
249
+ }
232
250
}
233
251
}
234
252
return combined ;
0 commit comments