Skip to content

Commit

Permalink
Merge 69ffab9 into feature/remove-data-com-lwc
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Oct 10, 2024
2 parents 0ad8813 + 69ffab9 commit 001a302
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
2 changes: 1 addition & 1 deletion force-app/main/default/lwc/illustration/illustration.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="slds-text-longform">
<h3 class="slds-text-heading_medium">{heading}</h3>
<slot name="messageBody">
<p class="slds-text-body_regular">{messageBody}</p>
<p class="slds-text-body_regular slds-p-around_xx-small">{messageBody}</p>
</slot>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ <h3 slot="title" class="slds-truncate slds-p-around_xx-small">
</div>
</div>
</div>
<template lwc:if={displayFooter}>
<footer class="slds-card__footer">
<lightning-badge label={mappedField}></lightning-badge>
<lightning-helptext content={targetMessage}></lightning-helptext>
</footer>
</template>
</article>
</template>
</template>
Expand Down
60 changes: 55 additions & 5 deletions force-app/main/default/lwc/indicatorBundle/indicatorBundle.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LightningElement, api, wire } from 'lwc';
import { LightningElement, api, wire, track } from 'lwc';
import { getRecord, getFieldValue } from 'lightning/uiRecordApi';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import { refreshApex } from '@salesforce/apex';
import KeyModal from 'c/indicatorBundleKey';

Expand All @@ -18,6 +19,13 @@ export default class IndicatorBundle extends LightningElement {
@api indsSize = 'large';
@api indsShape = 'base';
@api showRefresh = false;
@api mappedField = ''; // API Field Name for the record
@api showFooter = false;

targetIdField; // Syntax of template field: sObject.Field_Name__c
targetIdValue;
targetMessage;

bundleActive = true; // Set default active status
hasHeader = false; // Hide header by default

Expand All @@ -35,9 +43,16 @@ export default class IndicatorBundle extends LightningElement {
errorOccurred = false;
errorMessage = '';
showIllustration = false;
illustration = {};
@track illustration = {};

connectedCallback(){
if(this.mappedField == null || this.mappedField.trim() == ""){
this.targetIdValue = this.recordId;
} else {
this.targetIdField = this.objectApiName + '.' + this.mappedField;
console.log(this.targetIdField);
}

if(!this.bundleName){
this.errorOccurred = true;
this.showIllustration = true;
Expand All @@ -48,7 +63,37 @@ export default class IndicatorBundle extends LightningElement {
}
} else {
this.showIllustration=false;
this.illustration = {};
// this.illustration = {};
}
}

// Check the record for an existing field value in order to initialize it.
@wire(getRecord, { recordId: '$recordId', fields: '', optionalFields: '$targetIdField' })
record ({error, data}) {
if(error) {
console.log('ERROR');
this.errorOccurred = true;
this.showIllustration = true;
this.illustration = {
heading : 'Errors Using the Mapped Field',
messageBody: 'Check the API Name for the custom field API name: ' + this.mappedField,
imageName: 'custom:setup'
}
} else if (data) {
if( JSON.stringify(data.fields) === '{}' ) {
this.errorOccurred = true;
this.showIllustration = true;
this.illustration = {
heading : 'Problem Using Mapped Field',
messageBody: 'Check the case-sensitive API Name for the mapped field API name: ' + this.mappedField,
imageName: 'custom:setup'
};
} else {
this.targetMessage = 'This Indicator Bundle displays indicators based on the record id (' + data.fields[this.mappedField].value + ') in the mapped field \"' + this.mappedField + '\" from the ' + data.apiName + ' object.';
this.targetIdValue = getFieldValue(data, this.targetIdField);
this.showIllustration=false;
this.illustration = {};
}
}
}

Expand All @@ -62,6 +107,10 @@ export default class IndicatorBundle extends LightningElement {
return this.titleStyle == 'Lightning Card';
}

get displayFooter() {
return this.showFooter && (this.mappedField != null && this.mappedField.trim() != "");
}

initCSSVariables() {

if(this.showTitle && this.isStandardUsage && (this.bundle.CardIconBackground || this.bundle.CardIconForeground)) {
Expand Down Expand Up @@ -169,9 +218,10 @@ export default class IndicatorBundle extends LightningElement {
refreshApex(this.wiredData);
}

// Get the field values for the current record based on the configured fields in CMDT
// Get the field values for the target record based on the configured fields in CMDT
// Using 'optionalFields' ensures that if a user does not have access to a field, the indicator will not show.
@wire(getRecord, { recordId: '$recordId', optionalFields: '$apiFieldnameDefinitions' })
// TODO: Add fields parameter to retrieve the record name for use when the targetIdValue is for another record.
@wire(getRecord, { recordId: '$targetIdValue', optionalFields: '$apiFieldnameDefinitions' })
wiredRecord(result) {

const {error,data} = result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
<targetConfigs>
<targetConfig targets="lightning__RecordPage">
<property name="bundleName" type="String" label="Indicator Bundle" datasource="apex://IndicatorListBundleSelector" description="Choose the Indicator Bundle."/>
<property name="titleStyle" type="String" label="Title Style" placeholder="Lightning Card" datasource="Lightning Card,Dynamic Forms" description="Choose the Title Style: Standard Lightning Card or a style to match Dynamic Forms"/>
<property name="titleStyle" type="String" label="Title Style" placeholder="Lightning Card" datasource="Lightning Card,Dynamic Forms" description="Choose the Title Style: Standard Lightning Card or a style to match Dynamic Forms."/>
<property name="showTitle" type="Boolean" default="true" label="Display Title" description="Display the Indicator's Title on the component."/>
<property name="showDescription" type="Boolean" default="true" label="Display Description" description="Display the Indicator's Description on the component."/>
<property name="indsSize" type="String" label="Indicator Size" placeholder="large" datasource="large,medium" description="Choose the Indicator Size."/>
<property name="indsShape" type="String" label="Indicator Shape" placeholder="base" datasource="base,circle" description="Choose the Indicator Shape."/>
<property name="showRefresh" type="Boolean" label="Show refresh button" description="Enable an admin button to refresh the values."/>
<property name="mappedField" type="String" label="(Optional) Mapped Id Field" description="(Optional) Instead of using the current Record Id, provide the API Name of a field (Case Sensitive) on this object which holds a Record Id or Relationship Id to use that value." placeholder="Example: Source_Id__c, ParentId, or AccountId" />
<property name="showFooter" type="Boolean" label="Show footer when using Mapped Id Field" description="Enable a footer to show what mapped field is being used."/>
<supportedFormFactors>
<supportedFormFactor type="Large" />
<supportedFormFactor type="Small" />
Expand Down

0 comments on commit 001a302

Please sign in to comment.