Skip to content

Commit

Permalink
Implementation of evolution #28 - copy to clipboard action
Browse files Browse the repository at this point in the history
  • Loading branch information
P-E Gros committed Oct 26, 2022
1 parent cded76e commit 8596c96
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
30 changes: 30 additions & 0 deletions force-app/main/default/lwc/sfpegActionBarCmp/sfpegActionBarCmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,10 @@ export default class SfpegActionMenuDsp extends NavigationMixin(LightningElement
if (this.isDebug) console.log('processAction: notifying action to other component via channel ',action.channel);
this.triggerCustomNotification(action.params,action.channel);
break;
case 'clipboard':
if (this.isDebug) console.log('processAction: processing clipboard action');
this.triggerClipboard(action.params);
break;
default:
console.warn('processAction: END / no/bad action type provided',action.type);
return;
Expand Down Expand Up @@ -1516,6 +1520,32 @@ export default class SfpegActionMenuDsp extends NavigationMixin(LightningElement
}
}

triggerClipboard = function(textContent) {
if (this.isDebug) console.log('triggerClipboard: START with ',JSON.stringify(textContent));

if (!textContent) {
console.warn('triggerClipboard: END KO / Missing textContent property');
throw "Missing textContent in clipboard copy operation params!";
}

if (this.isDebug) console.log('triggerClipboard: navigator found ',navigator);
if (navigator?.clipboard) {
if (this.isDebug) console.log('triggerClipboard: triggering navigator copy on clipboard ',navigator.clipboard);
navigator.clipboard.writeText(textContent);
}
else {
if (this.isDebug) console.log('triggerClipboard: triggering legacy copy on clipboard');
let hiddenInput = document.createElement("input");
hiddenInput.setAttribute("value", textContent);
document.body.appendChild(hiddenInput);
hiddenInput.select();
document.execCommand("copy");
document.body.removeChild(hiddenInput);
}

if (this.isDebug) console.log('triggerClipboard: END');
}

//----------------------------------------------------------------
// Utilities
//----------------------------------------------------------------
Expand Down
3 changes: 3 additions & 0 deletions force-app/main/default/lwc/sfpegMergeUtl/sfpegMergeUtl.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,9 @@ const sfpegMergeUtl = {
case 'recordId':
resultData[iterField.field] = recordId;
break;
case 'baseUrl':
resultData[iterField.field] = window.location.origin;
break;
case 'now':
resultData[iterField.field] = (new Date()).toISOString();
break;
Expand Down
34 changes: 34 additions & 0 deletions help/sfpegActionBarCmp.md
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,38 @@ triggering via a `utility` action type followed by a `notify` one to refresh the
**[sfpegListCmp](/help/sfpegListCmp.md)** component.


### **clipboard** Action Type

The **clipboard** action type enables to copy a preconfigured string to the user clipboard, enabling
to paste it in other applications (or emails).

The `params` property should be a standard text string providing the content to be written in the user
clipboard.

Typical use cases are to copy a record name or a link to a given record to be pasted in an email or
message.
```
[
{
"label": "Clip Name",
"name": "ClipName",
"action": {
"type": "clipboard",
"params": "{{{RCD.Name}}}"
}
},
{
"label": "Clip URL",
"name": "ClipUrl",
"action": {
"type": "clipboard",
"params": "{{{GEN.baseUrl}}}/lightning/r/{{{GEN.objectApiName}}}/{{{GEN.recordId}}}/view"
}
}
]
```


### Action Types from Other Components (Flow Popup, Aura Application Event, List Refresh, List Filter...)

Other action types (or triggering contexts) are available from other components via various triggering mechanisms:
Expand All @@ -959,6 +991,8 @@ Other action types (or triggering contexts) are available from other components
* **[sfpegListCmp](/help/sfpegListCmp.md)** actions may be triggered within a **done** action type




---

## Configuration Examples
Expand Down
1 change: 1 addition & 0 deletions help/sfpegMergeUtl.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ As a baseline, the **sfpegMergeUtl** component provides the following set of tok
* **GEN.xxx** to fetch some generic elements :
* `GEN.objectApiName` and `GEN.recordId` for the Object name and Salesforce record Id of the current page (when applicable)
* `GEN.userId` for the Salesforce record Id of the current User
* `GEN.baseUrl` for the Salesforce base URL of the current application
* `GEN.now` to get current timestamp (in ISO format)
* `GEN.today`, `GEN.yesterday`, `GEN.tomorrow`, `GEN.lastWeek`, `GEN.nextWeek`, `GEN.lastMonth`, `GEN.nextMonth`, `GEN.lastQuarter`, `GEN.nextQuarter`, `GEN.lastYear`, `GEN.nextYear` to get dates in delta to current day, value being provided in ISO format
* To get these values in user local format (e.g. for message display), `Local` should be appended to the token name (e.g. `GEN.todayLocal`).
Expand Down

0 comments on commit 8596c96

Please sign in to comment.