Skip to content

Commit

Permalink
Merge pull request #119 from navikt/chatReporting
Browse files Browse the repository at this point in the history
Chat reporting on Threat button
  • Loading branch information
mamikals authored Apr 30, 2024
2 parents 6b01fbb + 1958dd1 commit 6a6d4f6
Show file tree
Hide file tree
Showing 11 changed files with 141 additions and 17 deletions.
2 changes: 2 additions & 0 deletions force-app/main/default/aura/afterworkEvent/afterworkEvent.evt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<aura:event type="APPLICATION" description="Event template">
<aura:attribute name="tabId" type="String" />
<aura:attribute name="recordId" type="String" />
<aura:attribute name="reportingId" type="String" />
<aura:attribute name="type" type="String" />
</aura:event>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<aura:component implements="flexipage:availableForAllPageTypes, force:hasRecordId" controller="NKS_ChatAfterWork">
<lightning:workspaceAPI aura:id="workspace" />

<aura:registerEvent name="appEvent" type="c:afterworkEvent" />
<aura:handler event="c:afterworkEvent" action="{!c.handleChatEnded}" />
<aura:handler name="init" action="{!c.doInit}" value="{!this}" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand All @@ -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);
}
});
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<aura:component implements="flexipage:availableForAllPageTypes, lightning:backgroundUtilityItem">
<aura:component
implements="flexipage:availableForAllPageTypes, lightning:backgroundUtilityItem"
controller="NKS_ChatAfterWork"
>
<lightning:workspaceAPI aura:id="workspace" />
<aura:handler event="lightning:tabClosed" action="{!c.onTabClosed}" />

<aura:handler event="lightning:conversationChatEnded" action="{!c.handleChatEnded}" />
<aura:attribute name="closedChatList" type="object[]" />

<aura:registerEvent name="appEvent" type="c:afterworkEvent" />
<aura:handler event="c:afterworkEvent" action="{!c.handleThreatReport}" />
<aura:attribute name="threatReportList" type="object[]" />
</aura:component>
Original file line number Diff line number Diff line change
@@ -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);
},

Expand All @@ -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);
}
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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);
}
});
23 changes: 23 additions & 0 deletions force-app/main/default/classes/NKS_ChatAfterWork.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@
<name>relationshipField</name>
<value>CaseId</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>showKrrInfo</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>showLink</name>
<value>false</value>
Expand All @@ -83,7 +87,7 @@
</componentInstanceProperties>
<componentInstanceProperties>
<name>text</name>
<value>{!$Label.NAV_Unit_Subheader_More_Actions}</value>
<value>{!$Label.NAV_Unit_Subheader_more_actions}</value>
</componentInstanceProperties>
<componentName>nksInvisibleContentForSr</componentName>
<identifier>c_nksInvisibleContentForSr</identifier>
Expand All @@ -93,6 +97,12 @@
<type>Region</type>
</flexiPageRegions>
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentName>nksChatAfterWork</componentName>
<identifier>c_nksChatAfterWork</identifier>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
Expand All @@ -119,6 +129,14 @@
</itemInstances>
<itemInstances>
<componentInstance>
<componentInstanceProperties>
<name>maxEARContainerHeight</name>
<value>500</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>shouldDisplayFiltersOnRight</name>
<value>false</value>
</componentInstanceProperties>
<componentName>forceKnowledge:articleSearchDesktop</componentName>
<identifier>forceKnowledge_articleSearchDesktop</identifier>
</componentInstance>
Expand Down Expand Up @@ -175,6 +193,10 @@
<name>numCols</name>
<value>2</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>showKrrInfo</name>
<value>false</value>
</componentInstanceProperties>
<componentInstanceProperties>
<name>showLink</name>
<value>true</value>
Expand All @@ -196,4 +218,4 @@
</properties>
</template>
<type>RecordPage</type>
</FlexiPage>
</FlexiPage>
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
<flexiPageRegions>
<itemInstances>
<componentInstance>
<componentName>nksBackgroundTabUpdator</componentName>
<identifier>nksBackgroundTabUpdator</identifier>
<componentName>nksChatConversationHandler</componentName>
<identifier>nksChatConversationHandler</identifier>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentName>nksChatConversationHandler</componentName>
<identifier>nksChatConversationHandler</identifier>
<componentName>nksChatAfterWorkBackground</componentName>
<identifier>nksChatAfterWorkBackground</identifier>
</componentInstance>
</itemInstances>
<itemInstances>
<componentInstance>
<componentName>nksBackgroundTabUpdator</componentName>
<identifier>nksBackgroundTabUpdator</identifier>
</componentInstance>
</itemInstances>
<name>backgroundComponents</name>
Expand Down
2 changes: 1 addition & 1 deletion post-scratch/scratchSetup.cls
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 6a6d4f6

Please sign in to comment.