Skip to content

Commit

Permalink
Merge pull request #91 from tsalb/message-service-enhancements
Browse files Browse the repository at this point in the history
Message service enhancements
  • Loading branch information
tsalb authored May 7, 2021
2 parents fee0339 + ac7205c commit 8f870ef
Show file tree
Hide file tree
Showing 30 changed files with 741 additions and 69 deletions.
18 changes: 9 additions & 9 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
"path": "utils-core",
"default": true,
"package": "LWC Utils",
"versionName": "ver 1.5.4",
"versionNumber": "1.5.4.NEXT",
"versionName": "ver 1.6.0",
"versionNumber": "1.6.0.NEXT",
"postInstallUrl": "https://github.com/tsalb/lwc-utils/releases",
"releaseNotesUrl": "https://github.com/tsalb/lwc-utils/releases"
},
{
"path": "utils-recipes",
"default": false,
"package": "LWC Utils Recipes",
"versionName": "ver 1.5.4",
"versionNumber": "1.5.4.NEXT",
"versionName": "ver 1.6.0",
"versionNumber": "1.6.0.NEXT",
"postInstallUrl": "https://github.com/tsalb/lwc-utils/releases",
"releaseNotesUrl": "https://github.com/tsalb/lwc-utils/releases",
"dependencies": [
{
"package": "LWC [email protected]"
"package": "LWC Utils",
"versionNumber": "1.6.0.LATEST"
}
]
}
Expand All @@ -29,10 +30,9 @@
"sourceApiVersion": "51.0",
"packageAliases": {
"LWC Utils Recipes": "0Ho1Q000000blJnSAI",
"LWC Utils Recipes@1.5.4-1": "04t1Q000001Qi2jQAC",
"LWC Utils Recipes@1.6.0-1": "04t1Q000001MRpjQAG",
"LWC Utils": "0Ho1Q000000blJiSAI",
"LWC [email protected]": "04t1Q000001QhyDQAS",
"LWC [email protected]": "04t1Q000001Qi0sQAC",
"LWC [email protected]": "04t1Q000001Qi2eQAC"
"LWC [email protected]": "04t1Q000001Qi2eQAC",
"LWC [email protected]": "04t1Q000001MRpeQAG"
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
<aura:component implements="flexipage:availableForAllPageTypes, lightning:utilityItem" access="global">
<c:DialogService aura:id="dialogService" />
<c:messageService aura:id="messageService" onopendialog="{! c.handleDialogService }" />
<aura:component
implements="flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes,lightning:utilityItem,force:hasRecordId"
access="global"
>
<c:messageService
aura:id="messageService"
onopendialog="{! c.handleDialogService }"
onworkspaceapi="{! c.handleWorkspaceApi }"
onrecordedit="{! c.handleRecordEdit }"
onrecordcreate="{! c.handleRecordCreate }"
/>

<c:singleton aura:id="singleton" />
<c:dialogService aura:id="dialogService" />
<c:workspaceService aura:id="workspaceService" />

<aura:attribute name="customBoundary" type="String" />
<aura:handler name="init" value="{! this }" action="{! c.doInit }" />
</aura:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<design:component label="Message Service Handler">
<design:attribute
name="customBoundary"
label="Custom Boundary"
description="Use any String or $recordId (if available, otherwise it will be null). Useful if you want granular control of which boundaries this handler can listen to."
/>
</design:component>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@
*/

({
doInit: function (component, event, helper) {
const customBoundary = component.get('v.customBoundary');
if (!!customBoundary) {
const messageService = helper.messageService(component);
const recordId = component.get('v.recordId');
const isRecordIdRequested = customBoundary === '$recordId';
// When recordId context is not available but was requested, leave messageService to its defaults
if (!recordId && isRecordIdRequested) {
return;
}
const finalBoundary = recordId && isRecordIdRequested ? recordId : customBoundary;
messageService.set('v.useRecordIdAsBoundary', recordId && isRecordIdRequested);
messageService.set('v.boundary', finalBoundary);
}
},
handleDialogService: function (component, event, helper) {
const payload = event.getParam('value');
const singleton = helper.singleton(component);
Expand All @@ -42,5 +57,38 @@
singleton.setIsCreatingModal(true);

helper.executeDialogService(component, payload);
},
handleWorkspaceApi: function (component, event, helper) {
const payload = event.getParam('value');
const singleton = helper.singleton(component);

if (singleton.getIsMessaging()) {
return;
}
singleton.setIsMessaging(true);

helper.executeWorkspaceApi(component, payload);
},
handleRecordEdit: function (component, event, helper) {
const payload = event.getParam('value');
const singleton = helper.singleton(component);

if (singleton.getIsMessaging()) {
return;
}
singleton.setIsMessaging(true);

helper.fireRecordEdit(component, payload);
},
handleRecordCreate: function (component, event, helper) {
const payload = event.getParam('value');
const singleton = helper.singleton(component);

if (singleton.getIsMessaging()) {
return;
}
singleton.setIsMessaging(true);

helper.fireRecordCreate(component, payload);
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,14 @@
*/

({
messageService: function (component) {
return component.find('messageService');
},
dialogService: function (component) {
return component.find('dialogService');
},
messageService: function (component) {
return component.find('messageService');
workspaceService: function (component) {
return component.find('workspaceService');
},
singleton: function (component) {
return component.find('singleton');
Expand Down Expand Up @@ -73,14 +76,13 @@
// nothing
}
},
// mainActionReference only works for aura components
modal: function (component, config) {
this.dialogService(component).modal(
config.auraId,
config.headerLabel,
config.component,
config.componentParams,
config.mainActionReference,
config.mainActionReference, // mainActionReference only works for aura components
config.mainActionLabel
);
},
Expand All @@ -99,5 +101,34 @@
config.component,
config.componentParams
);
},
executeWorkspaceApi: function (component, payload) {
switch (payload.method) {
case 'openTab':
this.workspaceService(component).openTab(payload.config);
break;
case 'openSubtab':
this.workspaceService(component).openSubtab(payload.config);
break;
case 'closeTabByTitle':
this.workspaceService(component).closeTabByTitle(payload.config);
break;
default:
// nothing
}
},
fireRecordEdit: function (component, payload) {
$A.get('e.force:editRecord').setParams({ recordId: payload.recordId }).fire();
this.singleton(component).setIsMessaging(false);
},
fireRecordCreate: function (component, payload) {
$A.get('e.force:createRecord')
.setParams({
entityApiName: payload.entityApiName,
recordTypeId: payload.recordTypeId,
defaultFieldValues: payload.defaultFieldValues
})
.fire();
this.singleton(component).setIsMessaging(false);
}
});
17 changes: 17 additions & 0 deletions utils-core/main/default/aura/WorkspaceService/WorkspaceService.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<aura:component>
<c:messageService aura:id="messageService"></c:messageService>
<c:singleton aura:id="singleton" />
<lightning:workspaceAPI aura:id="workspaceApi" />

<aura:method name="openTab" action="{! c.handleOpenTab }">
<aura:attribute name="config" type="Object" />
</aura:method>

<aura:method name="openSubtab" action="{! c.handleOpenSubtab }">
<aura:attribute name="config" type="Object" />
</aura:method>

<aura:method name="closeTabByTitle" action="{! c.handleCloseTabByTitle }">
<aura:attribute name="config" type="Object" />
</aura:method>
</aura:component>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>51.0</apiVersion>
<description>A Lightning Component Bundle</description>
</AuraDefinitionBundle>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.THIS {
display: none;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/**
* BSD 3-Clause License
*
* Copyright (c) 2021, [email protected]
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

({
handleOpenTab: function (component, event, helper) {
const params = event.getParam('arguments');
const messageService = helper.messageService(component);
const singleton = helper.singleton(component);
const workspace = helper.workspaceApi(component);

workspace
.openTab(params.config)
.then(tabId => {
const successPayload = {
tabId: tabId
};
messageService.publish({ key: 'opentabresolve', value: successPayload });
})
.catch(err => {
console.error(err);
const errorPayload = {
error: err
};
messageService.publish({ key: 'opentabresolve', value: errorPayload });
});

singleton.setIsMessaging(false);
},
handleOpenSubtab: function (component, event, helper) {
const params = event.getParam('arguments');
const messageService = helper.messageService(component);
const singleton = helper.singleton(component);
const workspace = helper.workspaceApi(component);

// Try to open subtab from current tab
if (!params.config.parentTabId) {
workspace.getEnclosingTabId().then(result => {
params.config.parentTabId = result;
});
}
workspace
.openSubtab(params.config)
.then(tabId => {
const successPayload = {
tabId: tabId
};
messageService.publish({ key: 'opensubtabresolve', value: successPayload });
})
.catch(err => {
console.error(err);
const errorPayload = {
error: err
};
messageService.publish({ key: 'opensubtabresolve', value: errorPayload });
});

singleton.setIsMessaging(false);
},
handleCloseTabByTitle: function (component, event, helper) {
const params = event.getParam('arguments');
const singleton = helper.singleton(component);
const workspace = helper.workspaceApi(component);

workspace.getAllTabInfo().then(allTabInfo => {
for (let tab of allTabInfo) {
if (tab.title === params.config.title) {
workspace.closeTab({ tabId: tab.tabId });
}
}
});
singleton.setIsMessaging(false);
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* BSD 3-Clause License
*
* Copyright (c) 2021, [email protected]
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* - Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* - Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

({
messageService: function (component) {
return component.find('messageService');
},
singleton: function (component) {
return component.find('singleton');
},
workspaceApi: function (component) {
return component.find('workspaceApi');
}
});
2 changes: 1 addition & 1 deletion utils-core/main/default/lwc/datatable/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const MAX_ROW_SELECTION = 200;
const OBJECTS_WITH_COMPOUND_NAMES = ['Contact'];

// Lower is less fuzzy / better hit result
const SEARCH_THRESHOLD = 0.3;
const SEARCH_THRESHOLD = 0.1;

// Datatable_Action_Config__mdt
const LEGACY_TABLE_ACTION_ONE_STRING = 'Primary';
Expand Down
Loading

0 comments on commit 8f870ef

Please sign in to comment.