Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BGE: custom lookup mappings #4082

Merged
merged 24 commits into from
Mar 11, 2019
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
7cc582c
all lookup fields supported in bge
bethbrains Feb 26, 2019
3110299
Verify custom map reference must point to same object
psadie-sfdo Feb 26, 2019
ffca5f9
putting back allowedFields for record type
bethbrains Feb 26, 2019
07ae622
Merge 0dd5a92555a1bb70ea29fde50f381e765a8d623d into feature/bge-any-l…
mrbelvedere Feb 27, 2019
f5a574d
refactor allowed fields to use schema displaytype
bethbrains Feb 28, 2019
890ae4e
make referenceFields attribute private
bethbrains Feb 28, 2019
743724a
resolving merge conflicts
bethbrains Mar 1, 2019
0ac5806
Merge 336c82f38ea9d37dbe47cd21d9bb816c824bb4f9 into feature/bge-any-l…
mrbelvedere Mar 1, 2019
e4090c9
Merge bd1b61d00ee5520deec956645dd89ff5242e6654 into feature/bge-any-l…
mrbelvedere Mar 2, 2019
20a3d0f
Merge 67165b73fbee2dc19e08649ab0cff3134897b9f2 into feature/bge-any-l…
mrbelvedere Mar 4, 2019
739ce0d
Merge 9033414d5d4a1f063c6a9bc772c3fc5dae42425f into feature/bge-any-l…
mrbelvedere Mar 4, 2019
b9fefa1
Merge e2c42466bf568c8b3d569ec46496c12f165326cd into feature/bge-any-l…
mrbelvedere Mar 4, 2019
290bac3
Merge 6cfec78f2cce14d2896a340ce9d11f9c673e8cea into feature/bge-any-l…
mrbelvedere Mar 5, 2019
5d7fe5d
Merge 2b3d2968d9a73b7f35769736e6a7edb452776153 into feature/bge-any-l…
mrbelvedere Mar 6, 2019
630fb64
Merge a79a12cab3b73b2303de0270d78019917ad48ed1 into feature/bge-any-l…
mrbelvedere Mar 6, 2019
ece2fca
iteration to accommodate objects without a Name field
bethbrains Mar 7, 2019
cd9fd5f
Merge 444b7ffab5ea673143eb683f0f04387188f9c562 into feature/bge-any-l…
mrbelvedere Mar 7, 2019
8a3c138
Merge 9aabedd95aae253696a328ef20de145cb4ffa80d into feature/bge-any-l…
mrbelvedere Mar 7, 2019
80498fe
Merge 8e71839df4707ab006c9c439757f093a1918c834 into feature/bge-any-l…
mrbelvedere Mar 8, 2019
54b00f0
Merge c1d610b6775fdb9ba9605219c18d1c850992a696 into feature/bge-any-l…
mrbelvedere Mar 8, 2019
3f06dd7
namespace fix and allow for different-named mapped fields
bethbrains Mar 8, 2019
ef6088a
fix spacing
bethbrains Mar 9, 2019
01a0e2d
Merge add8ce877c0cee64f476d385d52c579023fc8b07 into feature/bge-any-l…
mrbelvedere Mar 11, 2019
d1d1f45
Merge branch 'master' into feature/bge-any-lookup
ptewson-sfdo Mar 11, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<aura:attribute name="data" type="List" default="[]" description="Data Import records that appear in the table" access="public"/>
<aura:attribute name="errors" type="Map" description="Dry run errors to display on the lightning:dataTable" access="public"/>
<aura:attribute name="columns" type="List" description="Columns for the table" access="public"/>
<aura:attribute name="referenceFields" type="List" description="Reference fields used in this batch" access="public"/>
<aura:attribute name="labels" type="Map" description="Labels retrieved in Apex related to Schema information." access="public"/>
<aura:attribute name="dataImportFields" type="Object[]" default="[]" description="List of Data Import fields to use in the new row component." access="public"/>
<aura:attribute name="donorType" type="String" default="Contact1" description="Used to circumvent unhelpful labeling of Account1/Contact1" access="public"/>
Expand Down
34 changes: 22 additions & 12 deletions src/aura/BGE_DataImportBatchEntry/BGE_DataImportBatchEntryHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
*/
setColumns: function(component, dataColumns) {
var columns = [];
var referenceFields = [];
columns.push({
label: 'Donor',
fieldName: 'donorLink',
Expand All @@ -60,6 +61,8 @@
editable: !col.readOnly,
typeAttributes: JSON.parse(col.typeAttributes)
});
} else {
referenceFields.push(col.fieldName);
}
});

Expand All @@ -82,6 +85,7 @@
});

component.set('v.columns', columns);
component.set('v.referenceFields', referenceFields);
},

/**
Expand Down Expand Up @@ -186,10 +190,9 @@
setDataTableRows: function(component, baseRows, responseRows) {
let rows = [];
let errors = [];
let namespace = component.get('v.labels.namespacePrefix');

for (let i=0; i<responseRows.length; i++) {
const row = this.flattenDataImportRow(namespace, responseRows[i]);
const row = this.flattenDataImportRow(component, responseRows[i]);
rows.push(row);

//get payment and opportunity error information if import failed
Expand Down Expand Up @@ -275,8 +278,7 @@
* @param isNewRecord: flag to indicate if record needs to be inserted or replaced
*/
updateDataTableAfterDryRun: function (component, updatedRecord, isNewRecord) {
let namespace = component.get('v.labels.namespacePrefix');
let tableRow = this.flattenDataImportRow(namespace, updatedRecord);
let tableRow = this.flattenDataImportRow(component, updatedRecord);
let hasError = false;

//get payment and opportunity error information if import failed
Expand Down Expand Up @@ -547,20 +549,28 @@
* @param currentRow: custom DataImportRow class data passed from the Apex controller.
* @return Object row
*/
flattenDataImportRow: function(namespace, currentRow) {
flattenDataImportRow: function(component, currentRow) {
const referenceFields = component.get('v.referenceFields');

let row = currentRow.record;
row.donorName = currentRow.donorName;
row.donorLink = currentRow.donorLink;
row.matchedRecordUrl = currentRow.matchedRecordUrl;
row.matchedRecordLabel = currentRow.matchedRecordLabel;
row.errors = currentRow.errors;
// reformat lookup info to display as a url in datatable
if (row[namespace + 'DonationCampaignImported__c']) {
let campaignLinkFieldLabel = namespace + 'DonationCampaignImported__clabel';
let campaignLinkFieldName = namespace + 'DonationCampaignImported__clink';
row[campaignLinkFieldLabel] = row[namespace + 'DonationCampaignImported__r'].Name;
row[campaignLinkFieldName] = '/' + row[namespace + 'DonationCampaignImported__c'];
}

// reformat lookups to display as links in datatable
referenceFields.forEach(function(fieldName) {
if (row[fieldName]) {
let campaignLinkFieldLabel = fieldName + '_label';
let campaignLinkFieldName = fieldName + '_link';
//TODO: is this the easiest way to do this string manipulation?
let relationshipName = fieldName.slice(0, -1) + 'r';
row[campaignLinkFieldLabel] = row[relationshipName].Name;
row[campaignLinkFieldName] = '/' + row[fieldName];
}
});

return row;
},

Expand Down
20 changes: 11 additions & 9 deletions src/classes/BGE_ConfigurationWizard_CTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ public with sharing class BGE_ConfigurationWizard_CTRL {
*/
public static List<Schema.DescribeFieldResult> getRelevantFields(Set<String> allowedObjects) {

Map<String, Schema.DescribeFieldResult> dfrMap = new Map<String, Schema.DescribeFieldResult>();
Map<String, Schema.DescribeFieldResult> filteredDFRMap = new Map<String, Schema.DescribeFieldResult>();

Map<String, Schema.DescribeFieldResult> fieldMap =
Map<String, Schema.DescribeFieldResult> allFieldsMap =
UTIL_Describe.getAllFieldsDescribe(UTIL_Namespace.StrTokenNSPrefix('DataImport__c'));

Set<String> bannedFields = new Set<String>{
Expand Down Expand Up @@ -191,38 +191,40 @@ public with sharing class BGE_ConfigurationWizard_CTRL {
'EMAIL',
'MULTIPICKLIST',
'PHONE',
'URL'
'URL',
'REFERENCE'
};

// these fields have been whitelisted since they have special handling in BDI
Set<String> allowedFields = new Set<String>{
'DonationCampaignImported__c'
'Donation_Record_Type_Name__c'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern is no longer needed for DonationCampaignImported__c, but is still needed for Donation Record Type, which came in a separate sibling branch. Added it here so it wasn't an empty set in this branch.

};

// looping through the fields on DataImport__c and remove unsupported data types
for (Schema.DescribeFieldResult dfr : fieldMap.values()) {
for (Schema.DescribeFieldResult dfr : allFieldsMap.values()) {
String dataImportFieldApiName = UTIL_Namespace.StrTokenRemoveNSPrefix(dfr.getName());

String dataImportFieldMappedObject = BDI_DataImportService.getTargetObject(dfr.getName());

Boolean fieldAllowed = (allowedObjects.contains(dataImportFieldMappedObject)
&& allowedDataTypes.contains(dfr.getType().name())
&& !bannedFields.contains(dataImportFieldApiName)
&& dfr.getInlineHelpText() != null)
|| allowedFields.contains(dataImportFieldApiName);

if (fieldAllowed) {
dfrMap.put(dfr.label, dfr);
filteredDFRMap.put(dfr.label, dfr);
}
}

BGE_BatchGiftEntry_UTIL.checkFieldPermissions(dfrMap.values());
BGE_BatchGiftEntry_UTIL.checkFieldPermissions(filteredDFRMap.values());

List<String> sortedFieldLabels = new List<String>(dfrMap.keySet());
List<String> sortedFieldLabels = new List<String>(filteredDFRMap.keySet());
sortedFieldLabels.sort();

List<Schema.DescribeFieldResult> sortedDFRs = new List<Schema.DescribeFieldResult>();
for (String fieldLabel : sortedFieldLabels) {
sortedDFRs.add(dfrMap.get(fieldLabel));
sortedDFRs.add(filteredDFRMap.get(fieldLabel));
}

return sortedDFRs;
Expand Down
48 changes: 25 additions & 23 deletions src/classes/BGE_DataImportBatchEntry_CTRL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ public with sharing class BGE_DataImportBatchEntry_CTRL {
'donationAmountField' => Schema.SObjectType.DataImport__c.fields.Donation_Amount__c.getName(),
'expectedCountField' => Schema.SObjectType.DataImportBatch__c.fields.Expected_Count_of_Gifts__c.getName(),
'expectedTotalField' => Schema.SObjectType.DataImportBatch__c.fields.Expected_Total_Batch_Amount__c.getName(),
'namespacePrefix' => UTIL_Namespace.StrTokenNSPrefix(''),
'noDataImportsFound' => String.format(Label.stgNoObjectsFound, new List<String>{Schema.SObjectType.DataImport__c.getName()}),
'opportunityImportedLookupField' => Schema.SObjectType.DataImport__c.fields.DonationImported__c.getName(),
'opportunityImportedStatusField' => Schema.SObjectType.DataImport__c.fields.DonationImportStatus__c.getName(),
Expand Down Expand Up @@ -347,40 +346,43 @@ public with sharing class BGE_DataImportBatchEntry_CTRL {
if (dataImportDFR != null) {

if (UTIL_Permissions.canUpdate(dataImportDFR, false)) {
String targetObject = BDI_DataImportService.getTargetObject(dataImportDFR.name);
String targetField = BDI_DataImportService.getTargetField(dataImportDFR.name);
DescribeFieldResult targetDFR = UTIL_Describe.getFieldDescribe(targetObject, targetField);

Column col = new Column();

col.label = dataImportDFR.getLabel();
col.fieldName = dataImportDFR.getName();
col.label = dataImportDFR.label;
col.fieldName = dataImportDFR.name;
col.defaultValue = field.defaultValue;
col.required = field.requiredInEntryForm;
col.hide = field.hide;
col.type = UTIL_LightningComponentSupport.getLightningDataTableDataType(dataImportDFR.getType());
col.type = UTIL_LightningComponentSupport.getLightningDataTableDataType(dataImportDFR.type);
// lookups aren't editable in the grid since we don't have lookup support there
col.readOnly = col.type == 'reference' ? true : false;
col.typeAttributes = '{}';
col.options = BGE_BatchGiftEntry_UTIL.getPicklistOptions(col.fieldName);

columns.add(col);

if (dataImportDFR.getType().name() == 'reference') {
// manually construct EXTRA column for campaign link
Column linkCol = new Column();
linkCol.label = dataImportDFR.getLabel();
String fieldLabel = dataImportDFR.name + 'label';
String fieldName = dataImportDFR.name + 'link';
linkCol.fieldName = fieldName;
linkCol.readOnly = true;
linkCol.required = field.requiredInEntryForm;
linkCol.type = 'url';
linkCol.typeAttributes = '{"label":{"fieldName":"'+fieldLabel+'"},"target":"_blank"}';
columns.add(linkCol);

if (dataImportDFR.type == Schema.DisplayType.Reference) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁

if (targetDFR.getReferenceTo() == dataImportDFR.getReferenceTo()) {
// manually construct EXTRA column for lookup link
Column linkCol = new Column();
linkCol.label = dataImportDFR.getLabel();
String fieldLabel = dataImportDFR.name + '_label';
String fieldName = dataImportDFR.name + '_link';
linkCol.fieldName = fieldName;
linkCol.readOnly = true;
linkCol.required = field.requiredInEntryForm;
linkCol.type = 'url';
linkCol.typeAttributes = '{"label":{"fieldName":"' + fieldLabel + '"},"target":"_blank"}';

columns.add(linkCol);
columns.add(col);
}
} else {
columns.add(col);
}

String targetObject = BDI_DataImportService.getTargetObject(col.fieldName);
String targetField = BDI_DataImportService.getTargetField(col.fieldName);
DescribeFieldResult targetDFR = UTIL_Describe.getFieldDescribe(targetObject,targetField);

if (!UTIL_Permissions.canUpdate(targetDFR, false)) {
unpermittedFields.add(targetDFR);
}
Expand Down