[SalesForce] How to Get the QuickAction Name in Lightning Component

We are in process of converting our existing JS buttons to Quick Action + lightning Components.

There are some 2/3 buttons which do the same functionality with very little difference among them. For Example, Creating a case with subject field Test1 in buttonA, Test2 in button B, Test3 in button C.

So ideally i should have 3 quick actions with 3 components. But since this is a very little change, i do not want to create another new component+controller and would like to reuse 1 component for all 3.

My Solution:

document.getElementsByClassName('modal-header slds-modal__header')[0].innerText

Using the above js code, i get the modal header name (which is nothing but the quick action label).

Finally based on the value from above js, i assign value to the field in sObject.

Is this correct approach or is there any predefined function which can be used for getting the quick action name?

Best Answer

I think what I would recommend here is to create nested components. So you have a parent component that will call the component you want to call here, and you can pass in attributes to the component. You technically will end up with 4 components, but the one is reused. So for example:

<aura:component >
    <aura:attribute name="specificParameter" type="String" required="true" />

    <div>
        {!v.specificParameter} is passed from the parent.
    </div>
</aura:component>

and in your parent component that is the quick action, you call your main component (ChildComponent) with the specific parameters you need.

<aura:component implements="force:lightningQuickAction" >
    <c:ChildComponent specificParameter="Test 1" />
</aura:component>