Skip to content

Commit

Permalink
Initial version of an LWC List View wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-baillie-ortoo committed Feb 4, 2022
1 parent c3e29f5 commit 0f90c2e
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>52.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__AppPage</target>
<target>lightning__Tab</target>
</targets>
</LightningComponentBundle>

0 comments on commit 0f90c2e

Please sign in to comment.