Skip to content

Commit

Permalink
Add grant selector to editor for USer changing grant app without navi…
Browse files Browse the repository at this point in the history
…gation to tabs
  • Loading branch information
iandrosov committed Dec 26, 2023
1 parent d9b178a commit 4aa7f52
Show file tree
Hide file tree
Showing 10 changed files with 371 additions and 280 deletions.
480 changes: 226 additions & 254 deletions force-app/main/default/classes/GGW_ApplicationCtrl.cls

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions force-app/main/default/classes/GGW_ApplicationSelector.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*
* GGW_ApplicationSelector SOQL Query class support GGW.
*
*/
public with sharing class GGW_ApplicationSelector {
public static List<GGW_Grant_Application__c> getGrantApplications(){
return [SELECT Id, Name, Application_Name__c, Logo_Download_Url__c,
DistributionPublicUrl__c, Status__c, Description__c,
Language__c, Include_Logo__c
FROM GGW_Grant_Application__c
WITH SECURITY_ENFORCED];
}

public static GGW_Grant_Application__c queryGrantApp(String appId){
return [SELECT Id, Name, Application_Name__c, Logo_Download_Url__c,
DistributionPublicUrl__c, Status__c, Description__c,
Language__c, Include_Logo__c
FROM GGW_Grant_Application__c
WHERE Id =: appId WITH SECURITY_ENFORCED LIMIT 1];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<status>Active</status>
</ApexClass>
67 changes: 67 additions & 0 deletions force-app/main/default/classes/GGW_ApplicationSelectorTest.cls
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/**
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
* This class contains unit tests for validating the behavior of Apex classes
* and triggers.
*
* Unit tests are class methods that verify whether a particular piece
* of code is working properly. Unit test methods take no arguments,
* commit no data to the database, and are flagged with the testMethod
* keyword in the method definition.
*
* All test methods in an org are executed whenever Apex code is deployed
* to a production org to confirm correctness, ensure code
* coverage, and prevent regressions. All Apex classes are
* required to have at least 75% code coverage in order to be deployed
* to a production org. In addition, all triggers must have some code coverage.
*
* The @isTest class annotation indicates this class only contains test
* methods. Classes defined with the @isTest annotation do not count against
* the org size limit for all Apex scripts.
*
* See the Apex Language Reference for more information about Testing and Code Coverage.
*/
@isTest
private class GGW_ApplicationSelectorTest {

@isTest
static void testQueryGrantApp(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App', sections);

Test.startTest();
GGW_Grant_Application__c grant = GGW_ApplicationSelector.queryGrantApp(app.Id);
Test.stopTest();
System.assertEquals(grant.Name, 'Grant App', 'Could not create a new grant application');

}
@isTest
static void getGrantApplicationsTest(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
// Create 2 grants with same sections top test list
GGW_ApplicationCtrl.newGrant('Grant App 1', sections);
GGW_ApplicationCtrl.newGrant('Grant App 2', sections);

Test.startTest();
List<GGW_Grant_Application__c> grantList = GGW_ApplicationSelector.getGrantApplications();
Test.stopTest();
System.assertEquals(2, grantList.size(), 'Query grant application invalid');
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>58.0</apiVersion>
<status>Active</status>
</ApexClass>
2 changes: 1 addition & 1 deletion force-app/main/default/classes/GGW_ExportCtrl.cls
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public without sharing class GGW_ExportCtrl {
system.debug('### PDF VIew ID:'+this.recordId);
this.appName = 'This view requires a Grant record, missing.';
if(this.recordId != null && this.recordId.length() > 0){
GGW_Grant_Application__c app = GGW_Util.queryGrantApp(this.recordId.escapeHtml4());
GGW_Grant_Application__c app = GGW_ApplicationSelector.queryGrantApp(this.recordId.escapeHtml4());
if(app != null && app.Logo_Download_Url__c != null){
this.logoURL = app.Logo_Download_Url__c;
if(app.Include_Logo__c == true){
Expand Down
6 changes: 0 additions & 6 deletions force-app/main/default/classes/GGW_Util.cls
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ public without sharing class GGW_Util {
WHERE Grant_Application__c =: appId WITH SECURITY_ENFORCED ORDER BY Sort_Order__c];
return items;
}
public static GGW_Grant_Application__c queryGrantApp(String appId){
return [SELECT Id, Name, Application_Name__c, Logo_Download_Url__c,
DistributionPublicUrl__c, Status__c, Description__c, Language__c, Include_Logo__c
FROM GGW_Grant_Application__c
WHERE Id =: appId WITH SECURITY_ENFORCED LIMIT 1];
}
public static Boolean isValidString(String str){
Boolean res = false;
if(str != null && str.length() > 0){
Expand Down
18 changes: 0 additions & 18 deletions force-app/main/default/classes/GGW_UtilTest.cls
Original file line number Diff line number Diff line change
Expand Up @@ -117,24 +117,6 @@ public class GGW_UtilTest {
Test.stopTest();
System.assertEquals(sections.size(), lstItems.size(), 'Grant app missing selected items');

}
@isTest
static void testQueryGrantApp(){
// Query all suggested sections
List<GGW_SectionWrapper> lst = GGW_ApplicationCtrl.getSections();
List<String> sections = new List<String>();
for (GGW_SectionWrapper gww : lst){
if(gww.selected){
sections.add(gww.recordid);
}
}
GGW_Grant_Application__c app = GGW_ApplicationCtrl.newGrant('Grant App', sections);

Test.startTest();
GGW_Grant_Application__c grant = GGW_Util.queryGrantApp(app.Id);
Test.stopTest();
System.assertEquals(grant.Name, 'Grant App', 'Could not create a new grant application');

}
@isTest
static void testSelectOptionFromPicklist(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<template>
<template if:true={showCard}>
<lightning-quick-action-panel header={displayTitle}>

<div>
<!-- <lightning-card title={displayTitle} icon-name="utility:builder"> -->

Expand Down Expand Up @@ -86,6 +87,17 @@ <h3 slot="title" >
</div>
</lightning-layout-item>
</template>
<!-- Grant Selector positioned to right with alignment-bump -->
<lightning-layout-item alignment-bump="left" class="slds-p-right_xx-large">
<lightning-combobox
name="grant"
label="Available Grants"
value={selectedGrant}
placeholder="Select Grant"
options={grantOptions}
onchange={handleGrantChange} ></lightning-combobox>
</lightning-layout-item>

</lightning-layout>
</div>
</template>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
import { LightningElement ,wire , api, track } from "lwc";
import { LightningElement, wire, api, track } from "lwc";
import { CloseActionScreenEvent } from 'lightning/actions';
import { CurrentPageReference, NavigationMixin } from 'lightning/navigation';
import getApplication from '@salesforce/apex/GGW_ApplicationCtrl.getApplication';
import getApplicationList from '@salesforce/apex/GGW_ApplicationCtrl.getApplicationList';
import includeLogo from '@salesforce/apex/GGW_ApplicationCtrl.includeLogo';
import deleteLogo from '@salesforce/apex/GGW_ApplicationCtrl.deleteLogo';
import createContentDistribution from '@salesforce/apex/GGW_ApplicationCtrl.createContentDistribution';
Expand Down Expand Up @@ -46,6 +47,8 @@ export default class GgwGrantApplication extends NavigationMixin(LightningElemen
container = 'modal';
showModalFooter = false;
showCard = true; // Display Editor card if data grant exists ELSE show illustration
grantOptions = []; // List of available Grants for combo box
selectedGrant;

showToastSuccess(msg){
const evt = new ShowToastEvent({
Expand All @@ -64,6 +67,23 @@ export default class GgwGrantApplication extends NavigationMixin(LightningElemen
this.dispatchEvent(evt);
}

@wire(getApplicationList)
grantApplications({ error, data }) {
if (data) {
this.grantOptions = [];
for(let i = 0; i < data.length; i++) {
let grantItem = data[i];
if(grantItem){
this.grantOptions.push({ label: grantItem.Name, value: grantItem.Id });
}
}
this.error = undefined;
} else if (error) {
this.error = error;
this.grantOptions = undefined;
}
}

@wire(CurrentPageReference)
setCurrentPageReference(currentPageReference) {
this.currentPageReference = currentPageReference;
Expand All @@ -78,6 +98,13 @@ export default class GgwGrantApplication extends NavigationMixin(LightningElemen
this.queryGrantApplication();
}

handleGrantChange(event) {
this.selectedGrant = event.detail.value;
this.recordId = this.selectedGrant;
this.displayGrantCard();
this.queryGrantApplication();
}

handleLogoSelectorClick() {
this.logoState = !this.logoState;
includeLogo({recordId: this.recordId, state: this.logoState})
Expand Down

0 comments on commit 4aa7f52

Please sign in to comment.