From 2d331e23b3659ff2b2ac618a085c68eaa003f40c Mon Sep 17 00:00:00 2001 From: Morten Mikalsen Date: Tue, 13 Feb 2024 13:29:33 +0100 Subject: [PATCH 1/3] Fix scratch script --- post-scratch/scratchSetup.cls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/post-scratch/scratchSetup.cls b/post-scratch/scratchSetup.cls index 1d8b3efa..896503f9 100644 --- a/post-scratch/scratchSetup.cls +++ b/post-scratch/scratchSetup.cls @@ -17,7 +17,7 @@ catch(Exception ex) { Account personAccount = [SELECT FirstName, LastName, PersonContactId FROM Account WHERE INT_PersonIdent__c = '12345678901']; //Create user Profile portalProfile = [SELECT Id FROM Profile WHERE Name='Scratch Community Profile' Limit 1]; -String userName = personAccount.FirstName + '.' +personAccount.LastName + '@' + URL.getSalesforceBaseUrl().getHost(); +String userName = personAccount.FirstName + '.' +personAccount.LastName + '@' + URL.getOrgDomainUrl().getHost(); User user1 = new User( UserName = userName, FirstName = personAccount.FirstName, From 03a559694384b5732d9de279314592983e911384 Mon Sep 17 00:00:00 2001 From: Morten Mikalsen Date: Tue, 13 Feb 2024 13:30:37 +0100 Subject: [PATCH 2/3] Add afterwork to scratch app --- .../NKS_Chat_Record_Page.flexipage-meta.xml | 26 +++++++++++++++++-- .../Scratch_App_UtilityBar.flexipage-meta.xml | 14 +++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/force-app/scratch-org/flexipages/NKS_Chat_Record_Page.flexipage-meta.xml b/force-app/scratch-org/flexipages/NKS_Chat_Record_Page.flexipage-meta.xml index 1e1000e1..3293bb89 100644 --- a/force-app/scratch-org/flexipages/NKS_Chat_Record_Page.flexipage-meta.xml +++ b/force-app/scratch-org/flexipages/NKS_Chat_Record_Page.flexipage-meta.xml @@ -63,6 +63,10 @@ relationshipField CaseId + + showKrrInfo + false + showLink false @@ -83,7 +87,7 @@ text - {!$Label.NAV_Unit_Subheader_More_Actions} + {!$Label.NAV_Unit_Subheader_more_actions} nksInvisibleContentForSr c_nksInvisibleContentForSr @@ -93,6 +97,12 @@ Region + + + nksChatAfterWork + c_nksChatAfterWork + + @@ -119,6 +129,14 @@ + + maxEARContainerHeight + 500 + + + shouldDisplayFiltersOnRight + false + forceKnowledge:articleSearchDesktop forceKnowledge_articleSearchDesktop @@ -175,6 +193,10 @@ numCols 2 + + showKrrInfo + false + showLink true @@ -196,4 +218,4 @@ RecordPage - \ No newline at end of file + diff --git a/force-app/scratch-org/flexipages/Scratch_App_UtilityBar.flexipage-meta.xml b/force-app/scratch-org/flexipages/Scratch_App_UtilityBar.flexipage-meta.xml index 864d731c..db1de8ec 100644 --- a/force-app/scratch-org/flexipages/Scratch_App_UtilityBar.flexipage-meta.xml +++ b/force-app/scratch-org/flexipages/Scratch_App_UtilityBar.flexipage-meta.xml @@ -13,14 +13,20 @@ - nksBackgroundTabUpdator - nksBackgroundTabUpdator + nksChatConversationHandler + nksChatConversationHandler - nksChatConversationHandler - nksChatConversationHandler + nksChatAfterWorkBackground + nksChatAfterWorkBackground + + + + + nksBackgroundTabUpdator + nksBackgroundTabUpdator backgroundComponents From d90325b42012470365daad1c373dad42ded2b5bc Mon Sep 17 00:00:00 2001 From: Morten Mikalsen Date: Tue, 13 Feb 2024 13:31:12 +0100 Subject: [PATCH 3/3] Add reporting data to threat button --- .../aura/afterworkEvent/afterworkEvent.evt | 2 + .../nksChatAfterWork/nksChatAfterWork.cmp | 1 + .../nksChatAfterWorkController.js | 41 ++++++++++++++++--- .../nksChatAfterWorkBackground.cmp | 7 +++- .../nksChatAfterWorkBackgroundController.js | 10 ++++- .../nksChatAfterWorkBackgroundHelper.js | 28 ++++++++++++- .../default/classes/NKS_ChatAfterWork.cls | 23 +++++++++++ sfdx-project.json | 4 +- 8 files changed, 106 insertions(+), 10 deletions(-) diff --git a/force-app/main/default/aura/afterworkEvent/afterworkEvent.evt b/force-app/main/default/aura/afterworkEvent/afterworkEvent.evt index dc8ad27d..7ed4d2f3 100644 --- a/force-app/main/default/aura/afterworkEvent/afterworkEvent.evt +++ b/force-app/main/default/aura/afterworkEvent/afterworkEvent.evt @@ -1,4 +1,6 @@ + + diff --git a/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWork.cmp b/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWork.cmp index 9673f8a9..8cddb48f 100644 --- a/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWork.cmp +++ b/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWork.cmp @@ -1,6 +1,7 @@ + diff --git a/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWorkController.js b/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWorkController.js index b0627d7b..2b855174 100644 --- a/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWorkController.js +++ b/force-app/main/default/aura/nksChatAfterWork/nksChatAfterWorkController.js @@ -3,7 +3,6 @@ var action = component.get('c.hasBetaAccess'); action.setCallback(this, function (response) { var state = response.getState(); - console.log(state); if (state === 'SUCCESS') { component.set('v.betaAccess', response.getReturnValue()); @@ -26,13 +25,45 @@ $A.enqueueAction(action); }, handleChatEnded: function (component, event, helper) { - var recordId = component.get('v.recordId'); - var eventRecordId = event.getParam('recordId'); - if (recordId === eventRecordId && component.get('v.betaAccess')) { - helper.startTimer(component, eventRecordId); + var type = event.getParam('type'); + if (type === 'startTimer') { + var recordId = component.get('v.recordId'); + var eventRecordId = event.getParam('recordId'); + if (recordId === eventRecordId && component.get('v.betaAccess')) { + helper.startTimer(component, eventRecordId); + } } }, stopTimer: function (component) { component.set('v.stopped', true); + var action = component.get('c.reportThreatClick'); + action.setCallback(this, function (response) { + var state = response.getState(); + if (state === 'SUCCESS') { + var reportingId = response.getReturnValue(); + var appEvent = $A.get('e.c:afterworkEvent'); + const recordId = component.get('v.recordId'); + appEvent.setParams({ reportingId: reportingId }); + appEvent.setParams({ recordId: recordId }); + appEvent.setParams({ type: 'createdThreatReport' }); + appEvent.fire(); + + // You would typically fire a event here to trigger + // client-side notification that the server-side + // action is complete + } else if (state === 'INCOMPLETE') { + // do something + } else if (state === 'ERROR') { + var errors = response.getError(); + if (errors) { + if (errors[0] && errors[0].message) { + console.log('Error message: ' + errors[0].message); + } + } else { + console.log('Unknown error'); + } + } + }); + $A.enqueueAction(action); } }); diff --git a/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackground.cmp b/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackground.cmp index a8ec4127..7a51750e 100644 --- a/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackground.cmp +++ b/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackground.cmp @@ -1,4 +1,7 @@ - + @@ -6,4 +9,6 @@ + + diff --git a/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundController.js b/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundController.js index 6741d398..957cd5ce 100644 --- a/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundController.js +++ b/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundController.js @@ -1,7 +1,7 @@ ({ onTabClosed: function (component, event, helper) { var closedTabId = event.getParam('tabId'); - helper.removeClosedChatTabId(component, closedTabId); + helper.removeClosedChatTabId(component, closedTabId, helper); helper.startTimer(component); }, @@ -21,5 +21,13 @@ .catch(() => { //Errors require manual handling. }); + }, + handleThreatReport: function (component, event, helper) { + var type = event.getParam('type'); + if (type === 'createdThreatReport') { + var recordId = event.getParam('recordId'); + var reportingId = event.getParam('reportingId'); + helper.storeThreatReport(component, reportingId, recordId); + } } }); diff --git a/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundHelper.js b/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundHelper.js index f2f33683..36d1fd2b 100644 --- a/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundHelper.js +++ b/force-app/main/default/aura/nksChatAfterWorkBackground/nksChatAfterWorkBackgroundHelper.js @@ -21,13 +21,15 @@ component.set('v.closedChatList', tabs); }, - removeClosedChatTabId: function (component, tabId) { + removeClosedChatTabId: function (component, tabId, helper) { const tabs = component.get('v.closedChatList'); const index = tabs.findIndex((tab) => tab.tab === tabId); + const recordId = tabs[index].recordId; if (index > -1) { tabs.splice(index, 1); component.set('v.closedChatList', tabs); } + helper.removeThreatReport(component, recordId, helper); }, startTimer: function (component) { @@ -36,6 +38,30 @@ var appEvent = $A.get('e.c:afterworkEvent'); appEvent.setParams({ tabId: tabs[0].tab }); appEvent.setParams({ recordId: tabs[0].recordId }); + appEvent.setParams({ type: 'startTimer' }); appEvent.fire(); + }, + + storeThreatReport: function (component, reportingId, recordId) { + let threatReportList = component.get('v.threatReportList'); + threatReportList.push({ reportingId: reportingId, recordId: recordId, time: Date.now() }); + component.set('v.threatReportList', threatReportList); + }, + + removeThreatReport: function (component, recordId, helper) { + const threatReports = component.get('v.threatReportList'); + const index = threatReports.findIndex((reporting) => reporting.recordId === recordId); + const reportingId = threatReports[index].reportingId; + const time = Date.now() - threatReports[index].time; + if (index > -1) { + threatReports.splice(index, 1); + component.set('v.threatReportList', threatReports); + } + helper.updateThreatTime(component, reportingId, time); + }, + updateThreatTime: function (component, reportingId, time) { + var action = component.get('c.updateThreatClickValue'); + action.setParams({ rDataId: reportingId, value: time }); + $A.enqueueAction(action); } }); diff --git a/force-app/main/default/classes/NKS_ChatAfterWork.cls b/force-app/main/default/classes/NKS_ChatAfterWork.cls index bf3826b4..fa44bdfc 100644 --- a/force-app/main/default/classes/NKS_ChatAfterWork.cls +++ b/force-app/main/default/classes/NKS_ChatAfterWork.cls @@ -3,4 +3,27 @@ public with sharing class NKS_ChatAfterWork { public static Boolean hasBetaAccess() { return FeatureManagement.checkPermission('NKS_Beta'); } + + @AuraEnabled + public static Id reportThreatClick() { + try { + ReportingData__c rData = new ReportingData__c(); + rData.CRM_Category__c = 'Chat Threat'; + insert rData; + return rData.Id; + } catch (Exception e) { + throw new AuraHandledException(e.getMessage()); + } + } + + @AuraEnabled + public static void updateThreatClickValue(Id rDataId, Integer value) { + try { + ReportingData__c rData = new ReportingData__c(Id = rDataId); + rData.CRM_Value__c = value; + update rData; + } catch (Exception e) { + throw new AuraHandledException(e.getMessage()); + } + } } diff --git a/sfdx-project.json b/sfdx-project.json index 876353ee..76bc8a0b 100644 --- a/sfdx-project.json +++ b/sfdx-project.json @@ -8,11 +8,11 @@ "dependencies": [ { "package": "crm-platform-base", - "versionNumber": "0.194.0.LATEST" + "versionNumber": "0.198.0.LATEST" }, { "package": "crm-platform-reporting", - "versionNumber": "0.32.0.LATEST" + "versionNumber": "0.38.0.LATEST" }, { "package": "crm-platform-integration",