Skip to content

Commit

Permalink
Automatically select the default field set in LWC relatedLogEntries (#…
Browse files Browse the repository at this point in the history
…602)

* Added new LoggerParameter__mdt record DefaultLogEntryRelatedListFieldSet to control what LogEntry__c field set is used by default in App Builder

* Updated LogEntryFieldSetPicklist to return a default instance of VisualEditor.DataRow, based on LoggerParameter.DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET

* Updated sf cli to v2.24.4 to try to (yet again X 100) resolve a pipeline error about the Admin profile being removed (it hasn't, and it's not included in the packages anyway), and commented out the create-managed-package-version stage in build.yml, because the sf cli continues to be endlessly problematic
  • Loading branch information
jongpie authored Jan 20, 2024
1 parent b24d1f5 commit c1aeecd
Show file tree
Hide file tree
Showing 14 changed files with 19,783 additions and 11,650 deletions.
82 changes: 42 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,46 +264,48 @@ jobs:
runs-on: ubuntu-latest
environment: 'Demo Org'
steps:
- name: 'Checkout source code'
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: 'Restore node_modules cache'
id: cache-npm
uses: actions/cache@v3
with:
path: node_modules
key: npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-${{ env.cache-name }}-
npm-
- name: 'Install npm dependencies'
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci

- name: 'Authorize Dev Hub'
shell: bash
run: |
npx sf version
echo "${{ env.DEV_HUB_JWT_SERVER_KEY }}" > ./jwt-server.key
npx sf org login jwt --instance-url ${{ env.DEV_HUB_AUTH_URL }} --client-id ${{ env.DEV_HUB_CONSUMER_KEY }} --username ${{ env.DEV_HUB_BOT_USERNAME }} --jwt-key-file ./jwt-server.key --set-default-dev-hub
env:
DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }}
DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }}
DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }}
DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }}

# TODO remove this after the plugin @salesforce/packaging has been upgraded
# to a new version that only looks at package directories
- name: 'Temporarily delete problematic metadata'
run: |
rm -rf ./config/experience-cloud/
rm -rf ./nebula-logger/unsorted/main/default/profiles/
- name: 'Create Beta Managed Package Version'
run: npm run package:version:create:managed
# - name: 'Checkout source code'
# uses: actions/checkout@v3
# with:
# ref: ${{ github.event.pull_request.head.ref }}

# - name: 'Restore node_modules cache'
# id: cache-npm
# uses: actions/cache@v3
# with:
# path: node_modules
# key: npm-${{ hashFiles('**/package-lock.json') }}
# restore-keys: |
# npm-${{ env.cache-name }}-
# npm-

# - name: 'Install npm dependencies'
# if: steps.cache-npm.outputs.cache-hit != 'true'
# run: npm ci

# - name: 'Authorize Dev Hub'
# shell: bash
# run: |
# npx sf version
# echo "${{ env.DEV_HUB_JWT_SERVER_KEY }}" > ./jwt-server.key
# npx sf org login jwt --instance-url ${{ env.DEV_HUB_AUTH_URL }} --client-id ${{ env.DEV_HUB_CONSUMER_KEY }} --username ${{ env.DEV_HUB_BOT_USERNAME }} --jwt-key-file ./jwt-server.key --set-default-dev-hub
# env:
# DEV_HUB_AUTH_URL: ${{ secrets.DEV_HUB_AUTH_URL }}
# DEV_HUB_BOT_USERNAME: ${{ secrets.DEV_HUB_BOT_USERNAME }}
# DEV_HUB_CONSUMER_KEY: ${{ secrets.DEV_HUB_CONSUMER_KEY }}
# DEV_HUB_JWT_SERVER_KEY: ${{ secrets.DEV_HUB_JWT_SERVER_KEY }}

# # TODO remove this after the plugin @salesforce/packaging has been upgraded
# # to a new version that only looks at package directories
# - name: 'Temporarily delete problematic metadata'
# run: |
# rm -rf ./config/experience-cloud/

# - name: 'Create Beta Managed Package Version'
# run: npm run package:version:create:managed

- name: 'Placeholder because the sf cli and its plugins are trash'
run: echo hello

create-unlocked-package-release-candidate:
name: 'Create Core Package Release Candidate'
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

The most robust logger for Salesforce. Works with Apex, Lightning Components, Flow, Process Builder & Integrations. Designed for Salesforce admins, developers & architects.

## Unlocked Package - v4.12.0
## Unlocked Package - v4.12.2

[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001Mk4bQAC)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001Mk4bQAC)
[![Install Unlocked Package in a Sandbox](./images/btn-install-unlocked-package-sandbox.png)](https://test.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001Mk55QAC)
[![Install Unlocked Package in Production](./images/btn-install-unlocked-package-production.png)](https://login.salesforce.com/packaging/installPackage.apexp?p0=04t5Y000001Mk55QAC)
[![View Documentation](./images/btn-view-documentation.png)](https://jongpie.github.io/NebulaLogger/)

`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Mk4bQAC`
`sf package install --wait 20 --security-type AdminsOnly --package 04t5Y000001Mk55QAC`

`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Mk4bQAC`
`sfdx force:package:install --wait 20 --securitytype AdminsOnly --package 04t5Y000001Mk55QAC`

---

Expand Down
4 changes: 4 additions & 0 deletions docs/apex/Configuration/LoggerParameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ Provides a centralized way to load parameters for SObject handlers & plugins

Indicates if Nebula Logger will make an async callout to `https://api.status.salesforce.com` to get additional details about the current org, which is then stored on the Log\_\_c record. Controlled by the custom metadata record `LoggerParameter.CallStatusApi`, or `false` as the default

#### `DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET``String`

The name of the `LogEntry__c` field set to use as the default field set when configuring the LWC `<c-related-log-entries>` within App Builder. Controlled by the custom metadata record `LoggerParameter.DefaultLogEntryRelatedListFieldSet`, or `Related_List_Defaults` as the default

#### `ENABLE_LOG_ENTRY_EVENT_STREAM``Boolean`

Indicates if Nebula Logger's LWC `logEntryEventStream` is enabled. The component uses the Emp API, which counts towards orgs' daily delivery allocations for platform events. To help reduce usage of the daily allocation limit, orgs can disable the LWC. Controlled by the custom metadata record `LoggerParameter.EnableLogEntryEventStream`, or `true` as the default
Expand Down
4 changes: 2 additions & 2 deletions docs/apex/Log-Management/LogEntryFieldSetPicklist.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Dynamically returns `LogEntry__c` field sets in App Builder when configuring the

#### `getDefaultValue()``VisualEditor.DataRow`

Returns a default value of null - admins must select a field set within App Builder
Returns the default `LogEntry__c` field set, based on the `LoggerParameter_t` record `DefaultLogEntryRelatedListFieldSet`

##### Return

Expand All @@ -22,7 +22,7 @@ VisualEditor.DataRow

**Description**

null (no default value)
And instance of `VisualEditor.DataRow` if a valid, matching field set exists, or `null`

#### `getValues()``VisualEditor.DynamicPickListRows`

Expand Down
17 changes: 17 additions & 0 deletions nebula-logger/core/main/configuration/classes/LoggerParameter.cls
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ public class LoggerParameter {
private set;
}

/**
* @description The name of the `LogEntry__c` field set to use as the default field set when configuring
* the LWC `<c-related-log-entries>` within App Builder.
* Controlled by the custom metadata record `LoggerParameter.DefaultLogEntryRelatedListFieldSet`,
* or `Related_List_Defaults` as the default
*/
public static final String DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET {
get {
if (DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET == null) {
String configuredValue = getString('DefaultLogEntryRelatedListFieldSet', 'Related_List_Defaults');
DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET = String.isNotBlank(configuredValue) ? configuredValue : '';
}
return DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET;
}
private set;
}

/**
* @description Indicates if Nebula Logger's LWC `logEntryEventStream` is enabled. The component uses
* the Emp API, which counts towards orgs' daily delivery allocations for platform events.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomMetadata
xmlns="http://soap.sforce.com/2006/04/metadata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<label>Default Log Entry Related List Field Set</label>
<protected>false</protected>
<values>
<field>Description__c</field>
<value
xsi:type="xsd:string"
>The name of the LogEntry__c field set to use as the default field set when configuring the LWC &lt;c-related-log-entries&gt; within App Builder.

By default, the included field set partition &apos;Related_List_Defaults&apos; is used.</value>
</values>
<values>
<field>Value__c</field>
<value xsi:type="xsd:string">Related_List_Defaults</value>
</values>
</CustomMetadata>
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
*/
public without sharing class LogEntryFieldSetPicklist extends VisualEditor.DynamicPickList {
/**
* @description Returns a default value of null - admins must select a field set within App Builder
* @return null (no default value)
* @description Returns the default `LogEntry__c` field set, based on the `LoggerParameter__mdt` record `DefaultLogEntryRelatedListFieldSet`
* @return And instance of `VisualEditor.DataRow` if a valid, matching field set exists, or `null`
*/
public override VisualEditor.DataRow getDefaultValue() {
return null;
if (String.isBlank(LoggerParameter.DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET)) {
return null;
}

Schema.FieldSet configuredFieldSet = Schema.SObjectType.LogEntry__c.fieldSets.getMap().get(LoggerParameter.DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET);
return configuredFieldSet == null ? null : this.createDataRow(configuredFieldSet);
}

/**
Expand All @@ -26,12 +31,14 @@ public without sharing class LogEntryFieldSetPicklist extends VisualEditor.Dynam

List<Schema.FieldSet> fieldSets = Schema.SObjectType.LogEntry__c.fieldSets.getMap().values();
for (Schema.FieldSet fieldSet : fieldSets) {
String namespacePrefix = String.isBlank(fieldSet.getNameSpace()) ? '' : fieldSet.getNameSpace() + '__';

VisualEditor.DataRow picklistRow = new VisualEditor.DataRow(fieldSet.getLabel(), namespacePrefix + fieldSet.getName());
picklistRows.addRow(picklistRow);
picklistRows.addRow(this.createDataRow(fieldSet));
}

return picklistRows;
}

private VisualEditor.DataRow createDataRow(Schema.FieldSet fieldSet) {
String namespacePrefix = String.isBlank(fieldSet.getNameSpace()) ? '' : fieldSet.getNameSpace() + '__';
return new VisualEditor.DataRow(fieldSet.getLabel(), namespacePrefix + fieldSet.getName());
}
}
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/classes/Logger.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
global with sharing class Logger {
// There's no reliable way to get the version number dynamically in Apex
@TestVisible
private static final String CURRENT_VERSION_NUMBER = 'v4.12.0';
private static final String CURRENT_VERSION_NUMBER = 'v4.12.2';
private static final System.LoggingLevel FALLBACK_LOGGING_LEVEL = System.LoggingLevel.DEBUG;
private static final Set<String> IGNORED_APEX_CLASSES = initializeIgnoredApexClasses();
private static final List<LogEntryEventBuilder> LOG_ENTRIES_BUFFER = new List<LogEntryEventBuilder>();
Expand Down
2 changes: 1 addition & 1 deletion nebula-logger/core/main/logger-engine/lwc/logger/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { LightningElement, api } from 'lwc';
import { createLoggerService } from './loggerService';

const CURRENT_VERSION_NUMBER = 'v4.12.0';
const CURRENT_VERSION_NUMBER = 'v4.12.2';

export default class Logger extends LightningElement {
#loggerService = createLoggerService();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ private class LoggerParameter_Tests {
System.Assert.areEqual(mockValue, returnedValue);
}

@IsTest
static void it_should_return_constant_value_for_default_log_entry_related_list_field_set() {
String mockValue = 'SomeValue';
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(DeveloperName = 'DefaultLogEntryRelatedListFieldSet', Value__c = mockValue);
LoggerParameter.setMock(mockParameter);

String returnedValue = LoggerParameter.DEFAULT_LOG_ENTRY_RELATED_LIST_FIELD_SET;

System.Assert.areEqual(mockValue, returnedValue);
}

@IsTest
static void it_should_return_constant_value_for_enable_log_entry_event_stream() {
Boolean mockValue = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,67 @@
// See LICENSE file or go to https://github.com/jongpie/NebulaLogger for full license details. //
//------------------------------------------------------------------------------------------------//

@SuppressWarnings('PMD.ApexDoc, PMD.CyclomaticComplexity, PMD.ExcessiveParameterList, PMD.MethodNamingConventions, PMD.NcssMethodCount')
@SuppressWarnings('PMD.ApexDoc, PMD.MethodNamingConventions')
@IsTest(IsParallel=true)
private class LogEntryFieldSetPicklist_Tests {
@IsTest
static void it_should_return_null_for_default_value() {
// Admins should choose a field set, so always return null for the default
System.Test.startTest();
static void it_should_return_null_for_default_value_when_empty_value_is_configured() {
String emptyFieldSetName = '';
Schema.FieldSet expectedFieldSet = Schema.SObjectType.LogEntry__c.fieldSets.getMap().get(emptyFieldSetName);
System.Assert.isNull(expectedFieldSet);
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(DeveloperName = 'DefaultLogEntryRelatedListFieldSet', Value__c = emptyFieldSetName);
LoggerParameter.setMock(mockParameter);

LogEntryFieldSetPicklist instance = new LogEntryFieldSetPicklist();

System.Assert.isNull(instance.getDefaultValue());
}

@IsTest
static void it_should_return_null_for_default_value_when_invalid_value_is_configured() {
String invalidFieldSetName = 'Some value that definitely cannot exist';
Schema.FieldSet expectedFieldSet = Schema.SObjectType.LogEntry__c.fieldSets.getMap().get(invalidFieldSetName);
System.Assert.isNull(expectedFieldSet);
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(DeveloperName = 'DefaultLogEntryRelatedListFieldSet', Value__c = invalidFieldSetName);
LoggerParameter.setMock(mockParameter);

LogEntryFieldSetPicklist instance = new LogEntryFieldSetPicklist();
System.Test.stopTest();

System.Assert.isNull(instance.getDefaultValue());
}

@IsTest
static void it_should_return_non_null_for_default_value_when_valid_value_is_configured() {
String namespacePrefix = String.isBlank(Logger.getNamespacePrefix()) ? '' : Logger.getNamespacePrefix() + '__';
String validFieldSetName = namespacePrefix + 'Related_List_Defaults';
Schema.FieldSet expectedFieldSet = Schema.SObjectType.LogEntry__c.fieldSets.getMap().get(validFieldSetName);
System.Assert.isNotNull(expectedFieldSet);
LoggerParameter__mdt mockParameter = new LoggerParameter__mdt(DeveloperName = 'DefaultLogEntryRelatedListFieldSet', Value__c = validFieldSetName);
LoggerParameter.setMock(mockParameter);

LogEntryFieldSetPicklist instance = new LogEntryFieldSetPicklist();

System.Assert.isNotNull(instance.getDefaultValue());
System.Assert.areEqual(expectedFieldSet.getLabel(), instance.getDefaultValue().getLabel());
System.Assert.areEqual(namespacePrefix + expectedFieldSet.getName(), instance.getDefaultValue().getValue());
}

@IsTest
static void it_should_return_all_field_sets_as_values() {
Map<String, Schema.FieldSet> expectedFieldSets = Schema.SObjectType.LogEntry__c.fieldSets.getMap();

System.Test.startTest();
LogEntryFieldSetPicklist instance = new LogEntryFieldSetPicklist();
System.Test.stopTest();

List<VisualEditor.DataRow> dataRows = instance.getValues().getDataRows();
System.Assert.areEqual(expectedFieldSets.size(), dataRows.size());
for (VisualEditor.DataRow dataRow : dataRows) {
String fieldSetName = (String) dataRow.getValue();
String fieldSetLabel = (String) dataRow.getLabel();

System.Assert.isTrue(expectedFieldSets.containsKey(fieldSetName));

Schema.FieldSet fieldSet = expectedFieldSets.get(fieldSetName);
System.Assert.areEqual(fieldSet.getLabel(), fieldSetLabel);
String dataRowLabel = (String) dataRow.getLabel();
String dataRowValue = (String) dataRow.getValue();
System.Assert.isTrue(expectedFieldSets.containsKey(dataRowValue));
Schema.FieldSet matchingFieldSet = expectedFieldSets.get(dataRowValue);
String matchingFieldSetNamespacePrefix = String.isBlank(matchingFieldSet.getNameSpace()) ? '' : matchingFieldSet.getNameSpace() + '__';
System.Assert.areEqual(matchingFieldSet.getLabel(), dataRowLabel);
System.Assert.areEqual(matchingFieldSetNamespacePrefix + matchingFieldSet.getName(), dataRowValue);
}
}
}
Loading

0 comments on commit c1aeecd

Please sign in to comment.