forked from apex-enterprise-patterns/fflib-apex-common
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial version of an LWC List View wrapper
- Loading branch information
1 parent
c3e29f5
commit 0f90c2e
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
framework/default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
...default/ortoo-lwc-list-view-buttons/lwc/lwcListViewWrapper/lwcListViewWrapper.js-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |