8

PROBLEM STATEMENT

I have a 'Compose Email' component which is embedded in the docked utility bar. Please see below image for clarity. I am using lightning:fileUpload to allow multiple email attachments, which get automatically attached to the specified parent record. If the user attaches stuff and ultimately sends out the email, then we are golden. But what if the user does NOT send out the email? In that case I need to delete all the 'temporary' attachments from the parent record that were intended to be sent but never were.

enter image description here

WHAT I HAVE TRIED SO FAR

onUtilityClick() in lightning:utilityBarAPI

From my component init, I call the below method which finds the first utility item and implements a handler for onUtilityClick. It fires fine when I click on the actual utility bar item, BUT it does NOT fire when I minimize the utility by clicking on its header or the minimize button. I went through the utilityBarAPI methods here but none seem to be relevant for my goal.

handleUtilityBar : function(component, event, helper) {
        var utilityAPI = component.find("utilitybar");

        utilityAPI.getAllUtilityInfo().then(function(response) {
            var utilityId = response[0].id;
            var onComposeEmailMinimize = function(response){
                console.log('--------------------> WORKS ON UTILITY ITEM CLICK, BUT NEEDS TO FIRE ON UTILITY MINIMIZE AS WELL');
            };

            utilityAPI.onUtilityClick({
                utilityId: utilityId,
                eventHandler: onComposeEmailMinimize 
            }).then(function(result){
                console.log('--------------------> result = ' + result);
            }).catch(function(error){
                console.log('--------------------> error = ' + error);
            });

        })
        .catch(function(error) {
            console.log('-------> utilityAPI ERROR: ' + error);
        });

    },

unrender in RENDERER

I have also tried my luck handling unrender in RENDERER, but no dice.

unrender: function () {
    this.superUnrender();
    console.log('--------------------> UNRENDER CALLED');
}

Handle component destroy

As a measure of last resort, I also tried (a long shot) to see if destroy event is called upon minimize, but nope.

<aura:handler name="destroy" value="{!this}" action="{!c.handleDestroy}"/> 

QUESTION

How can we delete the 'orphan' ContentDocuments when:

  1. User minimizes 'Compose Email' utility, or
  2. Ends up refreshing the page, or
  3. Navigates away from the page they are on?
4
  • This problem is very common. one solution would be to run a scheduled batch, lets say every day, and delete all orphan files (files that emails have not been sent). You can add to this solution a file delete function and to execute it when User minimizes 'Compose Email' utility or other events that you can handle Commented Jul 29, 2018 at 12:04
  • How would you detect minimize action to a utility? There is way to minimize an open utility, but nothing that tells that a user has clicked on the minimize button. Commented Jul 29, 2018 at 12:15
  • I do not know if you can do that Commented Jul 29, 2018 at 13:51
  • Upvoted ... one would think this would be an action developers would be able to capture !!! But so far I cannot find a way to listen for it. Commented Nov 26, 2018 at 22:23

1 Answer 1

2

Here's how I solved this issue.

  1. Create a div in your component like this. The following div covers the minimize button at the top right of the utility popup. It intercepts the minimize click so that the click can be handled.
    <div style="background:transparent; width:30px; height:30px; position:absolute; top:6px; right:9px; cursor:pointer;" onclick="{!c.handleMinimizeClick}"></div>
  1. Add a method to your controller.js to do your stuff like this:
handleMinimizeClick : function(component, event, helper) {
   // my logic goes here
   let utility = component.find('utilityBar');
   utility.minimizeUtility();
}
1
  • I implemented this same solution, but discovered 1 issue with it. The User can also minimize the Component by clicking on the Utility Bar itself (at the bottom, below the component). I don't see a way to put a div overtop of the Utility Bar to capture those clicks as well. This is a great workaround! I just need to figure out if I can also override those clicks down below the component.
    – Dave Ries
    Commented Mar 1, 2023 at 17:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .