Skip to content

Commit

Permalink
Starting point for Sprint Sept 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
fromsteinsfdc committed Sep 26, 2024
1 parent 7632d03 commit 93db19a
Show file tree
Hide file tree
Showing 15 changed files with 506 additions and 643 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ public with sharing class ObjectFieldSelectorController {
@AuraEnabled public String apiName;
@AuraEnabled public String label;
@AuraEnabled public String dataType;
@AuraEnabled public boolean nameField;
@AuraEnabled public List<ReferenceToInfo> referenceToInfos;

public FieldResult(Schema.DescribeFieldResult fieldResult) {
this.apiName = fieldResult.getName();
this.label = fieldResult.getLabel();
this.dataType = fieldResult.getType().name();
this.nameField = fieldResult.isNameField();
List<ReferenceToInfo> refToInfos = new List<ReferenceToInfo>();
for (Schema.sObjectType objType : fieldResult.getReferenceTo()) {
refToInfos.add(new ReferenceToInfo(objType.getDescribe().getName()));
Expand All @@ -111,4 +113,4 @@ public with sharing class ObjectFieldSelectorController {
this.apiName = apiName;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ public class ObjectFieldSelectorControllerTest {
System.assert(String.isBlank(result4.errorMessage));
System.assert(!String.isBlank(result5.errorMessage));
}
}
}
2 changes: 1 addition & 1 deletion force-app/main/default/lwc/fsc_combobox/fsc_combobox.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
{computedLabel}
<template if:true={fieldLevelHelp}>
<lightning-helptext content={fieldLevelHelp}
class="slds-p-left_xx-small"></lightning-helptext>
class="slds-m-left_xx-small"></lightning-helptext>
</template>
</p>
</template>
Expand Down
49 changes: 38 additions & 11 deletions force-app/main/default/lwc/fsc_combobox/fsc_combobox.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Style from: https://www.lightningdesignsystem.com/components/combobox
import { LightningElement, api, track } from 'lwc';
import { KEYS, setValuesFromMultipleInput, setValuesFromSingularInput, includesIgnoreCase } from 'c/fsc_comboboxUtils';
import { KEYS, setValuesFromMultipleInput, setValuesFromSingularInput, includesIgnoreCase, CLEAR_REQUEST_EVENT_NAME } from 'c/fsc_comboboxUtils';

const VARIANTS = {
BASE: 'base',
Expand Down Expand Up @@ -37,6 +37,7 @@ export default class OptionSelector extends LightningElement {
@api includeValueInFilter = false; // If true, the 'value' text of an option is included when determining if an option is a match for a given search text.
@api filterActions = false; // If true, action items will be filtered along with selection items. By default, action items are always visible
@api showSelectedCount = false; // If true, when allowMultiselect is true, the component label will show the number of selected values in parentheses
@api notifyOnClear = false; // If true, clicking the clear button will not automatically clear the selection. Instead it will dispatch a notification event so that the parent component can implement any logic before clearing
@api hideSelectedValues = false; // Reserved for future use

@api builderContext;
Expand Down Expand Up @@ -175,7 +176,7 @@ export default class OptionSelector extends LightningElement {
/* PUBLIC FUNCTIONS */
@api
reportValidity() {
if (!this.required || this.selectedOptions.length) {
if (!this.required || this.selectedOptions.length) {
this.setCustomValidity();
} else {
this.setCustomValidity(this.messageWhenValueMissing);
Expand All @@ -200,6 +201,11 @@ export default class OptionSelector extends LightningElement {
this.errorMessage = errorMessage;
}

@api
focus() {
this.onRender.inputFocus = true;
}

/* LIFECYCLE HOOKS */
connectedCallback() {
window.addEventListener("resize", () => { this.resizePillContainer() });
Expand Down Expand Up @@ -254,7 +260,8 @@ export default class OptionSelector extends LightningElement {
}

get isInputDisabled() {
return this.disabled || this.isLoading;
// 5/6/2024: Removing isLoading as a disabling factor because it was interfering with the lookup component
return this.disabled;// || this.isLoading;
}

get noMatchFound() {
Expand All @@ -278,7 +285,7 @@ export default class OptionSelector extends LightningElement {
}

get showLabel() {
return this.variant !== VARIANTS.LABEL_HIDDEN;
return this.label && this.variant !== VARIANTS.LABEL_HIDDEN;
}

/* COMPUTED CSS CLASS STRINGS */
Expand Down Expand Up @@ -316,8 +323,9 @@ export default class OptionSelector extends LightningElement {
this.showList = false;
this.highlightedOptionIndex = undefined;
this.numOptionsDisplayed = LOAD_COUNT;
if (this.listboxElement)
if (this.listboxElement) {
this.listboxElement.scrollTop = 0;
}
}

resetSearch() {
Expand Down Expand Up @@ -363,12 +371,12 @@ export default class OptionSelector extends LightningElement {
// console.log('selecting '+ JSON.stringify(selectedOption));
// console.log('value before adding: '+ this.value);
// console.log('values before adding: '+ JSON.stringify(this.values) +', length: '+ this.values.length);
if (!selectedOption) {
if (!selectedOption || selectedOption.isGrouping) {
return;
}
if (selectedOption.isAction) {
this.dispatchEvent(new CustomEvent('customaction', { detail: selectedOption.value }));
} else {
} else {
this.values.push(selectedOption.value);
this.values = this.values;
// this.values = [...this.values, selectedOption.value]; // using spread instead of values.push to trigger the setter
Expand Down Expand Up @@ -414,6 +422,13 @@ export default class OptionSelector extends LightningElement {
}
}

@api
clearSelection() {
this.values = [];
this.dispatchOptions();
this.openList();
}

highlightOption(index) {
this.highlightedOptionIndex = index;
this.onRender.highlightOption = true;
Expand Down Expand Up @@ -515,11 +530,23 @@ export default class OptionSelector extends LightningElement {
this.highlightedOptionIndex = undefined;
}

handleClearClick() {
handleClearClick(event) {
// I don't know why, but without the preventDefault/stopPropagation, clicking this button sometimes passed URL parameters to the page with refreshed the page
event.preventDefault();
event.stopPropagation();
if (!this.disabled) {
this.values = [];
this.dispatchOptions();
this.openList();
if (this.notifyOnClear) {
this.dispatchEvent(new CustomEvent(CLEAR_REQUEST_EVENT_NAME));
/*
this.dispatchEvent(new CustomEvent(
'clearrequest',
// { bubbles: true, }
{ bubbles: true, composed: true }
));
*/
} else {
this.clearSelection();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const KEYS = {
ENTER: 'Enter'
}

const CLEAR_REQUEST_EVENT_NAME = 'clearrequest';

const setValuesFromMultipleInput = (values) => {
if (!values) {
return [];
Expand All @@ -27,7 +29,6 @@ const includesIgnoreCase = (valueToSearch, valueToSearchFor) => {
} else {
return valueToSearch.toLowerCase().includes(valueToSearchFor.toLowerCase());
}

}

export { KEYS, setValuesFromMultipleInput, setValuesFromSingularInput, includesIgnoreCase }
export { KEYS, setValuesFromMultipleInput, setValuesFromSingularInput, includesIgnoreCase, CLEAR_REQUEST_EVENT_NAME }
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@
field-level-help={fieldLevelHelp}
error-message={errorMessage}
builder-context={builderContext}
notify-on-clear={notifyOnClear}
onclearrequest={handleClearRequest}
></c-fsc_combobox>
</template>
72 changes: 33 additions & 39 deletions force-app/main/default/lwc/fsc_fieldSelector2/fsc_fieldSelector2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ import { LightningElement, api, track, wire } from 'lwc';
import { getObjectInfo } from 'lightning/uiObjectInfoApi';
import getObjectFields from '@salesforce/apex/ObjectFieldSelectorController.getObjectFields';
import { DISPLAY_TYPE_OPTIONS, AVAILABLE_OBJECT_OPTIONS, FIELD_TYPES, LAYOUT_OPTIONS, transformConstantObject } from 'c/fsc_objectFieldSelectorUtils';
import { setValuesFromMultipleInput, setValuesFromSingularInput, includesIgnoreCase } from 'c/fsc_comboboxUtils';
import { setValuesFromMultipleInput, setValuesFromSingularInput, includesIgnoreCase, CLEAR_REQUEST_EVENT_NAME } from 'c/fsc_comboboxUtils';

const COMBOBOX_COMPONENT_NAME = 'c-fsc_combobox';

const DATA_TYPE_ICONS = {
Address: 'utility:location',
Expand Down Expand Up @@ -45,11 +47,9 @@ export default class Fsc_fieldSelector2 extends LightningElement {
@api hidePills = false; // If true, list of selected pills in multiselect mode will not be displayed (generally because a parent component wants to display them differently).
@api excludeSublabelInFilter = false; // If true, the 'sublabel' text of an option is not included when determining if an option is a match for a given search text.
@api includeValueInFilter = false; // If true, the 'value' text of an option is included when determining if an option is a match for a given search text.
<<<<<<< HEAD
@api allowReferenceLookups = false;
=======
@api allowReferenceLookups = false;
>>>>>>> 73e5f784ff3ef05a4d7d8281abdb8191f0999bef
@api defaultToNameField = false;
@api notifyOnClear = false;
@track fields = [];
@track _values = [];
@track _availableFieldTypes = [];
Expand Down Expand Up @@ -122,13 +122,17 @@ export default class Fsc_fieldSelector2 extends LightningElement {

@api
reportValidity() {
return this.template.querySelector('c-fsc_combobox').reportValidity();
return this.combobox.reportValidity();
}

@api
validate() {
// console.log('in fieldSelector validate, returning '+ JSON.stringify(this.template.querySelector('c-fsc_combobox').validate()));
return this.template.querySelector('c-fsc_combobox').validate();
return this.combobox.validate();
}

@api
clearSelection() {
this.combobox.clearSelection();
}

get isLoadingOrDisabled() {
Expand All @@ -145,6 +149,10 @@ export default class Fsc_fieldSelector2 extends LightningElement {
}
}

get combobox() {
return this.template.querySelector(COMBOBOX_COMPONENT_NAME);
}

@wire(getObjectInfo, { objectApiName: '$objectName' })
handleGetObjectInfo({ error, data }) {
if (error) {
Expand All @@ -160,10 +168,10 @@ export default class Fsc_fieldSelector2 extends LightningElement {
}
}
} else if (data) {
console.log(JSON.stringify(Object.values(data.fields).filter(field => field.relationshipName)[0]));
// console.log(JSON.stringify(Object.values(data.fields).filter(field => field.relationshipName)[0]));
this.processFields(Object.values(data.fields));
} else {
console.log('neither data nor error');
// console.log('neither data nor error');
}
this.isLoading = false;
}
Expand Down Expand Up @@ -195,6 +203,10 @@ export default class Fsc_fieldSelector2 extends LightningElement {
this.dispatchFields();
}

handleClearRequest() {
this.dispatchEvent(new CustomEvent(CLEAR_REQUEST_EVENT_NAME));
}

/* ACTION FUNCTIONS */
processFields(fields) {
if (this.availableFieldTypes?.length) {
Expand All @@ -203,14 +215,18 @@ export default class Fsc_fieldSelector2 extends LightningElement {
fields = fields.filter(field => !field.referenceToInfos.length || field.referenceToInfos.some(ref => includesIgnoreCase(this.availableReferenceTypes, ref.apiName)));
}
}
<<<<<<< HEAD
this.fields = fields.map(field => this.newField(field.label, field.apiName, field.apiName, field.dataType, this.hideIcons ? null : this.getIconFromDataType(field.dataType)));
=======
this.fields = fields.map(field => this.newField(field.label, field.apiName, field.apiName, this.hideIcons ? null : this.getIconFromDataType(field.dataType)));
>>>>>>> 73e5f784ff3ef05a4d7d8281abdb8191f0999bef
this.fields = fields.map(field => this.newField(field.label, field.apiName, field.apiName, this.hideIcons ? null : this.getIconFromDataType(field.dataType), field.nameField));
this.fields.sort((a, b) => {
return a.label.toLowerCase() > b.label.toLowerCase() ? 1 : -1;
});
if (this.defaultToNameField && !this.value) {
// First check to see if "Name" is a valid name field, as some objects like Contact have multiple name fields
let nameField = this.fields.find(field => field.value === 'Name' && field.nameField) || this.fields.find(field => field.nameField);
if (nameField) {
this.value = nameField.value;
this.dispatchFields();
}
}

}

Expand All @@ -224,42 +240,20 @@ export default class Fsc_fieldSelector2 extends LightningElement {
}

dispatchFields() {
<<<<<<< HEAD
let fieldData;
if (this.values.length) {
fieldData = this.fields.filter(field => this.values.includes(field.value));
// {
// return this.values.find(value => field.apiName == value)
// });
}
let detail = {
value: this.value,
values: this.values,
fieldData: fieldData
}
this.dispatchEvent(new CustomEvent('change', { detail }));
}
=======
let detail = {
value: this.value,
values: this.values,
}
this.dispatchEvent(new CustomEvent('change', { detail }));
}
>>>>>>> 73e5f784ff3ef05a4d7d8281abdb8191f0999bef

/* UTILITY FUNCTIONS */
getIconFromDataType(type) {
let matchingType = this.fieldTypes.options.find(fieldType => includesIgnoreCase(fieldType.value.split(this.fieldTypeDelimiter), type));
return matchingType?.icon || DEFAULT_ICON;
}

<<<<<<< HEAD
newField(label, sublabel, value, dataType, icon) {
return { label, sublabel, value, dataType, icon }
=======
newField(label, sublabel, value, icon) {
return { label, sublabel, value, icon }
>>>>>>> 73e5f784ff3ef05a4d7d8281abdb8191f0999bef
newField(label, sublabel, value, icon, nameField) {
return { label, sublabel, value, icon, nameField };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@
<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}>
available-objects={availableObjects} disabled={objectPicklistIsDisabled}
onchange={handleObjectChange} value={objectValue} builder-context={builderContext} notify-on-clear
onclearrequest={handleObjectClearRequest}>
</c-fsc_object-selector>
</template>
</div>
Expand All @@ -19,12 +20,9 @@
<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}
<<<<<<< HEAD
builder-context={builderContext} allow-reference-lookups={allowReferenceLookups}>
=======
builder-context={builderContext}>
>>>>>>> 73e5f784ff3ef05a4d7d8281abdb8191f0999bef
default-to-name-field={defaultToNameField} disabled={fieldPicklistIsDisabled}
onchange={handleFieldChange} value={fieldValue} builder-context={builderContext} notify-on-clear
onclearrequest={handleFieldClearRequest}>
</c-fsc_field-selector2>
</template>
</div>
Expand Down
Loading

0 comments on commit 93db19a

Please sign in to comment.