@@ -5,6 +5,10 @@ import { getRecord } from 'lightning/uiRecordApi';
5
5
import { getObjectInfo } from 'lightning/uiObjectInfoApi' ;
6
6
7
7
export default class TagRelatedList extends NavigationMixin ( LightningElement ) {
8
+
9
+ hoverTimer ;
10
+ hideTimer ;
11
+
8
12
@api recordId ;
9
13
@api objectApiName ;
10
14
@api listTitle ; // Title of the list.
@@ -24,14 +28,13 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
24
28
@api popoverFields ; //Popover additional fields (comma separated)
25
29
@api showNewRecordButton ;
26
30
@api newRecordButtonLabel ; // Button label for New Record button
27
-
31
+ @ api inactiveRecordFilter ; // Example: "Active__c = false"
28
32
29
33
@track relatedRecords ;
30
34
@track isExpanded = false ; // Accordion state
31
35
32
36
@track popoverRecordData ; // Holds the record data for the hovered row
33
37
@track showPopover = false ; // Flag to conditionally display popover
34
- hoverTimer ; // Timer for delayed popover display
35
38
@track popoverPosition = { top : 0 , left : 0 } ;
36
39
37
40
connectedCallback ( ) {
@@ -48,7 +51,6 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
48
51
if ( data && this . dynamicUpdate === true ) {
49
52
this . getList ( ) ;
50
53
} else if ( error ) {
51
- // Handle error accordingly
52
54
}
53
55
}
54
56
@@ -126,6 +128,15 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
126
128
get listRecords ( ) {
127
129
let returnRecords = [ ] ;
128
130
if ( this . relatedRecords ) {
131
+ // Parse the inactive filter if provided
132
+ let filterField = null ;
133
+ 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 ( ) ;
138
+ }
139
+
129
140
this . relatedRecords . forEach ( ( dataRecord ) => {
130
141
let recordFields = [ ] ;
131
142
this . displayedFieldList . forEach ( ( key ) => {
@@ -136,11 +147,34 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
136
147
} ) ;
137
148
}
138
149
} ) ;
139
- returnRecords . push ( { recordFields : recordFields , Id : dataRecord . Id } ) ;
150
+
151
+ // Determine if the record is inactive
152
+ let isInactive = false ;
153
+ if ( filterField && filterValue !== null ) {
154
+ 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 ;
158
+ }
159
+ }
160
+
161
+ // Set rowClass based on whether the record is inactive.
162
+ let rowClass = 'slds-hint-parent' ;
163
+ if ( isInactive ) {
164
+ rowClass += ' inactiveRow' ;
165
+ }
166
+
167
+ returnRecords . push ( {
168
+ recordFields : recordFields ,
169
+ Id : dataRecord . Id ,
170
+ isInactive : isInactive ,
171
+ rowClass : rowClass
172
+ } ) ;
140
173
} ) ;
141
174
}
142
175
return returnRecords ;
143
176
}
177
+
144
178
145
179
// Build the card title with record count
146
180
get cardTitle ( ) {
@@ -170,11 +204,10 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
170
204
return labels . map ( ( label , index , arr ) => {
171
205
// Base style for every header cell.
172
206
let style = 'vertical-align: middle; text-align: left; padding: 4px 8px;' ;
173
- // Remove extra left padding for the first cell.
207
+ // Padding for the first cell.
174
208
if ( index === 0 ) {
175
- style += 'padding-left: 5px ;' ;
209
+ style += 'padding-left: 1rem ;' ;
176
210
}
177
- // Remove extra right padding for the last cell.
178
211
if ( index === arr . length - 1 ) {
179
212
style += 'padding-right: 0px;' ;
180
213
}
@@ -185,14 +218,19 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
185
218
} ) ;
186
219
}
187
220
188
- // Parse and combine the displayed fields and popoverFields strings into an array
189
221
get apexFieldList ( ) {
190
- // Get displayedFields (if any)
222
+ // Get fields from displayedFields and popoverFields
191
223
let displayed = this . displayedFields ? this . displayedFields . replace ( / \s / g, '' ) . split ( ',' ) : [ ] ;
192
- // Get popoverFields (if any)
193
224
let popover = this . popoverFields ? this . popoverFields . replace ( / \s / g, '' ) . split ( ',' ) : [ ] ;
194
- // Combine them and remove duplicates
195
225
let combined = Array . from ( new Set ( [ ...displayed , ...popover ] ) ) ;
226
+
227
+ // 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 ) ;
232
+ }
233
+ }
196
234
return combined ;
197
235
}
198
236
@@ -218,25 +256,29 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
218
256
} , obj || { } ) ;
219
257
}
220
258
221
- // Event handler for mouse enter on a record row
222
259
handleMouseEnter ( event ) {
223
260
const recordId = event . currentTarget . dataset . recordId ;
224
261
const rect = event . currentTarget . getBoundingClientRect ( ) ;
225
- // Adjusting the position slightly (you can fine‑tune the offsets)
226
262
this . popoverPosition = {
227
- top : rect . top + 10 ,
228
- left : rect . left + 10
263
+ top : rect . top + 2 ,
264
+ left : rect . left + 2
229
265
} ;
230
266
this . hoverTimer = window . setTimeout ( ( ) => {
231
267
this . popoverRecordData = this . relatedRecords . find ( rec => rec . Id === recordId ) ;
232
268
this . showPopover = true ;
233
- } , 1500 ) ;
269
+ } , 1000 ) ;
234
270
}
235
271
236
- // Event handler for mouse leave from a record row (or popover)
237
272
handleMouseLeave ( ) {
238
273
window . clearTimeout ( this . hoverTimer ) ;
239
- this . showPopover = false ;
274
+ this . hideTimer = window . setTimeout ( ( ) => {
275
+ this . showPopover = false ;
276
+ } , 200 ) ; // Delay closing popover to allow mouse movement
277
+ }
278
+
279
+ handlePopoverEnter ( ) {
280
+ // Prevent hiding when entering the popover
281
+ window . clearTimeout ( this . hideTimer ) ;
240
282
}
241
283
242
284
// Getter to combine displayedFields with additional popoverFields
@@ -246,7 +288,6 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
246
288
247
289
// Getter to prepare an array of objects with localized field labels and values from the hovered record
248
290
get popoverFieldValues ( ) {
249
- // Ensure we have the record data and the object metadata
250
291
if ( ! this . popoverRecordData || ! this . objectInfo . data ) {
251
292
return [ ] ;
252
293
}
@@ -275,7 +316,17 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
275
316
top: ${ relativeTop + 20 } px;
276
317
left: ${ relativeLeft } px;
277
318
z-index: 1000;
278
- transform: translate(-50%, 0);` ;
319
+ transform: translate(0, 0);` ;
320
+ }
321
+ return '' ;
322
+ }
323
+
324
+ get popoverTitle ( ) {
325
+ if ( this . popoverRecordData && this . displayedFieldList && this . displayedFieldList . length > 0 && this . objectInfo . data ) {
326
+ // Get the first field's API name from the displayedFields array
327
+ let firstFieldApiName = this . displayedFieldList [ 0 ] ;
328
+ let fieldValue = this . resolve ( firstFieldApiName , this . popoverRecordData ) ;
329
+ return `${ fieldValue } ` ;
279
330
}
280
331
return '' ;
281
332
}
0 commit comments