Skip to content

Commit

Permalink
Enhancement - immediate autorefresh
Browse files Browse the repository at this point in the history
  • Loading branch information
tomansley committed Sep 17, 2024
1 parent 3537d65 commit 77d2510
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @description :
* @author : [email protected]
* @last modified on : 08-07-2024
* @last modified on : 09-17-2024
* @last modified by : [email protected]
* Modifications Log
* Ver Date Author Modification
Expand Down Expand Up @@ -301,7 +301,7 @@ global class ListViewAdminControllerTest {

System.assertEquals('All', config.getObject());
System.assertEquals('All', config.getName());
System.assertEquals(29, config.getParameters().size());
System.assertEquals(30, config.getParameters().size());

ListViewAbstract.ListViewParam param = config.getParameters()[0];
System.assertNotEquals(param.getReadOnly(), null);
Expand Down
6 changes: 3 additions & 3 deletions force-app/main/default/classes/ListViewControllerTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @description :
* @author : [email protected]
* @group :
* @last modified on : 09-16-2024
* @last modified on : 09-17-2024
* @last modified by : [email protected]
* Modifications Log
* Ver Date Author Modification
Expand Down Expand Up @@ -66,7 +66,7 @@ global class ListViewControllerTest {

Map<String, String> configs = ListViewController.getComponentConfig('CompName 1');

System.assertEquals(30, configs.size());
System.assertEquals(31, configs.size());
System.assertEquals('Account:simpli_lv__AllAccounts', configs.get('pinnedListView'));

//update user config
Expand All @@ -75,7 +75,7 @@ global class ListViewControllerTest {

configs = ListViewController.getComponentConfig('CompName 1');

System.assertEquals(30, configs.size());
System.assertEquals(31, configs.size());
System.assertEquals('Contact:simpli_lv__AllContacts', configs.get('pinnedListView'));


Expand Down
10 changes: 9 additions & 1 deletion force-app/main/default/classes/ListViewHelper.cls
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* @author : [email protected]
* @last modified on : 08-14-2024
* @last modified on : 09-17-2024
* @last modified by : [email protected]
* Modifications Log
* Ver Date Author Modification
Expand Down Expand Up @@ -2333,6 +2333,14 @@ global with sharing class ListViewHelper
param.Parameter_Label__c = 'Display Row Count';
params.add(param);

param = new List_View_Config_Parameter__c();
param.List_View_Config__c = config.Id;
param.Parameter_Name__c = 'AllowImmediateRefresh';
param.Parameter_Type__c = ListViewHelper.TYPE_BOOLEAN;
param.Parameter_Value__c = ListViewHelper.FFALSE;
param.Parameter_Label__c = 'Allow Immediate Refresh';
params.add(param);

param = new List_View_Config_Parameter__c();
param.List_View_Config__c = config.Id;
param.Parameter_Name__c = 'MaxRowsDisplayed';
Expand Down
23 changes: 22 additions & 1 deletion force-app/main/default/classes/ScriptInstall.cls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* @description :
* @author : [email protected]
* @last modified on : 08-01-2024
* @last modified on : 09-17-2024
* @last modified by : [email protected]
* Modifications Log
* Ver Date Author Modification
Expand Down Expand Up @@ -68,6 +68,27 @@ global with sharing class ScriptInstall implements InstallHandler {
{
CacheHelper.clearAllCache();

List_View_Config__c orgWideConfig = ListViewConfigHelper.getListViewConfig('All', 'All');

//put params into a map by name
Map<String, List_View_Config_Parameter__c> orgParams = new Map<String, List_View_Config_Parameter__c>();
for (List_View_Config_Parameter__c param: orgWideConfig.List_View_Config_Parameters__r)
orgParams.put(param.Parameter_Name__c, param);

if (orgParams.get('AllowImmediateRefresh') == null)
{
List_View_Config_Parameter__c param = new List_View_Config_Parameter__c();
param.List_View_Config__c = orgWideConfig.Id;
param.Parameter_Name__c = 'AllowImmediateRefresh';
param.Parameter_Type__c = ListViewHelper.TYPE_BOOLEAN;
param.Parameter_Value__c = ListViewHelper.FFALSE;
param.Parameter_Label__c = 'Allow Immediate Refresh';
orgParams.put(param.Parameter_Name__c, param);
}

HelperDatabase.upsertRecords(orgParams.values());


//send email notifying of the upgrade
HelperEmail.sendInstallEmail('Upgraded');
}
Expand Down
42 changes: 34 additions & 8 deletions force-app/main/default/lwc/simpliUIListViews/simpliUIListViews.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
@api displayAllRelatedRecords = false;
@api objectList = undefined;
@api listViewList = undefined;
@api allowImmediateRefresh = false;
@api immediatelyRefresh = false;
@api set actionList(value)
{
this.objectActionList = value;
Expand Down Expand Up @@ -215,6 +217,9 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
@track pinnedObject = undefined; //the object that is pinned if there is a pinned list view.
@track isRefreshing = false; //identifies whether this list views data is being refreshed AT INTERVALS.
@track refreshTime = Date.now(); //the timestamp for when the data was refreshed.
@track refreshRate = ''; //the refresh rate in seconds if the list view is auto refreshing.
@track refreshTitle = 'Click to perform full list view refresh';

@track spinner = false; //identifies if the PAGE spinner should be displayed or not.
@track dataSpinner = false; //identifies if the DATA spinner should be displayed or not.
@track firstListViewGet = true; //indicates whether this is the first time the list views are being retrieved.
Expand All @@ -238,7 +243,7 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
@track quickDataOldFieldValue;
@track offset = -1;
@track rowLimit = -1;
@track refreshRate = ''; //the refresh rate in seconds if the list view is auto refreshing.

//for handling hover changes
@track hoverSFDCId;
@track hoverAPIName;
Expand Down Expand Up @@ -269,7 +274,7 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
@track batchId = ''; //indicates the batch Id of the list view batch process.
@track isInitializing = true; //indicates whether we are initializing the page or not.
@track inRenderedCallback = false; //indicates whether the rendered callback method is processing
@track refreshTitle = 'Click to perform full list view refresh';

//for message channel handlers
subscription = null;
receivedMessage;
Expand Down Expand Up @@ -358,6 +363,11 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
this.selectedObject = this.singleListViewObject;
this.selectedListView = this.singleListViewApiName;
this.refreshAllListViewData();
if (this.immediatelyRefresh && this.allowImmediateRefresh) {
this.singleClickAutoRefresh = 'true';
this.handleAutoRefreshButtonClick();
}

} else if (this.mode === 'Related List View') {
if (this.singleListViewObject === '' || this.singleListViewApiName === '' || this.joinFieldName === '') {
this.dispatchEvent(SLVHelper.createToast('error', '', 'Related List View Configuration Error', 'If using Related List View mode the list view object, list view API name and join field name must be provided.', false));
Expand Down Expand Up @@ -397,6 +407,7 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
this.displayActions = false;
this.displayRecordPopovers = false;
this.allowRefresh = false;
this.allowImmediateRefresh = false;
this.displayURL = false;
this.displayReprocess = false;
this.listviewdropdownstyle = 'splitviewlistviewdropdown';
Expand Down Expand Up @@ -547,6 +558,7 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
if (this.displayTextSearch === true) { this.canDisplayTextSearch = true; }
if (SLVHelper.toBool(this.componentConfig.AllowDataExport) === false) { this.displayExportButton = false; }
if (SLVHelper.toBool(this.componentConfig.AllowAutomaticDataRefresh) === false) { this.allowRefresh = false; }
if (this.allowImmediateRefresh === true) { this.allowImmediateRefresh = SLVHelper.toBool(this.componentConfig.AllowImmediateRefresh); }
if (SLVHelper.toBool(this.componentConfig.AllowInlineEditing) === false) { this.allowInlineEditing = false; }
if (SLVHelper.toBool(this.componentConfig.AllowHorizontalScrolling) === false) { this.allowHorizontalScrolling = false; }
if (SLVHelper.toBool(this.componentConfig.DisplayRecordPopovers) === false) { this.displayRecordPopovers = false; }
Expand All @@ -573,8 +585,8 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
console.log('List view sort fields size - ' + listViewSortFields.listviews.length);
//EXAMPLE JSON - {"listviews": [{"name": "Account:Simpli_LV_Acct_1","fields": [{"sortIndex": "0", "fieldName": "Name", "sortDirection": "true"},{"sortIndex": "1", "fieldName": "BillingState", "sortDirection": "false"}]}, {"name": "Account:PlatinumandGoldSLACustomers","fields": [{"sortIndex": "0", "fieldName": "Name", "sortDirection": "true"},{"sortIndex": "1", "fieldName": "BillingState", "sortDirection": "false"},{"sortIndex": "2", "fieldName": "Id", "sortDirection": "false"}]}]}
// eslint-disable-next-line guard-for-in
for (let m in listViewSortFields.listviews) {
let listviewSorting = listViewSortFields.listviews[m];
for (let lv in listViewSortFields.listviews) {
let listviewSorting = listViewSortFields.listviews[lv];
//if we are working with the current list view
if (listviewSorting.name === this.pinnedObject + ':' + this.pinnedListView
|| listviewSorting.name === this.selectedObject + ':' + this.selectedListView
Expand Down Expand Up @@ -647,13 +659,13 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
SLVHelper.showErrorMessage(error);
}
}
getListViewActions() {
async getListViewActions() {
console.log('Starting getListViewActions');
if (this.virtual) {
this.dispatchEvent(new CustomEvent('getactions', { detail: { pageName: this.pageName, compType: this.mode, objectName: this.selectedObject, listViewName: this.selectedListView } }));
} else {
console.log(this.pageName + ' CALLOUT - getListViewActions - ' + this.calloutCount++);
getListViewActions({ objectType: this.selectedObject, listViewName: this.selectedListView, componentName: this.pageName }).then(result => {
await getListViewActions({ objectType: this.selectedObject, listViewName: this.selectedListView, componentName: this.pageName }).then(result => {
console.log(this.pageName + ' CALLOUT - getListViewActions - ' + this.calloutCount++);
this.objectActionList = result;
this.handleListViewActions(0);
Expand Down Expand Up @@ -769,14 +781,15 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
//if the offset has not changed or the row size has not changed then we are done.
if (this.offset === listViewDataResult.listView.offset || oldDataRowsSize === this.listViewDataRowsSize) {
this.dataSpinnerOff();
//update offset (which will trigger another request for data)

//update offset (which will trigger another request for data)
} else {
this.dataSpinnerOn();
this.offset = listViewDataResult.listView.offset;
this.rowLimit = listViewDataResult.listView.rowLimit;
this.getListViewDataPage();
}
//if we have reached our max limit
//if we have reached our max limit
} else {
this.dataSpinnerOff();
}
Expand Down Expand Up @@ -862,6 +875,11 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
this.selectedListView = this.pinnedListView;
this.selectedListViewExportName = this.selectedListView + '.csv';
this.refreshAllListViewData();
if (this.immediatelyRefresh && this.allowImmediateRefresh) {
this.singleClickAutoRefresh = 'true';
this.handleAutoRefreshButtonClick();
}

//if we do not then bail.
} else {
console.log('Did NOT find a list view with the pinned list view name for ' + this.pageName);
Expand Down Expand Up @@ -992,6 +1010,7 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
}
}
}

handleAutoRefreshData() {
console.log('Refreshing data for ' + this.pageName);
if (this.isRefreshing) {
Expand All @@ -1004,10 +1023,12 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
setTimeout(this.handleAutoRefreshData.bind(this), this.refreshRate * 1000); //change to milliseconds
}
}

async handleAutoRefreshButtonClick() {
console.log('Refresh button clicked for ' + this.pageName);
console.log('Auto refresh was set to ' + this.isRefreshing + ' for ' + this.pageName);
console.log('Refresh time was ' + this.refreshTime + ' for ' + this.pageName);

//if we do not have the single/double click refresh setting then get it
if (this.singleClickAutoRefresh === undefined) {
console.log(this.pageName + ' CALLOUT - getListViewConfigParameter(SingleClickAutoDataRefresh) - ' + this.calloutCount++);
Expand All @@ -1032,6 +1053,9 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
if (this.refreshRate === undefined || this.refreshRate === null || this.refreshRate === '') {
this.refreshRate = '45'; //default to 45s if nothing returned
}
if (this.immediatelyRefresh && this.allowImmediateRefresh && Number(this.refreshRate) < 60) {
this.refreshRate = '60';
}
}
this.dispatchEvent(SLVHelper.createToast('success', '', 'Auto Refresh Started', 'Refreshing every ' + this.refreshRate + 's', false));
this.dispatchEvent(new CustomEvent('eventresponse', { detail: { type: 'autoRefreshOn', status: 'finished' } }));
Expand All @@ -1044,6 +1068,7 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
this.dispatchEvent(SLVHelper.createToast('success', '', 'List View Refreshed', 'Click within 5 seconds of data loading to auto refresh.', false));
}
}

async getConfigParameter(paramName) {
return getListViewConfigParameter({ objectName: this.selectedObject, listViewName: this.selectedListView, paramName: paramName });
}
Expand Down Expand Up @@ -2284,6 +2309,7 @@ export default class simpliUIListViews extends NavigationMixin(LightningElement)
case 'displayModified': this.displayModified = SLVHelper.toBool(value); break;
case 'displayExportButton': this.displayExportButton = SLVHelper.toBool(value); break;
case 'displayTextSearch': this.displayTextSearch = SLVHelper.toBool(value); break;
case 'allowImmediateRefresh': this.allowImmediateRefresh = SLVHelper.toBool(value); break;
default: break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
<property name="displayRecordPopovers" type="Boolean" default="true" label="Display Record Popovers" description="Indicates whether the record detail popover should be displayed when the user moves the mouse over the record URL or name."/>
<property name="excludedRecordPopoverTypes" type="String" default="" label="Excluded Record Popover Types" description="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."/>
<property name="allowRefresh" type="Boolean" default="true" label="Allow Automatic Data Refresh" description="Indicates whether the data refresh checkbox should be made available. This checkbox allows the user to automatically have the page data refreshed. Use with caution!"/>
<property name="allowImmediateRefresh" type="Boolean" default="false" label="Allow Immediate Refresh" description="Indicates whether list views can be configured to automatically start refreshing as soon as its displayed."/>
<property name="immediatelyRefresh" type="Boolean" default="false" label="Immediately Refresh" description="Indicates whether this component will automatically start refreshing as soon as its displayed."/>
<property name="allowInlineEditing" type="Boolean" default="true" label="Allow Inline Editing" description="Indicates whether inline editing should be allowed for the list view rows."/>
<property name="allowHorizontalScrolling" type="Boolean" default="true" label="Allow Horizontal Scrolling" description="Indicates whether horizontal scrolling is allowed on the list view."/>
<property name="displayAllRelatedRecords" type="Boolean" default="false" label="Display All Related Records" description="Related List View Mode Only: Indicates whether all records should be displayed or scrolling should be used."/>
Expand Down

0 comments on commit 77d2510

Please sign in to comment.