@@ -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
@api recordId ;
@@ -100,12 +101,19 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
100
101
handleNewRecord ( event ) {
101
102
// Prevent the header's onclick from firing
102
103
event . stopPropagation ( ) ;
104
+
105
+ const defaultValues = encodeDefaultFieldValues ( {
106
+ [ this . relationField ] : this . recordId
107
+ } ) ;
103
108
this [ NavigationMixin . Navigate ] ( {
104
109
type : 'standard__objectPage' ,
105
110
attributes : {
106
111
objectApiName : this . relatedObjectApiName ,
107
112
actionName : 'new'
108
- }
113
+ } ,
114
+ state : {
115
+ defaultFieldValues : defaultValues
116
+ }
109
117
} ) ;
110
118
}
111
119
@@ -126,6 +134,20 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
126
134
get listRecords ( ) {
127
135
let returnRecords = [ ] ;
128
136
if ( this . relatedRecords ) {
137
+ // Parse the inactive filter if provided
138
+ let filterField = null ;
139
+ let filterOperator = null ;
140
+ let filterValue = null ;
141
+ if ( this . inactiveRecordFilter ) {
142
+ let regex = / ^ ( [ ^ ! < > = ] + ) \s * ( = | ! = ) \s * ( .* ) $ / ;
143
+ let match = this . inactiveRecordFilter . match ( regex ) ;
144
+ if ( match ) {
145
+ filterField = match [ 1 ] . trim ( ) ;
146
+ filterOperator = match [ 2 ] . trim ( ) ;
147
+ filterValue = match [ 3 ] . trim ( ) . toLowerCase ( ) ;
148
+ }
149
+ }
150
+
129
151
this . relatedRecords . forEach ( ( dataRecord ) => {
130
152
let recordFields = [ ] ;
131
153
this . displayedFieldList . forEach ( ( key ) => {
@@ -136,7 +158,30 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
136
158
} ) ;
137
159
}
138
160
} ) ;
139
- returnRecords . push ( { recordFields : recordFields , Id : dataRecord . Id } ) ;
161
+
162
+ let isInactive = false ;
163
+ if ( filterField ) {
164
+ let fieldVal = this . resolve ( filterField , dataRecord ) ;
165
+ let recordValue = fieldVal !== null ? String ( fieldVal ) . toLowerCase ( ) : null ;
166
+
167
+ if ( filterOperator === "=" ) {
168
+ isInactive = ( recordValue === filterValue ) ;
169
+ } else if ( filterOperator === "!=" ) {
170
+ isInactive = ( recordValue !== filterValue && recordValue !== null ) ;
171
+ }
172
+ }
173
+
174
+ let rowClass = 'slds-hint-parent' ;
175
+ if ( isInactive ) {
176
+ rowClass += ' inactiveRow' ;
177
+ }
178
+
179
+ returnRecords . push ( {
180
+ recordFields : recordFields ,
181
+ Id : dataRecord . Id ,
182
+ isInactive : isInactive ,
183
+ rowClass : rowClass
184
+ } ) ;
140
185
} ) ;
141
186
}
142
187
return returnRecords ;
@@ -169,8 +214,8 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
169
214
: [ ] ;
170
215
return labels . map ( ( label , index , arr ) => {
171
216
// Base style for every header cell.
172
- let style = 'vertical-align: middle; text-align: left; padding: 4px 8px;' ;
173
- // Remove extra left padding for the first cell.
217
+ let style = 'vertical-align: middle; text-align: left; padding: 4px 8px; max-width: 33% ' ;
218
+ // Padding for the first cell.
174
219
if ( index === 0 ) {
175
220
style += 'padding-left: 5px;' ;
176
221
}
@@ -193,6 +238,15 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
193
238
let popover = this . popoverFields ? this . popoverFields . replace ( / \s / g, '' ) . split ( ',' ) : [ ] ;
194
239
// Combine them and remove duplicates
195
240
let combined = Array . from ( new Set ( [ ...displayed , ...popover ] ) ) ;
241
+
242
+ // extract the field name and add it to the list if not already present.
243
+ if ( this . inactiveRecordFilter ) {
244
+ let regex = / ^ ( [ ^ ! < > = ] + ) \s * ( = | ! = ) \s * ( .* ) $ / ;
245
+ let match = this . inactiveRecordFilter . match ( regex ) ;
246
+ if ( match ) {
247
+ let filterField = match [ 1 ] . trim ( ) ;
248
+ if ( ! combined . includes ( filterField ) ) {
249
+ combined . push ( filterField ) ;
196
250
return combined ;
197
251
}
198
252
0 commit comments