Skip to content

Commit

Permalink
Jkranz rk/issue18 (#19) (#20)
Browse files Browse the repository at this point in the history
* Setting "Show Description" toggle 
to False in CPE doesn't save attribute to Flow Properties
Fixes #18

See discussion on issue.
Flow Builder Runtime will send Strings instead
of Boolean values to CPE, so this update transforms
those strings to Booleans, and then back again.

Also changed the approach, using "hideDescription" with a default of False
instead of "showDescription" with a default
of True. Bad practice to use true as default
for Element attributes, so flipped that.

This is an "under the hood" change, as
CPE UI still presents as "Show Description"
because from the User perspective, it feels
more natural to be active when you are showing
the descriptions, and then toggle off to hide

* Added an icon. Pretty!

* Created a separate scratch org def file
for spinning up a test install during package testing

* bump to v0.3!
  • Loading branch information
jkranz-rk authored Sep 23, 2022
1 parent 4e7bb3b commit afb6e6b
Show file tree
Hide file tree
Showing 13 changed files with 124 additions and 45 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ NOTE ABOUT THE TEST DIRECTORY: the "test" directory is _not_ needed for sandbox

## Latest Released Unlocked Package Install URL

`/packaging/installPackage.apexp?p0=04t4x000000RUUUAA4`
`/packaging/installPackage.apexp?p0=04t4x000000RqyHAAS`

## Display Types

Expand Down
5 changes: 5 additions & 0 deletions config/project-scratch-installtesting.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"orgName": "RecordType Picker Install Testing",
"edition": "Enterprise",
"features": []
}
16 changes: 11 additions & 5 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,36 @@
"path": "src",
"default": true,
"package": "Record Type Picker",
"versionName": "ver 0.1",
"versionNumber": "0.1.0.NEXT",
"versionName": "ver 0.3",
"versionNumber": "0.3.0.NEXT",
"unpackagedMetadata": {
"path": "tests"
},
"apexTestAccess": {
"permissionSets": [
"RecordTypePickerPermissionsTesting"
]
}
},
"releaseNotesUrl": "https://github.com/jkranz-rk/RecordTypePicker",
"postInstallUrl": "https://github.com/jkranz-rk/RecordTypePicker"
},
{
"path": "tests"
}
],
"name": "RecordTypePicker",
"namespace": "",
"namespace": "rtp",
"sfdcLoginUrl": "https://login.salesforce.com",
"sourceApiVersion": "55.0",
"packageAliases": {
"Record Type Picker": "0Ho4x000000GmwBCAS",
"Record Type [email protected]/unlockedpackaging": "04t4x000000RUQ2AAO",
"Record Type [email protected]/unlockedpackaging": "04t4x000000RUQ7AAO",
"Record Type [email protected]/unlockedpackaging": "04t4x000000RUQCAA4",
"Record Type [email protected]": "04t4x000000RUUUAA4"
"Record Type [email protected]": "04t4x000000RUUUAA4",
"Record Type [email protected]": "04t4x000000RqffAAC",
"Record Type [email protected]": "04t4x000000RqfkAAC",
"Record Type [email protected]": "04t4x000000RqyCAAS",
"Record Type [email protected]": "04t4x000000RqyHAAS"
}
}
2 changes: 2 additions & 0 deletions src/main/default/classes/RecordTypePickerController.cls
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ global with sharing class RecordTypePickerController {
@InvocableMethod(
label='Record Types for Running User'
description='Input an Object\'s API name, returns a collection of Record Types that are available to the running user'
category='Record Types'
iconName='slds:standard:relationship'
)
/**
*/
Expand Down
22 changes: 18 additions & 4 deletions src/main/default/lwc/cpeHelper/cpeHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ const flowConstants = {
}
};

const convertBooleanFlowToReal = (boolVal) => {
if (boolVal === '$GlobalConstant.True') {
return true;
} else if (boolVal === '$GlobalConstant.False') {
return false;
} else {
return boolVal;
}
};

const convertBooleanRealToFlow = (boolVal) => {
return boolVal ? '$GlobalConstant.True' : '$GlobalConstant.False';
};

const defaultProperties = {
objectApiName : {
name : 'objectApiName',
Expand All @@ -49,9 +63,9 @@ const defaultProperties = {
value : 'picker',
valueDataType : 'String'
},
showDescription : {
name : 'showDescription',
value : true,
hideDescriptions : {
name : 'hideDescriptions',
value : false,
valueDataType : 'Boolean'
},
autoNavigateNext : {
Expand All @@ -61,4 +75,4 @@ const defaultProperties = {
}
};

export {notifyPropertyChange, flowConstants, defaultProperties};
export {notifyPropertyChange, flowConstants, defaultProperties, convertBooleanFlowToReal, convertBooleanRealToFlow};
30 changes: 17 additions & 13 deletions src/main/default/lwc/recordTypePicker/recordTypePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@ export default class RecordTypePicker extends LightningElement {
@api availableRecordTypes;

@api objectApiName;
@api label;

@api
get label(){
return this._label;
}
set label(val){
this._label = val;
}
_label = 'Select a RecordType';
_label = 'Select a Record Type';

@api autoNavigateNext;
@api
get autoNavigateNext(){
return this._autoNavigateNext;
}
Expand All @@ -33,16 +34,16 @@ export default class RecordTypePicker extends LightningElement {
}
_autoNavigateNext = false;

@api showDescription;
get showDescription(){
return this._showDescription;
@api
get hideDescriptions(){
return this._hideDescriptions;
}
set showDescription(val){
this._showDescription = val;
set hideDescriptions(val){
this._hideDescriptions = val;
}
_showDescription = true;
_hideDescriptions;

@api displayType;
@api
get displayType(){
return this._displayType;
}
Expand All @@ -51,7 +52,7 @@ export default class RecordTypePicker extends LightningElement {
}
_displayType = 'picker';

@api mode;
@api
get mode(){
return this._mode;
}
Expand All @@ -60,6 +61,10 @@ export default class RecordTypePicker extends LightningElement {
}
_mode = 'live';

// deprecated in favor of hideDescriptions, since we want the default
// value to be `True`, its a bad practice to set boolean defaults to `True`
@api showDescription;

_error;
_selectedValue;

Expand Down Expand Up @@ -108,7 +113,7 @@ export default class RecordTypePicker extends LightningElement {
};

get picklistOptions(){
if (this.showDescription){
if (!this.hideDescriptions){
return this.availableRecordTypes.map((rt) => {
return {
value: rt.Id,
Expand All @@ -124,7 +129,6 @@ export default class RecordTypePicker extends LightningElement {
};
});
}

}

handleChange(event){
Expand Down
20 changes: 14 additions & 6 deletions src/main/default/lwc/recordTypePicker/recordTypePicker.js-meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<targetConfigs>
<targetConfig
targets="lightning__FlowScreen"
configurationEditor="rtp-record-type-picker-cpe">
configurationEditor="rtp-record-type-picker-cpe">
<property
name="objectApiName"
type="String"
Expand All @@ -23,7 +23,7 @@
type="String"
label="Label"
description="Label to display above the selection. Defaults to 'Select a Record Type'"
default="Select a RecordType"
default="Select a Record Type"
role="inputOnly"
/>
<property
Expand All @@ -41,11 +41,11 @@
role="inputOnly"
/>
<property
name="showDescription"
name="hideDescriptions"
type="Boolean"
label="Show Descriptions"
description="Set to TRUE to display each Record Type's Description"
default="true"
label="Hide Descriptions"
description="Set to TRUE to hide the Record Types' Descriptions"
default="false"
role="inputOnly"
/>
<property
Expand All @@ -56,6 +56,14 @@
description="Choose how to display the Record Type Picker: picker, radio, or picklist. Defaults to picker"
role="inputOnly"
/>
<property
name="showDescription"
type="Boolean"
label="DEPRECATED"
description="DEPRECATED"
default="true"
role="inputOnly"
/>
</targetConfig>
</targetConfigs>
</LightningComponentBundle>
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<label class="slds-radio__label slds-grid" for={recordType.Id}>
<span class="slds-radio_faux slds-m-top_xxx-small"></span>
<span class="slds-form-element__label slds-p-top_none">
<template if:true={showDescription}>
<template if:false={hideDescriptions}>
<lightning-layout multiple-rows class="slds-m-bottom_x-small">
<lightning-layout-item size="12" flexibility="auto" class="slds-p-left_none">
<strong>{recordType.Name}</strong>
Expand All @@ -19,7 +19,7 @@
</lightning-layout-item>
</lightning-layout>
</template>
<template if:false={showDescription}>
<template if:true={hideDescriptions}>
{recordType.Name}
</template>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<span class="slds-text-heading_medium slds-m-bottom_x-small">
{recordType.Name}
</span>
<span if:true={showDescription} class="slds-text-title">
<span if:false={hideDescriptions} class="slds-text-title">
{recordType.Description}
</span>
</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h2 class="slds-card__header-title">
object-api-name={previewConfig.objectApiName.value}
mode="preview"
class="preview"
show-description={previewConfig.showDescription.value} >
hide-descriptions={previewConfig.hideDescriptions.value} >
</c-record-type-picker>
</template>
</div>
Expand Down
50 changes: 43 additions & 7 deletions src/main/default/lwc/recordTypePickerCpe/recordTypePickerCpe.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
import { api, LightningElement, track } from 'lwc';
import { defaultProperties } from 'c/cpeHelper';
import {
defaultProperties,
convertBooleanRealToFlow,
convertBooleanFlowToReal
} from 'c/cpeHelper';

export default class RecordTypePickerCpe extends LightningElement {
@api
get allInputVariables(){
return this._allInputVariables;
}
set allInputVariables(val){
this._allInputVariables = val;
}
@track _allInputVariables;

@api
get inputVariables(){
return this._inputVariables;
}
set inputVariables(val){
this._inputVariables = val;
}
_inputVariables;
@track _inputVariables;

@api
get builderContext(){
Expand All @@ -18,7 +31,16 @@ export default class RecordTypePickerCpe extends LightningElement {
set builderContext(val){
this._builderContext = val;
}
_builderContext;
@track _builderContext;

@api
get automaticOutputVariables(){
return this._automaticOutputVariables;
}
set automaticOutputVariables(val){
this._automaticOutputVariables = val;
}
@track _automaticOutputVariables;

@api
get elementInfo(){
Expand All @@ -27,7 +49,7 @@ export default class RecordTypePickerCpe extends LightningElement {
set elementInfo(val){
this._elementInfo = val;
}
_elementInfo;
@track _elementInfo;

@track
configuration = {...defaultProperties};
Expand All @@ -43,9 +65,16 @@ export default class RecordTypePickerCpe extends LightningElement {
}

this._inputVariables.forEach( input => {
this.configuration[input.name] = {...input};
let cleanedInput = {...input};
if (input.valueDataType === 'Boolean') { // transpose '$GlobalConstant strings to Booleans
cleanedInput.value = convertBooleanFlowToReal(input.value);
}
if (input.name === 'showDescription') { //convert deprecated showDescription attribute to new hideDescriptions attribute
cleanedInput.name = 'hideDescriptions';
cleanedInput.value = !cleanedInput.value;
}
this.configuration[cleanedInput.name] = {...cleanedInput};
});

this._initialized = true;
}

Expand All @@ -63,6 +92,7 @@ export default class RecordTypePickerCpe extends LightningElement {
};

notifyPropertyChange = (name,newValue,newValueDataType) => {
newValue = (newValueDataType === 'Boolean' ? convertBooleanRealToFlow(newValue) : newValue);
this.dispatchEvent(new CustomEvent(
'configuration_editor_input_value_changed', {
bubbles: true,
Expand Down Expand Up @@ -102,8 +132,14 @@ export default class RecordTypePickerCpe extends LightningElement {
handlePreviewSave(){
Object.values(this.previewConfig).forEach(prop => {
if (this.configuration[prop.name]?.value !== prop.value){

this.configuration[prop.name].value = prop.value;
this.notifyPropertyChange(prop.name,prop.value,prop.valueDataType);

this.notifyPropertyChange(
prop.name,
prop.value,
prop.valueDataType
);
}
});
this.template.querySelector('c-configuration-modal').hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
type="toggle"
label="Show Record Type Descriptions"
class="slds-m-top_xx-small"
data-attribute="showDescription"
data-attribute="hideDescriptions"
data-type="Boolean"
onchange={handleBooleanChange}
checked={showDescription}>
Expand All @@ -43,8 +43,7 @@
data-attribute="autoNavigateNext"
data-type="Boolean"
onchange={handleBooleanChange}
checked={autoNavigateNext}
>
checked={autoNavigateNext}>
</lightning-input>
</template>
<template if:true={_error}>
Expand Down
Loading

0 comments on commit afb6e6b

Please sign in to comment.