With Summer 21', we have the ability to create a Quick Action from a LWC. https://developer.salesforce.com/blogs/2021/05/learn-moar-with-summer-21-lwc-quick-actions.html
https://help.salesforce.com/articleView?id=release-notes.rn_lwc_quick_actions.htm&type=5&release=232
The Quick Action doesn't use any of the HTML I can write in this component :
But I want to include a Spinner. I search for many ideas, creating another component which include just a spinner, but it seems really hard to open and close this component from the first one. I also didn't find any way to call a spinner by the JS without the HTML
There is my code :
getAccountReport.js
import { LightningElement, api, track } from 'lwc';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import getAccountReport from '@salesforce/apex/WS_Account_Report.getAccountReport';
export default class GetAccountInfosQALWC extends LightningElement
{
@api recordId;
@api invoke() {
//Here i'm sending a Toast message as a workaround
//But I want the spinner starting here
this.showToastMessage(1,'We are getting your report in few seconds...');
getAccountReport({accId : this.recordId })
.then((result) => {
//I want the spinner to stop here
if(result != true && result != 'true'){
this.showToastMessage(1,result);
}
else{
this.showToastMessage(2,'The report was successfully downloaded');
eval("$A.get('e.force:refreshView').fire();");
}
})
.catch((error) => {
console.log(error);
});
}
showToastMessage(fromWho, mess, urlToast) {
var variantToast;
var titleToast;
if(fromWho == 1){
variantToast = 'info';
}
else if(fromWho == 2){
variantToast = 'success';
titleToast = 'Success'
}
const toastMessage = new ShowToastEvent({
title: titleToast,
message: mess,
variant: variantToast,
messageData: [
{
url: urlToast,
label: 'here'
}
]
});
this.dispatchEvent(toastMessage);
}
}
getAccountReport.js-meta.xml
<?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__RecordAction</target>
</targets>
<targetConfigs>
<targetConfig targets="lightning__RecordAction">
<actionType>Action</actionType>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
I already tested to put the spinner in the HTML, that's not working.
#LWC #Lightning Web Components #Quick Actions #Service Cloud #New Releases
Thanks you !
if you dont wanna utilize html,
You can try add spinner html in slds to dom by js and remove it.
this is demo code
import { LightningElement } from 'lwc';
export default class SpinnerComponent extends LightningElement {
addSpinner() {
const container = this.template.querySelector('.spinner-container');
const spinnerHTML = `
<div class="demo-only demo-only_viewport" style="height:6rem;position:relative">
<div role="status" class="slds-spinner slds-spinner_medium">
<span class="slds-assistive-text">Loading</span>
<div class="slds-spinner__dot-a"></div>
<div class="slds-spinner__dot-b"></div>
</div>
</div>`;
container.innerHTML = spinnerHTML;
}
removeSpinner() {
const container = this.template.querySelector('.spinner-container');
container.innerHTML = '';
}
}