Skip to content

Commit ff42eb2

Browse files
authored
Handle negative inactiveFilter logic; autofill for new record with Ac… (#2129)
* Handle negative inactiveFilter logic; autofill for new record with Account; fixed table column width, * Update tagRelatedList.js
1 parent adbcd47 commit ff42eb2

File tree

2 files changed

+40
-22
lines changed

2 files changed

+40
-22
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>
@@ -46,8 +46,8 @@ <h1 class="headerTitle slds-text-heading_small">{cardTitle}</h1>
4646
<tr key={record.Id} data-record-id={record.Id} data-value={rowIndex} class={record.rowClass} onclick={handleRowClick} style="cursor: pointer"
4747
onmouseenter={handleMouseEnter} onmouseleave={handleMouseLeave}>
4848
<template for:each={record.recordFields} for:item="field">
49-
<td key={field.label}>
50-
<div class="slds-truncate slds-cell-wrap">{field.value}</div>
49+
<td key={field.label} style="max-width: 33%">
50+
<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" class="slds-truncate slds-cell-wrap">{field.value}</div>
5151
</td>
5252
</template>
5353
</tr>
@@ -56,8 +56,8 @@ <h1 class="headerTitle slds-text-heading_small">{cardTitle}</h1>
5656
<tr key={record.Id} data-record-id={record.Id} data-value={rowIndex} class={record.rowClass}
5757
onmouseenter={handleMouseEnter} onmouseleave={handleMouseLeave}>
5858
<template for:each={record.recordFields} for:item="field">
59-
<td key={field.label}>
60-
<div class="slds-truncate slds-cell-wrap">{field.value}</div>
59+
<td key={field.label} style="max-width: 33%">
60+
<div style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;" class="slds-truncate slds-cell-wrap">{field.value}</div>
6161
</td>
6262
</template>
6363
</tr>

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

+34-16
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

@@ -102,12 +103,19 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
102103
handleNewRecord(event) {
103104
// Prevent the header's onclick from firing
104105
event.stopPropagation();
106+
107+
const defaultValues = encodeDefaultFieldValues({
108+
[this.relationField]: this.recordId
109+
});
105110
this[NavigationMixin.Navigate]({
106111
type: 'standard__objectPage',
107112
attributes: {
108113
objectApiName: this.relatedObjectApiName,
109114
actionName: 'new'
110-
}
115+
},
116+
state: {
117+
defaultFieldValues: defaultValues
118+
}
111119
});
112120
}
113121

@@ -130,11 +138,16 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
130138
if (this.relatedRecords) {
131139
// Parse the inactive filter if provided
132140
let filterField = null;
141+
let filterOperator = null;
133142
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+
}
138151
}
139152

140153
this.relatedRecords.forEach((dataRecord) => {
@@ -148,17 +161,18 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
148161
}
149162
});
150163

151-
// Determine if the record is inactive
152164
let isInactive = false;
153-
if (filterField && filterValue !== null) {
165+
if (filterField) {
154166
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);
158173
}
159174
}
160175

161-
// Set rowClass based on whether the record is inactive.
162176
let rowClass = 'slds-hint-parent';
163177
if (isInactive) {
164178
rowClass += ' inactiveRow';
@@ -203,7 +217,7 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
203217
: [];
204218
return labels.map((label, index, arr) => {
205219
// 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%';
207221
// Padding for the first cell.
208222
if (index === 0) {
209223
style += 'padding-left: 1rem;';
@@ -225,10 +239,14 @@ export default class TagRelatedList extends NavigationMixin(LightningElement) {
225239
let combined = Array.from(new Set([...displayed, ...popover]));
226240

227241
// 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+
}
232250
}
233251
}
234252
return combined;

0 commit comments

Comments
 (0)