From 0f90c2e36656a5ad0200f8c18a6dc1357b671a1f Mon Sep 17 00:00:00 2001 From: Robert Baillie Date: Fri, 4 Feb 2022 14:31:35 +0000 Subject: [PATCH] Initial version of an LWC List View wrapper --- .../lwcListViewWrapper/lwcListViewWrapper.js | 70 +++++++++++++++++++ .../lwcListViewWrapper.js-meta.xml | 9 +++ 2 files changed, 79 insertions(+) create mode 100644 framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js create mode 100644 framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js-meta.xml diff --git a/framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js b/framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js new file mode 100644 index 00000000000..1148603360e --- /dev/null +++ b/framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js @@ -0,0 +1,70 @@ +import { LightningElement, wire, track } from 'lwc'; +import { CurrentPageReference, NavigationMixin } from 'lightning/navigation'; +import displayError from 'c/errorRenderer'; +import getEpochTime from '@salesforce/apex/TimeController.getEpochTime'; + +const LOAD_LEEWAY = 60; // number of seconds leeway between the redirection to the page and the load of it. + +// TODO: can we have a generic 'no records selected' error? +// TODO: clarify the error message when using an old link +// TODO: standards to always say how many records will be updated on the included LWC +export default class LwcListViewWrapper extends NavigationMixin( LightningElement ) { + + @track currentPageReference; + @wire( CurrentPageReference ) + setCurrentPageReference( currentPageReference ) { + this.currentPageReference = currentPageReference; + this.checkLoadTimeWithinLimits(); + } + + displayForm; + launchedEpochTime; + + get recordIds() { + return JSON.parse( this.currentPageReference?.state?.c__recordIds ); + } + + get directedEpochTime() { + return parseInt( this.currentPageReference?.state?.c__epoch ); + } + + get returnUrl() { + return this.currentPageReference?.state?.c__returnUrl; + } + + checkLoadTimeWithinLimits() { + + if ( ! this.directedEpochTime ) { + return; + } + + getEpochTime() + .then( launchedEpochTime => { + + this.launchedEpochTime = parseInt( launchedEpochTime ); + + let timeDifference = Math.abs( this.directedEpochTime - this.launchedEpochTime ); + let withinLeeway = timeDifference < LOAD_LEEWAY; + + if ( ! withinLeeway ) + { + displayError.call( this, 'It appears the page was loaded from an old link, and this is dangerous so it is not allowed' ); + } + this.displayForm = withinLeeway; + }); + } + + navigateToReturnUrl() { + const navigation = { + type: 'standard__webPage', + attributes: { + url: this.returnUrl + } + }; + this[NavigationMixin.Navigate]( navigation ); + } + + close() { + this.navigateToReturnUrl(); + } +} \ No newline at end of file diff --git a/framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js-meta.xml b/framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js-meta.xml new file mode 100644 index 00000000000..c318e17cd58 --- /dev/null +++ b/framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js-meta.xml @@ -0,0 +1,9 @@ + + + 52.0 + true + + lightning__AppPage + lightning__Tab + + \ No newline at end of file