From f35ab43411a9bcde0fa1123ee3946a51e4e462b1 Mon Sep 17 00:00:00 2001 From: David Fromstein Date: Tue, 31 Oct 2023 15:52:35 -0500 Subject: [PATCH] Adding objectFieldSelector --- .../fsc_objectFieldSelector.html | 28 +++ .../fsc_objectFieldSelector.js | 189 ++++++++++++++++++ .../fsc_objectFieldSelector.js-meta.xml | 32 +++ .../indicatorBundleItem.js | 2 +- 4 files changed, 250 insertions(+), 1 deletion(-) create mode 100644 force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.html create mode 100644 force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js create mode 100644 force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js-meta.xml diff --git a/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.html b/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.html new file mode 100644 index 0000000..54c3a73 --- /dev/null +++ b/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.html @@ -0,0 +1,28 @@ + \ No newline at end of file diff --git a/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js b/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js new file mode 100644 index 0000000..2b3cf2d --- /dev/null +++ b/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js @@ -0,0 +1,189 @@ +import { LightningElement, api, track } from 'lwc'; +import { FlowAttributeChangeEvent } from 'lightning/flowSupport'; + +import { DISPLAY_TYPE_OPTIONS, AVAILABLE_OBJECT_OPTIONS, FIELD_TYPES, LAYOUT_OPTIONS, transformConstantObject } from 'c/fsc_objectFieldSelectorUtils'; +import { setValuesFromMultipleInput, setValuesFromSingularInput } from 'c/fsc_comboboxUtils'; + +export default class Fsc_objectFieldSelector extends LightningElement { + availableObjectOptions = transformConstantObject(AVAILABLE_OBJECT_OPTIONS); + + @api name; + @api masterLabel; + @api objectLabel = 'Select Object'; + @api fieldLabel = 'Select Field'; + @api valueDelimiter = ','; + + @api disableObjectPicklist = false; + @api hideObjectPicklist = false; + @api hideFieldPicklist = false; + @api objectAllowMultiselect = false; + @api fieldAllowMultiselect = false; + @api required = false; + + @api availableObjectSelection = this.availableObjectOptions.default?.value; + @api availableObjects; + @api availableFieldTypes; + @api availableReferenceTypes; + @api lockDefaultObject; + @api defaultToNameField; + @api layout = LAYOUT_OPTIONS.VERTICAL.value; + + @api + get builderContext() { + return this._builderContext; + } + set builderContext(value) { + console.log('setting builderContext'); + console.log(JSON.stringify(value)); + this._builderContext = value; + } + _builderContext; + + @api + get objectValues() { + return this._objectValues || []; + } + set objectValues(values) { + this._objectValues = setValuesFromMultipleInput(values); + } + @track _objectValues = []; + + @api + get objectValue() { + return this.objectValues.join(this.valueDelimiter); + } + set objectValue(value) { + console.log('in set objectValue'); + console.log(value); + this.objectValues = setValuesFromSingularInput(value, this.valueDelimiter, this.objectAllowMultiselect); + } + + @api + get fieldValues() { + return this._fieldValues || []; + } + set fieldValues(values) { + this._fieldValues = setValuesFromMultipleInput(values); + } + @track _fieldValues = []; + + @api + get fieldValue() { + return this.fieldValues.join(this.valueDelimiter); + } + set fieldValue(value) { + this.fieldValues = setValuesFromSingularInput(value, this.valueDelimiter, this.fieldAllowMultiselect); + } + + + @api + get displayType() { + return this._displayType; + } + set displayType(value) { + this._displayType = value; + if (this.displayType === DISPLAY_TYPE_OPTIONS.FIELD.value) { + this.hideObjectPicklist = true; + } + if (this.displayType === DISPLAY_TYPE_OPTIONS.OBJECT.value) { + this.hideFieldPicklist = true; + } + } + + @api + reportValidity() { + let isValid = true; + if (this.objectSelector) { + isValid = this.objectSelector.reportValidity() && isValid; + } + if (this.fieldSelector) { + isValid = this.fieldSelector.reportValidity() && isValid; + } + return isValid; + } + + @api + validate() { + let errorMessages = [] + const validateComponents = [this.objectSelector, this.fieldSelector]; + validateComponents.forEach(cmp => { + if (cmp?.validate().errorMessage) { + errorMessages.push(cmp.validate().errorMessage) + } + }) + // if (this.objectSelector && this.objectSelector.validate().errorMessage) { + // errorMessages.push(this.objectSelector.validate().errorMessage) + // } + // if (this.fieldSelector && this.fieldSelector.validate().errorMessage) { + // errorMessages.push(this.fieldSelector.validate().errorMessage) + // } + console.log('in ofsValidate, errorMessages = ' + errorMessages); + if (errorMessages.length) { + return { + isValid: false, + errorMessage: errorMessages.join(' ') + }; + } else { + return { isValid: true }; + } + } + + get computedColClass() { + let classString = 'slds-col'; + if (this.displayType === DISPLAY_TYPE_OPTIONS.BOTH.value && this.layout === LAYOUT_OPTIONS.HORIZONTAL.value) { + classString += ' slds-size_1-of-2'; + } else { + classString += ' slds-size_1-of-1'; + } + return classString; + } + + get objectSelector() { + return this.template.querySelector('c-fsc_object-selector'); + } + + get fieldSelector() { + return this.template.querySelector('c-fsc_field-selector2'); + } + + handleObjectChange(event) { + this.objectValue = event.detail.value; + const attributeChangeEvent = new FlowAttributeChangeEvent( + 'objectValue', + this.objectValue + ); + this.dispatchEvent(attributeChangeEvent); + this.dispatchValues(); + } + + handleFieldChange(event) { + this.fieldValue = event.detail.value; + const attributeChangeEvent = new FlowAttributeChangeEvent( + 'fieldValue', + this.fieldValue + ); + this.dispatchEvent(attributeChangeEvent); + this.dispatchValues(); + } + + dispatchValues() { + this.dispatchEvent(new CustomEvent('change', { + detail: { + objectValue: this.objectValue, + objectValues: this.objectValues, + fieldValue: this.fieldValue, + fieldValues: this.fieldValues + } + })); + } + + + connectedCallback() { + // console.log('displayType = ' + this.displayType); + // console.log('objectValue = ' + this.objectValue); + // console.log('availableFieldTypes = ' + this.availableFieldTypes); + // console.log('availableReferenceTypes = ' + this.availableReferenceTypes); + // console.log('hideObjectPicklist = ' + this.hideObjectPicklist); + // console.log('hideFieldPicklist = ' + this.hideFieldPicklist); + } +} \ No newline at end of file diff --git a/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js-meta.xml b/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js-meta.xml new file mode 100644 index 0000000..498f554 --- /dev/null +++ b/force-app/main/default/lwc/fsc_objectFieldSelector/fsc_objectFieldSelector.js-meta.xml @@ -0,0 +1,32 @@ + + + 54.0 + true + Object and Field Selector + + lightning__FlowScreen + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/force-app/main/default/lwc/indicatorBundleItem/indicatorBundleItem.js b/force-app/main/default/lwc/indicatorBundleItem/indicatorBundleItem.js index 4872229..7270149 100644 --- a/force-app/main/default/lwc/indicatorBundleItem/indicatorBundleItem.js +++ b/force-app/main/default/lwc/indicatorBundleItem/indicatorBundleItem.js @@ -6,7 +6,7 @@ export default class IndicatorListItem extends LightningElement { // @api indText = ''; // @api indImage = ''; // @api indIcon = 'standard:all' ; - // @api indHoverText = ''; + @api indHoverText = ''; @api iconSource; @api sourceValue;