I have a custom LWC component where I build up a Path in order to display the full picklist value name instead of just a tick when the stage is completed. This all works nicely. The original @wire without the condition is this
import { LightningElement, wire, api } from "lwc";
import { getObjectInfo } from "lightning/uiObjectInfoApi";
import { getPicklistValues } from "lightning/uiObjectInfoApi";
import MY_OBJECT from "@salesforce/schema/My_Object__c";
import MY_OBJECT_STATUS from "@salesforce/schema/My_Object__c.Status__c";
import MY_OBJECT_ACCEPTANCE from "@salesforce/schema/My_Object__c.Parent__r.Acceptance__c";
export default class MyObjectPath extends LightningElement {
@api objectApiName;
@api recordId;
stageOptions;
status = MY_OBJECT_STATUS;
acceptance = MY_OBJECT_ACCEPTANCE;
currentStep = "slds-path__item slds-is-current";
completeStep = "slds-path__item slds-is-active";
incompleteStep = "slds-path__item slds-is-incomplete";
@wire(getObjectInfo, { objectApiName: MY_OBJECT })
myObject;
@wire(getPicklistValues, {
recordTypeId: "$myObject.data.defaultRecordTypeId",
fieldApiName: MY_OBJECT_STATUS
})
picklistValues({ data }) {
if (data) {
let increment = 1;
this.stageOptions = data.values.map((item) => {
return {
position: increment++,
value: item.value,
pathStatus: this.incompleteStep,
tickIcon: false
};
});
}
}
Except I now have a requirement to exclude certain stages based on a condition. The code below is what I tried but I get an error in the js
Array.prototype.map() expects a value to be returned at the end of arrow function.
and if I ignore it the component fails so this is not a solution.
import { LightningElement, wire, api } from "lwc";
import { getObjectInfo } from "lightning/uiObjectInfoApi";
import { getPicklistValues } from "lightning/uiObjectInfoApi";
import MY_OBJECT from "@salesforce/schema/My_Object__c";
import MY_OBJECT_STATUS from "@salesforce/schema/My_Object__c.Status__c";
import MY_OBJECT_ACCEPTANCE from "@salesforce/schema/My_Object__c.Parent__r.Acceptance__c";
export default class RegistryTransferPath extends LightningElement {
@api objectApiName;
@api recordId;
stageOptions;
status = MY_OBJECT_STATUS;
acceptance = MY_OBJECT_ACCEPTANCE;
currentStep = "slds-path__item slds-is-current";
completeStep = "slds-path__item slds-is-active";
incompleteStep = "slds-path__item slds-is-incomplete";
@wire(getObjectInfo, { objectApiName: MY_OBJECT })
registryTransfer;
@wire(getPicklistValues, {
recordTypeId: "$myObject.data.defaultRecordTypeId",
fieldApiName: MY_OBJECT_STATUS
})
picklistValues({ data }) {
if (data) {
let increment = 1;
this.stageOptions = data.values.map((item) => {
if (
item.value === "Awaiting Approval" ||
item.value === "Contract Acceptance"
) {
if (this.acceptance === "Enabled") {
return {
position: increment++,
value: item.value,
pathStatus: this.incompleteStep,
tickIcon: false
};
}
} else {
return {
position: increment++,
value: item.value,
pathStatus: this.incompleteStep,
tickIcon: false
};
}
});
}
}
I've tried finding a way to do this but am stuck. How would I exclude the 2 options if my condition is met?