Skip to content

Commit

Permalink
Adding objectFieldSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
fromsteinsfdc committed Oct 31, 2023
1 parent 5321bfb commit f35ab43
Show file tree
Hide file tree
Showing 4 changed files with 250 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<template>
<div class="slds-grid slds-wrap slds-gutters">
<template if:true={masterLabel}>
<div class="slds-col slds-size_1-of-1">
<legend class="slds-form-element__legend slds-form-element__label">{masterLabel}</legend>
</div>
</template>
<div class={computedColClass}>
<template if:false={hideObjectPicklist}>
<c-fsc_object-selector name="objectSelector" allow-multiselect={objectAllowMultiselect}
label={objectLabel} required={required} available-object-selection={availableObjectSelection}
available-objects={availableObjects} disabled={lockDefaultObject} onchange={handleObjectChange}
value={objectValue} builder-context={builderContext}>
</c-fsc_object-selector>
</template>
</div>
<div class={computedColClass}>
<template if:false={hideFieldPicklist}>
<c-fsc_field-selector2 name="fieldSelector" label={fieldLabel} required={required}
allow-multiselect={fieldAllowMultiselect} object-name={objectValue}
available-field-types={availableFieldTypes} available-reference-types={availableReferenceTypes}
default-to-name-field={defaultToNameField} onchange={handleFieldChange} value={fieldValue}
builder-context={builderContext}>
</c-fsc_field-selector2>
</template>
</div>
</div>
</template>
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>54.0</apiVersion>
<isExposed>true</isExposed>
<masterLabel>Object and Field Selector</masterLabel>
<targets>
<target>lightning__FlowScreen</target>
</targets>
<targetConfigs>
<!-- <targetConfig targets="lightning__FlowScreen" configurationEditor="c-fsc_object-field-selector-cpe"> -->
<targetConfig targets="lightning__FlowScreen">
<property name="masterLabel" label="Component Label" type="String" />
<property name="objectLabel" label="Object Label" type="String" />
<property name="fieldLabel" label="Field Label" type="String" />
<property name="required" label="Required" type="String" />
<property name="availableObjectSelection" label="Available Object Selection" type="String" />
<property name="availableObjects" label="Available Object Selection" type="String" />
<property name="lockDefaultObject" label="Lock Default Object" type="String" />
<property name="displayType" label="Display Type" type="String" />
<property name="fieldAllowMultiselect" label="Field Multiselect" type="String" />
<property name="objectAllowMultiselect" label="Object Multiselect" type="String" />
<property name="availableFieldTypes" label="Allowed Field Types" type="String" />
<property name="availableReferenceTypes" label="Allowed Reference Types" type="String" />
<property name="layout" label="Layout Style" type="String" />
<property name="objectValue" label="Selected Object (string)" type="String" />
<property name="fieldValue" label="Selected Field (string)" type="String" />
<property name="objectValues" label="Selected Objects" type="String[]" />
<property name="fieldValues" label="Selected Fields" type="String[]" />
<!-- <property name="masterLabel" label="Component Label" type="String" /> -->
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f35ab43

Please sign in to comment.