Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit 45b6da2

Browse files
authored
Initial beta release of several metadata-driven components
First beta release of 4 components - sobjectLabel - fieldLabel - inputField - outputField These are designed to support - Automatic detection of field type and related metadata (like automatically getting picklist values) - Automatic detection of sobject-level security and field-level security - Automatic translation support for sobject labels & field labels - Overrides and additional options (like additional rendering conditions on inputField) to give developers control when needed
1 parent 2a9df9c commit 45b6da2

23 files changed

+487
-410
lines changed

README.md

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,17 @@
11
# Lightning Components
2-
A collection of custom Salesforce Lightning components to try to make Lightning development a little bit less frustrating
3-
4-
## lightningData.cmp
5-
* A service component that dynamically queries any SObject
6-
7-
`<c:lightningData sobjectType="Account" fields="Id,Name,MyCustomField__c" />`
8-
* Feature: Field level security is automatically enforced by default - only fields that the current user has access to read (based on field.isAccessible()) will be returned. When false, all fields specified in the "fields" attribute are returned, regardless of field level security settings.
9-
10-
`<c:lightningData sobjectType="Account" fields="Id,Name,MyCustomField__c" enforceFLS="false" />`
11-
* Feature: Query caching can be enabled. When true, the Lightning component will cache the results for subsequent calls (action.setStorable())
12-
13-
`<c:lightningData sobjectType="Account" fields="Id,Name,MyCustomField__c" cacheResults="true" />`
2+
A collection of custom Salesforce Lightning components that streamline developing in Lightning by automatically applying sobject-level security, field-level security, field types and more.
143

154
## inputField.cmp
16-
* Provides a simple way to display an SObject's field that automatically determines the field type, field label, etc. Attributes can be overridden to allow control over the field when needed
5+
* Provides a simple way to display an SObject's field as an input (editable) that automatically determines sobject-level security, field-level security, the field type, field label, etc. Attributes can be overridden to allow control over the field when needed
176

187
`<c:inputField sobjectName="Account" record="{!v.myAccount}" fieldName="Type" />`
198

20-
## fieldLabel.cmp
21-
* Displays the localized version of the provided field's label
9+
## outputField.cmp
10+
* Provides a simple way to display an SObject's field as an output (read-only) that automatically determines sobject-level security, field-level security, the field type, field label, etc. Attributes can be overridden to allow control over the field when needed
2211

23-
`<c:fieldLabel sobjectName="Account" fieldName="Type" />`
12+
`<c:inputField sobjectName="Account" record="{!v.myAccount}" fieldName="Type" />`
2413

25-
* Feature: Show the field's inline help text
2614

27-
`<c:fieldLabel sobjectName="Account" fieldName="Type" showHelpText="true" />`
2815
## sobjectLabel.cmp
2916
* Displays the localized version of the provided SObject's label
3017

@@ -33,6 +20,16 @@ A collection of custom Salesforce Lightning components to try to make Lightning
3320
* Feature: Show the SObject's plural label
3421

3522
`<c:sobjectLabel sobjectName="Account" variant="labelPlural" />`
23+
24+
## fieldLabel.cmp
25+
* Displays the localized version of the provided field's label
26+
27+
`<c:fieldLabel sobjectName="Account" fieldName="Type" />`
28+
29+
* Feature: Show the field's inline help text
30+
31+
`<c:fieldLabel sobjectName="Account" fieldName="Type" showHelpText="true" />`
32+
3633
## modal.cmp
3734
* Generates a modal window and displays your contents inside
3835
```
@@ -49,18 +46,6 @@ A collection of custom Salesforce Lightning components to try to make Lightning
4946
`<c:objectPropertyValue object="{!v.my.complex.nested.object}" propertyName="someProperty" />`
5047
5148
# Apex Classes
52-
Two Apex classes are included in this repo. Future updates will try to keep the number of custom classes to a minumum so this library remains lightweight.
53-
54-
## LightningDataController.cls
55-
Contains methods for accessing and modifying data. All methods are designed to work with any SObject type.
56-
* createNewRecord(String sobjectName) - returns a new SObject record of the specified type - any default field values are populated on fields that the current user can modify (based on the field describe's isCreateable())
57-
* queryRecords(String parameterString) - accepts a serialized version of LightningDataController.QueryParameters and returns the SOQL results of the dynamic query
58-
* insertRecords(List<SObject> records) - inserts & returns the provided records
59-
* updateRecords(List<SObject> records) - updates & returns the provided records
60-
* upsertRecords(List<SObject> records) - upserts & returns the provided records
61-
* deleteRecords(List<SObject> records) - deletes the provided records, no return value
62-
* hardDeleteRecords(List<SObject> records) - hard deletes the provided records, no return value
63-
* undeleteRecords(List<SObject> records) - undeletes the provided records, no return value
6449
6550
## LightningMetadataController.cls
6651
Contains methods for describing your orgs metadata and returning the info as aura-friendly objects that can be consumed by Lightning Components

src/aura/fieldLabel/fieldLabel.cmp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<aura:component controller="LightningMetadataController">
1+
<aura:component controller="LightningMetadataController" implements="flexipage:availableForAllPageTypes">
22

33
<!-- Public Attributes -->
44
<aura:attribute name="sobjectName" type="String" required="true" />
@@ -14,9 +14,9 @@
1414

1515
<!-- Markup -->
1616
<ui:outputText value="{!v.label}" />
17-
<aura:if isTrue="{!and(v.showHelpText, v.fieldMetadata.fieldInlineHelpText != null)}">
17+
<aura:if isTrue="{!and(v.showHelpText, v.fieldMetadata.inlineHelpText != null)}">
1818
<a class="help-icon" href="javascript:void(0);">
19-
<lightning:icon iconName="utility:info" variant="info" title="{!v.fieldMetadata.fieldInlineHelpText}" />
19+
<lightning:icon iconName="utility:info" variant="info" title="{!v.fieldMetadata.inlineHelpText}" />
2020
<span class="slds-assistive-text">Help</span>
2121
</a>
2222
</aura:if>

src/aura/fieldLabel/fieldLabel.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.THIS .slds-icon {
2-
height: 1rem;
3-
width: 1rem;
2+
height: 1rem !important;
3+
width: 1rem !important;
44
}
55
.THIS .help-icon {
66
padding: 0 4px;

src/aura/fieldLabel/fieldLabelHelper.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
({
22
fetchFieldMetadata : function(component, event) {
3-
var action = component.get("c.getFieldMetadata");
3+
var action = component.get('c.getFieldMetadata');
44
action.setParams({
5-
"sobjectName": component.get("v.sobjectName"),
6-
"fieldName": component.get("v.fieldName")
5+
'sobjectName': component.get('v.sobjectName'),
6+
'fieldName': component.get('v.fieldName')
77
});
88
action.setStorable();
99
action.setCallback(this, function(response) {
10-
if(response.getState() == "SUCCESS") {
10+
if(response.getState() == 'SUCCESS') {
1111
component.set('v.fieldMetadata', response.getReturnValue());
12-
component.set('v.label', response.getReturnValue().fieldLabel);
12+
component.set('v.label', response.getReturnValue().label);
13+
} else if(response.getState() == 'ERROR') {
14+
console.log('ERROR');
15+
for(var i=0; i < response.getError().length; i++) {
16+
console.log(response.getError()[i]);
17+
}
1318
}
1419
});
1520
$A.enqueueAction(action);

src/aura/inputField/inputField.cmp

Lines changed: 126 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
<aura:component controller="LightningMetadataController">
1+
<aura:component controller="LightningMetadataController" implements="flexipage:availableForAllPageTypes">
22

33
<!-- Public Attributes -->
44
<aura:attribute name="sobjectName" type="String" required="true" />
55
<aura:attribute name="fieldName" type="String" required="true" />
66
<aura:attribute name="record" type="SObject" required="true" />
7-
<aura:attribute name="fieldType" type="String" />
7+
<aura:attribute name="displayType" type="String" />
88
<aura:attribute name="picklistOptions" type="Object[]" />
9-
<aura:attribute name="variant" type="String" default="form" description="Options: form (default) and bare" />
10-
<aura:attribute name="disabled" type="Boolean" required="false" />
9+
<aura:attribute name="showLabel" type="Boolean" default="true" />
10+
<aura:attribute name="render" type="Boolean" default="true" />
11+
<aura:attribute name="disabled" type="Boolean" default="false" />
12+
<aura:attribute name="required" type="Boolean" default="false" />
1113

1214
<!-- Private Attributes -->
1315
<aura:attribute name="fieldMetadata" type="Object" access="private" />
@@ -17,61 +19,137 @@
1719
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
1820
<aura:handler name="change" value="{!v.record}" action="{!c.handleRecordChanged}" />
1921
<aura:handler name="change" value="{!v.fieldValue}" action="{!c.handleFieldValueChanged}" />
22+
<aura:handler name="change" value="{!v.handleBlur}" action="{!c.handleFieldValueChanged}" />
2023

2124
<!-- Markup -->
22-
<div class="slds-form-element">
23-
<aura:if isTrue="{!v.variant == 'form'}">
24-
<label class="slds-form-element__label" for="{!v.auraId}">
25-
<aura:if isTrue="{!and(v.fieldMetadata.fieldRequired, v.fieldMetadata.fieldType != 'BOOLEAN')}">
26-
<abbr class="slds-required" title="required">*</abbr>
25+
<aura:if isTrue="{!and(v.fieldMetadata.sobjectMetadata.isAccessible, v.fieldMetadata.isAccessible, v.render)}">
26+
<div class="slds-form-element">
27+
<aura:if isTrue="{!v.showLabel}">
28+
<label class="slds-form-element__label" for="{!v.auraId}">
29+
<aura:if isTrue="{!and(v.required, v.displayType != 'BOOLEAN')}">
30+
<abbr class="slds-required" title="required">*</abbr>
31+
</aura:if>
32+
<c:fieldLabel sobjectName="{!v.sobjectName}" fieldName="{!v.fieldName}" showHelpText="{!v.fieldMetadata.inlineHelpText != null}" />
33+
</label>
34+
</aura:if>
35+
36+
<div class="slds-form-element__control">
37+
<!--
38+
Input type is determined based on the field's display type
39+
More info: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_enum_Schema_DisplayType.htm
40+
-->
41+
<!-- ADDRESS - TODO -->
42+
<!-- BASE64 - TODO -->
43+
<!-- COMBOBOX - TODO -->
44+
<!-- DATACATEGORYGROUPREFERENCE - TODO -->
45+
<!-- ID - TODO -->
46+
<!-- REFERENCE - TODO -->
47+
<!-- TIME - TODO -->
48+
49+
<!-- BOOLEAN -->
50+
<aura:if isTrue="{!v.displayType == 'BOOLEAN'}">
51+
<div class="slds-form-element">
52+
<label class="slds-checkbox_toggle slds-grid">
53+
<!-- <span class="slds-form-element__label slds-m-bottom_none">Toggle Label</span> -->
54+
<ui:inputCheckbox value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input slds-checkbox uiInput--checkbox" />
55+
<span id="toggle-desc" class="slds-checkbox_faux_container" aria-live="assertive">
56+
<span class="slds-checkbox_faux"></span>
57+
<!-- <span class="slds-checkbox_on">Enabled</span>
58+
<span class="slds-checkbox_off">Disabled</span> -->
59+
</span>
60+
</label>
61+
</div>
2762
</aura:if>
28-
<c:fieldLabel sobjectName="{!v.sobjectName}" fieldName="{!v.fieldName}" showHelpText="{!v.fieldMetadata.fieldInlineHelpText != null}" />
29-
</label>
30-
</aura:if>
3163

32-
<div class="slds-form-element__control">
64+
<!-- CURRENCY -->
65+
<aura:if isTrue="{!v.displayType == 'CURRENCY'}">
66+
<ui:inputCurrency aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input"
67+
blur="{!c.handleBlur}"
68+
/>
69+
</aura:if>
3370

34-
<!-- BOOLEAN -->
35-
<aura:if isTrue="{!v.fieldType == 'BOOLEAN'}">
36-
<ui:inputCheckbox value="{!v.fieldValue}" required="{v.required}" disabled="{!v.disabled}" class="slds-input" />
37-
</aura:if>
71+
<!-- DATE -->
72+
<aura:if isTrue="{!v.displayType == 'DATE'}">
73+
<ui:inputDate aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" displayDatePicker="true"
74+
blur="{!c.handleBlur}"
75+
/>
76+
</aura:if>
3877

39-
<!-- CURRENCY -->
40-
<aura:if isTrue="{!v.fieldType == 'CURRENCY'}">
41-
<ui:inputCurrency value="{!v.fieldValue}" required="{v.required}" disabled="{!v.disabled}" class="slds-input" />
42-
</aura:if>
78+
<!-- DATETIME -->
79+
<aura:if isTrue="{!v.displayType == 'DATETIME'}">
80+
<ui:inputDatetime aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" displayDatePicker="true"
81+
blur="{!c.handleBlur}"
82+
/>
83+
</aura:if>
4384

44-
<!-- DATE -->
45-
<aura:if isTrue="{!v.fieldType == 'DATE'}">
46-
<ui:inputDate value="{!v.fieldValue}" required="{v.required}" disabled="{!v.disabled}" class="slds-input" displayDatePicker="true" />
47-
</aura:if>
85+
<!-- DOUBLE or INTEGER -->
86+
<aura:if isTrue="{!or(v.displayType == 'DOUBLE', v.displayType == 'INTEGER')}">
87+
<ui:inputNumber aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input"
88+
blur="{!c.handleBlur}"
89+
/>
90+
</aura:if>
4891

49-
<!-- DOUBLE -->
50-
<aura:if isTrue="{!or(v.fieldType == 'DOUBLE', v.fieldType == 'INTEGER')}">
51-
<ui:inputNumber value="{!v.fieldValue}" required="{v.required}" disabled="{!v.disabled}" class="slds-input" />
52-
</aura:if>
92+
<!-- EMAIL -->
93+
<aura:if isTrue="{!v.displayType == 'EMAIL'}">
94+
<ui:inputEmail aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" maxlength="{!v.fieldMetadata.maxLength}"
95+
blur="{!c.handleBlur}"
96+
/>
97+
</aura:if>
5398

54-
<!-- PICKLIST -->
55-
<aura:if isTrue="{!or(v.fieldType == 'PICKLIST', v.fieldType == 'MULTIPICKLIST')}">
56-
<ui:inputSelect aura:id="auraId" required="{v.required}" disabled="{!v.disabled}" class="{!'slds-select ' + v.styleClass}"
57-
multiple="{!v.fieldType == 'MULTIPICKLIST'}" change="{!c.handleFieldValueChanged}"
58-
>
59-
<aura:iteration items="{!v.picklistOptions}" var="picklistOption">
60-
<ui:inputSelectOption label="{!picklistOption.picklistLabel}" text="{!picklistOption.picklistValue}" value="{!picklistOption.isSelectedValue}" />
61-
</aura:iteration>
62-
</ui:inputSelect>
63-
</aura:if>
99+
<!-- ENCRYPTEDSTRING -->
100+
<aura:if isTrue="{!v.displayType == 'ENCRYPTEDSTRING'}">
101+
<ui:inputSecret aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" maxlength="{!v.fieldMetadata.maxLength}"
102+
blur="{!c.handleBlur}"
103+
/>
104+
</aura:if>
64105

65-
<!-- STRING -->
66-
<aura:if isTrue="{!v.fieldType == 'STRING'}">
67-
<ui:inputText value="{!v.fieldValue}" required="{!v.required}" disabled="{!v.disabled}" class="slds-input" maxLength="{!v.fieldMetadata.fieldMaxLength}" />
68-
</aura:if>
106+
<!-- MULTIPICKLIST or PICKLIST -->
107+
<aura:if isTrue="{!or(v.displayType == 'MULTIPICKLIST', v.displayType == 'PICKLIST')}">
108+
<ui:inputSelect aura:id="inputField" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="{!'slds-select ' + v.styleClass}"
109+
blur="{!c.handleBlur}" multiple="{!v.displayType == 'MULTIPICKLIST'}" change="{!c.handleFieldValueChanged}"
110+
>
111+
<aura:iteration items="{!v.picklistOptions}" var="picklistOption">
112+
<ui:inputSelectOption label="{!picklistOption.label}" text="{!picklistOption.value}" value="{!picklistOption.value == v.fieldValue}" />
113+
</aura:iteration>
114+
</ui:inputSelect>
115+
</aura:if>
69116

70-
<!-- TEXTAREA -->
71-
<aura:if isTrue="{!v.fieldType == 'TEXTAREA'}">
72-
<ui:inputTextArea value="{!v.fieldValue}" required="{!v.required}" disabled="{!v.disabled}" class="slds-input" maxLength="{!v.fieldMetadata.fieldMaxLength}" />
73-
</aura:if>
117+
<!-- PERCENT -->
118+
<aura:if isTrue="{!v.displayType == 'PERCENT'}">
119+
<ui:inputNumber aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input"
120+
blur="{!c.handleBlur}"
121+
/>
122+
</aura:if>
123+
124+
<!-- PHONE -->
125+
<aura:if isTrue="{!v.displayType == 'PHONE'}">
126+
<ui:inputPhone aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" maxlength="{!v.fieldMetadata.maxLength}"
127+
blur="{!c.handleBlur}"
128+
/>
129+
</aura:if>
130+
131+
<!-- STRING -->
132+
<aura:if isTrue="{!v.displayType == 'STRING'}">
133+
<ui:inputText aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" maxlength="{!v.fieldMetadata.maxLength}"
134+
blur="{!c.handleBlur}"
135+
/>
136+
</aura:if>
137+
138+
<!-- TEXTAREA -->
139+
<aura:if isTrue="{!v.displayType == 'TEXTAREA'}">
140+
<ui:inputTextArea aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" maxlength="{!v.fieldMetadata.maxLength}"
141+
blur="{!c.handleBlur}"
142+
/>
143+
</aura:if>
144+
145+
<!-- URL -->
146+
<aura:if isTrue="{!v.displayType == 'URL'}">
147+
<ui:inputURL aura:id="inputField" value="{!v.fieldValue}" required="{!v.required}" disabled="{!or(v.fieldMetadata.isUpdateable == false, v.disabled)}" class="slds-input" maxlength="{!v.fieldMetadata.maxLength}"
148+
blur="{!c.handleBlur}"
149+
/>
150+
</aura:if>
151+
</div>
74152
</div>
75-
</div>
153+
</aura:if>
76154

77155
</aura:component>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
33
<apiVersion>40.0</apiVersion>
4-
<description>InputField</description>
4+
<description>inputField</description>
55
</AuraDefinitionBundle>

0 commit comments

Comments
 (0)