Skip to content

Commit

Permalink
Sergey refactoring and Tom change to search to allow multiple criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
tomansley committed Aug 19, 2024
1 parent 85c8bb8 commit 1ddddd4
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 68 deletions.
26 changes: 17 additions & 9 deletions force-app/main/default/classes/ListViewTypeAheadController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ public with sharing class ListViewTypeAheadController {
if (String.isBlank(whereClauseJSON)) {
soql = 'SELECT Id, ' + String.escapeSingleQuotes(labelFieldName) + ', ' + String.escapeSingleQuotes(keyFieldName) + ' FROM ' + String.escapeSingleQuotes(objName) + ' LIMIT 100';
} else {
WhereClause clause = (WhereClause) JSON.deserialize(whereClauseJSON, WhereClause.class);
String whereStatement = clause.getWhereClause();
String whereStatement = createWhereClause(whereClauseJSON);
soql = 'SELECT Id, ' + String.escapeSingleQuotes(labelFieldName) + ', ' + String.escapeSingleQuotes(keyFieldName) + ' FROM ' + String.escapeSingleQuotes(objName) + ' WHERE ' + whereStatement + ' LIMIT 100';
}
}
else {
if (String.isBlank(whereClauseJSON)) {
soql = 'SELECT Id, ' + String.escapeSingleQuotes(labelFieldName) + ', ' + String.escapeSingleQuotes(keyFieldName) + ' FROM ' + String.escapeSingleQuotes(objName) + ' WHERE ' + String.escapeSingleQuotes(labelFieldName) + ' LIKE \'%' + String.escapeSingleQuotes(searchTerm) + '%\' LIMIT 100';
} else {
WhereClause clause = (WhereClause) JSON.deserialize(whereClauseJSON, WhereClause.class);
String whereStatement = clause.getWhereClause();
String whereStatement = createWhereClause(whereClauseJSON);
soql = 'SELECT Id, ' + String.escapeSingleQuotes(labelFieldName) + ', ' + String.escapeSingleQuotes(keyFieldName) + ' FROM ' + String.escapeSingleQuotes(objName) + ' WHERE ' + whereStatement + ' AND ' + String.escapeSingleQuotes(labelFieldName) + ' LIKE \'%' + String.escapeSingleQuotes(searchTerm) + '%\' LIMIT 100';
}
}
Expand All @@ -59,15 +57,14 @@ public with sharing class ListViewTypeAheadController {

if (hasWhereClause)
{
WhereClause clause = (WhereClause) JSON.deserialize(whereClauseJSON, WhereClause.class);
String whereStatement = clause.getWhereClause();
List<WhereClause> clauses = (List<WhereClause>) JSON.deserialize(whereClauseJSON, List<WhereClause>.class);

if (clause.operator == 'NOT IN')
if (clauses[0].operator == 'NOT IN')
isInc = false;
else
isInc = true;

objs = clause.getValuesList();
objs = clauses[0].getValuesList();
}

for (String apiName : objMap.keySet())
Expand All @@ -79,7 +76,7 @@ public with sharing class ListViewTypeAheadController {
String label = objMap.get(apiName);
if (searchTerm == '')
options.add(new ListViewController.SelectOption(apiName, label));
else if (label.toLowerCase().contains(searchTerm))
else if (label.toLowerCase().contains(searchTerm.toLowerCase()))
options.add(new ListViewController.SelectOption(apiName, label));
}

Expand All @@ -106,6 +103,17 @@ public with sharing class ListViewTypeAheadController {
return (String) Database.query(soql)[0].get(String.escapeSingleQuotes(labelFieldName));
}

private static String createWhereClause(String whereClauseJSON)
{
String whereStatement = '';
List<WhereClause> clauses = (List<WhereClause>) JSON.deserialize(whereClauseJSON, List<WhereClause>.class);
for (WhereClause clause: clauses)
whereStatement += clause.getWhereClause() + ' AND ';
whereStatement = whereStatement.removeEnd(' AND ');

return whereStatement;
}

public class WhereClause {

public String field {get; set;}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ public with sharing class ListViewTypeAheadControllerTest {
List<ListViewController.SelectOption> options = ListViewTypeAheadController.search('schema', 'Acc', 'SObject', 'Label', 'Name', null);
System.assert(options.size() > 0);

List<ListViewTypeAheadController.WhereClause> clauses = new List<ListViewTypeAheadController.WhereClause>();
ListViewTypeAheadController.WhereClause whereClause = new ListViewTypeAheadController.WhereClause();
whereClause.field = 'simpli_lv__Object_Name__c';
whereClause.operator = 'NOT IN';
whereClause.values = 'Contact';
clauses.add(whereClause);

options = ListViewTypeAheadController.search('schema', 'Contact', 'SObject', 'Label', 'Name', JSON.serialize(whereClause));
options = ListViewTypeAheadController.search('schema', 'Contact', 'SObject', 'Label', 'Name', JSON.serialize(clauses));

Test.stopTest();
}
Expand All @@ -32,12 +34,14 @@ public with sharing class ListViewTypeAheadControllerTest {
{
Test.startTest();

List<ListViewTypeAheadController.WhereClause> clauses = new List<ListViewTypeAheadController.WhereClause>();
ListViewTypeAheadController.WhereClause whereClause = new ListViewTypeAheadController.WhereClause();
whereClause.field = 'simpli_lv__Object_Name__c';
whereClause.operator = '=';
whereClause.values = 'Account';
clauses.add(whereClause);

List<ListViewController.SelectOption> options = ListViewTypeAheadController.search('sobject', 'Acc', 'simpli_lv__List_View__c', 'simpli_lv__Label__c', 'simpli_lv__API_Name__c', JSON.serialize(whereClause));
List<ListViewController.SelectOption> options = ListViewTypeAheadController.search('sobject', 'Acc', 'simpli_lv__List_View__c', 'simpli_lv__Label__c', 'simpli_lv__API_Name__c', JSON.serialize(clauses));
System.assert(options.size() > 0);

Test.stopTest();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,4 @@ th {

.slds-card__header {
padding-top: 0px;
}
}
60 changes: 30 additions & 30 deletions force-app/main/default/lwc/simpliUIListViews/simpliUIListViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,42 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
//-----------
//API FIELDS
//-----------
@api mode = undefined; //indicates the mode the page is in for displaying the list view. i.e. app, single etc.
@api virtual = false; //indicates whether the list view is displaying data virtually from another org.
@api pageName = ''; //this is NOT the page name but the COMPONENT name
@api uniqueComponentId = ''; //identifies the component uniquely so that messages can be handled in a multi-component page.
@api hasMainTitle = undefined; //indicates whether the component should display the main title
@api mainTitle = 'List Views'; //the main title of the component.
@api includedObjects = ''; //indicates the objects that should be included in the list view
@api excludedObjects = ''; //indicates the objects that should be excluded in the list view.
@api joinFieldName = ''; //if the component uses data coming in from the message channel this field identifies the lookup field to use that data for.
@api useMessageChannel = false; //identifies if the message channel should be used or not. This is used when components should be passing data between each other for updates.
@api allowRefresh = false; //config indicating whether the auto refresh checkbox is made available.
@api singleClickAutoRefresh = undefined; //whether clicking a single or double time starts the auto refresh.
@api allowHorizontalScrolling = false; //config indicating whether horizontal scrolling is available on the list view
@api allowInlineEditing = false; //config indicating whether inline editing is available
@api displayRecordPopovers = false; //config indicating whether record popovers should be displayed
@api allowAdmin = false; //indicates whether the admin button should display to the user
@api mode = undefined;
@api virtual = false;
@api pageName = '';
@api uniqueComponentId = '';
@api hasMainTitle = undefined;
@api mainTitle = 'List Views';
@api includedObjects = '';
@api excludedObjects = '';
@api joinFieldName = '';
@api useMessageChannel = false;
@api allowRefresh = false;
@api singleClickAutoRefresh = undefined;
@api allowHorizontalScrolling = false;
@api allowInlineEditing = false;
@api displayRecordPopovers = false;
@api allowAdmin = false;
@api displayActions = false;
@api typeAheadListSearch = false; //indicates whether a straight combobox or typeahead text will be used when selecting list views
@api typeAheadObjectSearch = false; //indicates whether a straight combobox or typeahead text will be used when selecting objects
@api displayReprocess = false; //indicates whether the reprocessing button should be displayed allowing core list views to be reprocessed
@api typeAheadListSearch = false;
@api typeAheadObjectSearch = false;
@api displayReprocess = false;
@api displayURL = false;
@api displayRowCount = false;
@api noSorting = false; //indicates whether any sorting should be allowed on the listview
@api useSimpleSorting = false; //indicates whether standard sorting should be used.
@api noSorting = false;
@api useSimpleSorting = false;
@api displaySelectedCount = false;
@api displayOrigButton; //this is not used....deprecated.
@api displayOrigButton;
@api displayModified = false;
@api displayExportButton = false;
@api displayTextSearch = false; //identifies whether the text search field should be displayed.
@api singleListViewObject = ''; //if in SINGLE mode holds the list view object to use.
@api singleListViewApiName = ''; //if in SINGLE mode holds the list view API name to use.
@api excludedRecordPopoverTypes = ''; //Indicates those object types for which record detail popovers should not be displayed when the user moves the mouse over the record URL or name.
@api displayAllRelatedRecords = false; //Related List View Mode Only: Indicates whether all records should be displayed or scrolling should be used.
@api objectList = undefined; //holds the list of objects from which a user can choose one.
@api listViewList = undefined; //holds the set of list views for the chosen object
@api set actionList(value) //if in STANDALONE or VIRTUAL mode used when passing actions directly into the component
@api displayTextSearch = false;
@api singleListViewObject = '';
@api singleListViewApiName = '';
@api excludedRecordPopoverTypes = '';
@api displayAllRelatedRecords = false;
@api objectList = undefined;
@api listViewList = undefined;
@api set actionList(value)
{
this.objectActionList = value;
if (this.objectActionList !== undefined && this.objectActionList !== '')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

.pageSpinnerHolder {
position: absolute;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

.pageSpinnerHolder {
position: relative;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
margin-right: 2%;
margin-top: 20px;
margin-bottom: 20px;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

.pageSpinnerHolder {
position: relative;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import Column_Styles from '@salesforce/label/c.Column_Styles';
import Font from '@salesforce/label/c.Font';
import Decoration from '@salesforce/label/c.Decoration';
import Style from '@salesforce/label/c.Style';
import constiant from '@salesforce/label/c.constiant';
// import constiant from '@salesforce/label/c.constiant';
import Transform from '@salesforce/label/c.Transform';
import Weight from '@salesforce/label/c.Weight';
import Alignment from '@salesforce/label/c.Alignment';
Expand Down Expand Up @@ -204,7 +204,7 @@ export default class simpliUIListViewsAdminModal extends NavigationMixin(Lightni
label = {
Close, List_View_Config, Settings, Parameter_Name, Value, Select_A_Value, Highlighting, Add_Remove, Field,
Operator, Precedence, Color, Field_Name, Remove_Condition, Select_A_Column, Enter_A_Value, Add_Condition,
Update, Column_Styles, Font, Decoration, Style, constiant, Transform, Weight, Alignment
Update, Column_Styles, Font, Decoration, Style, Transform, Weight, Alignment
}

constructor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
font-size: 16px;
margin: 4px 2px;
cursor: pointer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ export function showErrorMessage({ message, body }) {
errorMessage = body.message;
}
}
console.log("Error", errorMessage);
console.error("Error", errorMessage);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
position: absolute;
left: 0rem;
top: -1.3rem;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.pageSpinnerHolder {
position: absolute;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ lightning-radio-group .slds-radio_faux {

.slds-modal__content {
overflow: initial;
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.pageSpinnerHolder {
position: absolute;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
font-weight: bold;
top: calc(50% + 1rem);
color: grey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
.splitboxright {
border-top: 1px solid lightgray;
border-right: 1px solid lightgray;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ lightning-radio-group .slds-radio_faux {

.slds-modal__content {
overflow: initial;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ export default class SimpliUIListViewsTypeAhead extends LightningElement {
return this._fieldObjName;
}

_whereClause; //any additional criteria (in SOQL format without WHERE keyword) to be applied when displaying values
@api set whereClause(value) {
if (value !== this._whereClause) {
_whereClause = []; //any additional criteria (in SOQL format without WHERE keyword) to be applied when displaying values
@api set whereClause(value)
{
this.searchTerm = '';
this.oldSearchTerm = '';
}
this._whereClause = value;
this.search();
}
this._whereClause = [];
if (!SLVHelper.isEmpty(value)) {
this._whereClause.push(value);
}
this.search();
}
get whereClause() {
return this._whereClause;
}
Expand Down Expand Up @@ -152,7 +154,7 @@ export default class SimpliUIListViewsTypeAhead extends LightningElement {
this.isInitialized = true;
})
.catch(error => {
console.log('Error Detected - ' + error.body.message + ' | ' + error.body.stackTrace);
SLVHelper.showErrorMessage(error);
});
this.isInitialized = true;
}
Expand All @@ -166,15 +168,15 @@ export default class SimpliUIListViewsTypeAhead extends LightningElement {
}

search() {

console.log("searchTerm1", this.searchTerm);
if ((this.searchType === 'sobject' && this.whereClause !== undefined && this.labelFieldName !== undefined && this.keyFieldName !== undefined && this.fieldObjName !== undefined)
||
(this.searchType === 'schema' && this.fieldObjName !== undefined)
&&
this.searchTerm.length > 1) {
let whereClauseStr = JSON.stringify(this.whereClause);

console.log('Performing search - ' + this.searchType + ', ' + this.searchTerm + ', ' + this.fieldObjName + ', ' + this.labelFieldName + ', ' + this.keyFieldName + ', ' + this.whereClause)
console.log('Performing search - ' + this.searchType + ', ' + this.searchTerm + ', ' + this.fieldObjName + ', ' + this.labelFieldName + ', ' + this.keyFieldName + ', ' + this.whereClauseStr)

search({ searchType: this.searchType, searchTerm: this.searchTerm, objName: this.fieldObjName, labelFieldName: this.labelFieldName, keyFieldName: this.keyFieldName, whereClauseJSON: whereClauseStr })
.then(result => {
Expand All @@ -187,7 +189,7 @@ export default class SimpliUIListViewsTypeAhead extends LightningElement {
this.options = undefined;
})
.catch(error => {
console.log('Error Detected - ' + error.message + ' | ' + error.stackTrace);
SLVHelper.showErrorMessage(error);
});

} else if (this.searchType === 'schema' && this.fieldObjName !== undefined) {
Expand Down Expand Up @@ -221,6 +223,7 @@ export default class SimpliUIListViewsTypeAhead extends LightningElement {

if (this.searchTerm === '')
this.searchTerm = this.oldSearchTerm;

// eslint-disable-next-line @lwc/lwc/no-async-operation
this.blurTimeout = setTimeout(() => { this.boxClass = 'slds-combobox slds-dropdown-trigger slds-dropdown-trigger_click slds-has-focus' }, 300);
}
Expand Down

0 comments on commit 1ddddd4

Please sign in to comment.