Skip to content

Commit 4a6505e

Browse files
committed
Handle negative inactiveFilter logic; autofill for new record with Account; fixed table column width,
1 parent e61aa48 commit 4a6505e

File tree

2 files changed

+64
-10
lines changed

2 files changed

+64
-10
lines changed

force-app/components/relatedList/lwc/tagRelatedList/tagRelatedList.html

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ <h1 class="headerTitle slds-text-heading_small">{cardTitle}</h1>
2828
<!-- TABLE RENDERED BASED ON EXPANSION STATE -->
2929
<template if:true={showRecords}>
3030
<div style="overflow:auto; max-height: {maxHeight}em;">
31-
<table class="slds-table slds-table_cell-buffer slds-table_bordered slds-max-medium-table_stacked-horizontal" style="table-layout: auto;">
31+
<table class="slds-table slds-table_cell-buffer slds-table_bordered slds-max-medium-table_stacked-horizontal" style="table-layout: fixed; width: 100%;">
3232
<thead>
3333
<tr class="slds-line-height_reset">
3434
<template for:each={fieldLabels} for:item="label">
3535
<th key={label.value} scope="col" style={label.headerStyle}>
36-
<div style="display: flex; align-items: center; height: 100%; font-size: 0.75rem; white-space: nowrap;" title={label.value}>
36+
<div style="display: flex; align-items: center; height: 100%; font-size: 0.75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" title={label.value}>
3737
{label.value}
3838
</div>
3939
</th>
@@ -47,8 +47,8 @@ <h1 class="headerTitle slds-text-heading_small">{cardTitle}</h1>
4747
<tr key={record.Id} data-record-id={record.Id} data-value={rowIndex} class="slds-hint-parent" onclick={handleRowClick} style="cursor: pointer"
4848
onmouseenter={handleMouseEnter} onmouseleave={handleMouseLeave}>
4949
<template for:each={record.recordFields} for:item="field">
50-
<td key={field.label}>
51-
<div class="slds-truncate slds-cell-wrap">{field.value}</div>
50+
<td key={field.label} style="max-width: 33%">
51+
<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" class="slds-truncate slds-cell-wrap">{field.value}</div>
5252
</td>
5353
</template>
5454
</tr>
@@ -58,8 +58,8 @@ <h1 class="headerTitle slds-text-heading_small">{cardTitle}</h1>
5858
<tr key={record.Id} data-record-id={record.Id} data-value={rowIndex} class="slds-hint-parent"
5959
onmouseenter={handleMouseEnter} onmouseleave={handleMouseLeave}>
6060
<template for:each={record.recordFields} for:item="field">
61-
<td key={field.label}>
62-
<div class="slds-truncate slds-cell-wrap">{field.value}</div>
61+
<td key={field.label} style="max-width: 33%">
62+
<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" class="slds-truncate slds-cell-wrap">{field.value}</div>
6363
</td>
6464
</template>
6565
</tr>

force-app/components/relatedList/lwc/tagRelatedList/tagRelatedList.js

+58-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import getRelatedList from '@salesforce/apex/TAG_RelatedListController.getRelate
33
import { NavigationMixin } from 'lightning/navigation';
44
import { getRecord } from 'lightning/uiRecordApi';
55
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
6+
import { encodeDefaultFieldValues } from 'lightning/pageReferenceUtils';
67

78
export default class TagRelatedList extends NavigationMixin(LightningElement) {
89
@api recordId;
@@ -100,12 +101,19 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
100101
handleNewRecord(event) {
101102
// Prevent the header's onclick from firing
102103
event.stopPropagation();
104+
105+
const defaultValues = encodeDefaultFieldValues({
106+
[this.relationField]: this.recordId
107+
});
103108
this[NavigationMixin.Navigate]({
104109
type: 'standard__objectPage',
105110
attributes: {
106111
objectApiName: this.relatedObjectApiName,
107112
actionName: 'new'
108-
}
113+
},
114+
state: {
115+
defaultFieldValues: defaultValues
116+
}
109117
});
110118
}
111119

@@ -126,6 +134,20 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
126134
get listRecords() {
127135
let returnRecords = [];
128136
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+
129151
this.relatedRecords.forEach((dataRecord) => {
130152
let recordFields = [];
131153
this.displayedFieldList.forEach((key) => {
@@ -136,7 +158,30 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
136158
});
137159
}
138160
});
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+
});
140185
});
141186
}
142187
return returnRecords;
@@ -169,8 +214,8 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
169214
: [];
170215
return labels.map((label, index, arr) => {
171216
// 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.
174219
if (index === 0) {
175220
style += 'padding-left: 5px;';
176221
}
@@ -193,6 +238,15 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
193238
let popover = this.popoverFields ? this.popoverFields.replace(/\s/g, '').split(',') : [];
194239
// Combine them and remove duplicates
195240
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);
196250
return combined;
197251
}
198252

0 commit comments

Comments
 (0)