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

Commit

Permalink
Added SimpleMetadata library for metadata classes, created new compon…
Browse files Browse the repository at this point in the history
…ents

Created several new components that are built on top of SimpleMetadata library (included in this repo)
* simpleAdmin.cmp
* currentUser.cmp
* environmentMetadata.cmp
* fieldSetMetadata.cmp
* listviewMetadata.cmp
* queueMetadata.cmp
* recordTypeMetadata.cmp
  • Loading branch information
jongpie authored Feb 12, 2018
1 parent 26a5b28 commit 90c645a
Show file tree
Hide file tree
Showing 82 changed files with 2,663 additions and 418 deletions.
14 changes: 0 additions & 14 deletions .codeclimate.yml

This file was deleted.

110 changes: 37 additions & 73 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,79 +1,43 @@
# Lightning Components
A library of lightweight Salesforce Lightning components that streamline developing by automatically applying sobject-level security, field-level security, field types and more.
# Simple Lightning Components
A library of lightweight Salesforce Lightning components that simplify developing in Lightning by automatically:
* Honoring SObject-level security & field-level security for displaying fields & allowing fields to be edited
* Displaying the correct input field type based on the field's metadata, including lookup fields & support for polymorphic fields like Task.WhoId & Task.WhatId
* Translating SObject labels, field labels and picklist options

<a href="https://githubsfdeploy.herokuapp.com" target="_blank">
<img alt="Deploy to Salesforce"
src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">
<img alt="Deploy to Salesforce" src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png">
</a>

## sobjectMetadata.cmp
* An extensible, markup-less component that returns an instance of LightningMetadataController.SObjectMetadata for the specified SObject

`<c:sobjectMetadata sobjectName="Account" aura:id="accountMetadataService" />`

## fieldMetadata.cmp
* An extensible, markup-less component that returns an instance of LightningMetadataController.FieldMetadata for the specified field

`<c:fieldMetadata sobjectName="Account" fieldName="Type" aura:id="accountTypeMetadataService" />`

## inputField.cmp
* 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

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

## lookup.cmp
* Provides lookup functionality that Salesforce does not provide for developers in LEX. This component is used by inputField.cmp for lookup fields.

Users can search for the record or choose one of the recently viewed records automatically displayed on focus
`<c:lookup sobjectName="Contact" fieldName="AccountId" record="{!v.myContact}" />`

Polymorphic fields, like Task.WhoId, automatically display an SObject Switcher.
SObject-level permissions are automatically applied - only objects that the user has permission to view are displayed in the SObject Switcher.
`<c:lookup sobjectName="Task" fieldName="WhoId" record="{!v.myTask}" />`
![lookup-task-whoid](https://user-images.githubusercontent.com/1267157/34769563-6f5b8374-f5fe-11e7-88c7-98e6fbb0ec75.gif)


## outputField.cmp
* 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

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

## sobjectLabel.cmp
* Displays the localized version of the provided SObject's label

`<c:sobjectLabel sobjectName="Account" />`

* Feature: Show the SObject's plural label

`<c:sobjectLabel sobjectName="Account" variant="labelPlural" />`

## fieldLabel.cmp
* Displays the localized version of the provided field's label

`<c:fieldLabel sobjectName="Account" fieldName="Type" />`

* Feature: Show the field's inline help text

`<c:fieldLabel sobjectName="Account" fieldName="Type" showHelpText="true" />`

## modal.cmp
* Generates a modal window and displays your contents inside
```
<c:modal title="My Modal" isOpen="{!v.showModal}">
<aura:set attribute="body">
<p>This paragraph will be shown inside the modal</p>
</aura:set>
</c:modal>
```
## objectPropertyValue.cmp
* Displays the specified property of any javascript object - this is helpful since Lightning does not allow you to dynamically get a property value by name (like 'myObject[someProperty]')
`<c:objectPropertyValue object="{!v.my.complex.nested.object}" propertyName="someProperty" />`
# Apex Classes
## LightningMetadataController.cls
## Simple Admin component
* simpleAdmin.cmp - this is a demo component that provides examples of how to use the other components. It's also a handy admin tool to quickly get information about your org.

## Metadata Components
Several no-markup components are included. These can be used to dynamically access metadata about your org in Lightning components
* **currentUser.cmp**: return info about the current user. Additional user fields can be returned by setting currentUser.additionalFieldApiNames
* **environmentMetadata.cmp**: returns an instance of EnvironmentMetadata for the specified SObjectenvironmentMetadata.cmp
* **fieldMetadata.cmp**: returns an instance of FieldMetadata for the specified SObjectfieldMetadata.cmp
* **fieldSetMetadata.cmp**: returns an instance of FieldSetMetadata for the specified SObjectfieldSetMetadata.cmp
* **listviewMetadata.cmp**: returns an instance of ListviewMetadata for the specified SObjectlistviewMetadata.cmp
* **queueMetadata.cmp**: returns an instance of QueueMetadata for the specified SObjectqueueMetadata.cmp
* **recordTypeMetadata.cmp**: returns an instance of RecordTypeMetadata for the specified SObjectrecordTypeMetadata.cmp
* **sobjectMetadata.cmp**: returns an instance of SObjectMetadata for the specified SObjectsobjectMetadata.cmp

## UI Components
These components are used to build UIs in Lightning - several of these leverage the metadata service components
* **fieldLabel.cmp**: Displays the localized version of the provided field's label
* **inputField.cmp**: 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
* **lookup.cmp**: Provides lookup functionality that Salesforce does not provide for developers in LEX. This component is used by inputField.cmp for lookup fields.
* **modal.cmp**: Generates a modal window and displays your contents inside
* **objectPropertyValue.cmp**: Displays the specified property of any javascript object - this is helpful since Lightning does not allow you to dynamically get a property value by name (like 'myObject[someProperty]')
* **outputField.cmp**: 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
* **sobjectLabel.cmp**: Displays the localized version of the provided SObject's label

## Apex Classes

### LightningMetadataController.cls
Contains methods for describing your orgs metadata and returning the info as aura-friendly objects that can be consumed by Lightning Components
* getSObjectMetadata(String sobjectName) - returns an instance of LightningMetadataController.SObjectMetadata
* getFieldMetadata(String sobjectName, String fieldName) - returns an instance of LightningMetadataController.FieldMetadata
* getFieldMetadata(String sobjectName, String fieldName) - returns an instance of LightningMetadataController.FieldMetadata

### SimpleMetadata classes
The remaining metadata classes (SObjectMetadata.cls, FieldMetadata.cls, etc) are part of the [SimpleMetadata](https://github.com/jongpie/SimpleMetadata) project - any bugs or enhancements for those classes are maintained in that project, and the latest version is used in this repo.
23 changes: 23 additions & 0 deletions src/aura/currentUser/currentUser.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!--
This file is part of the Simple Lightning Components project, released under the MIT License.
See LICENSE file or go to https://github.com/jongpie/LightningComponents for full license details.
-->
<aura:component extensible="true" controller="LightningMetadataController">

<!-- Public Attributes -->
<aura:attribute name="additionalFieldApiNames" type="String[]" description="(Optional) Additional field API names to return for the current user" />
<aura:attribute name="currentUser" type="User" description="The current user" />

<!-- Public Functions -->
<aura:method name="fetch" action="{!c.doInit}" description="(Optional) Callback function to use after fetching the current user">
<aura:attribute name="callback" type="function"/>
</aura:method>

<!-- Handlers -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.additionalFieldApiNames}" action="{!c.doInit}" />

<!-- Markup -->
{!v.body}

</aura:component>
5 changes: 5 additions & 0 deletions src/aura/currentUser/currentUser.cmp-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>41.0</apiVersion>
<description>currentUser</description>
</AuraDefinitionBundle>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
({
doInit : function(component, event, helper) {
helper.fetchSObjectMetadata(component, event);
helper.fetchCurrentUser(component, event);
}
})
28 changes: 28 additions & 0 deletions src/aura/currentUser/currentUserHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
({
fetchCurrentUser : function(component, event) {
var params = event.getParam('arguments');

var action = component.get('c.getCurrentUser');
action.setParams({
'additionalFieldApiNames': component.get('v.additionalFieldApiNames')
});
action.setStorable();
action.setCallback(this, function(response) {
if(response.getState() === 'SUCCESS') {
var currentUser = response.getReturnValue();
component.set('v.currentUser', currentUser);

if(params) params.callback(null, currentUser);
} else if(response.getState() === 'ERROR') {
this.processCallbackErrors(response);
}
});
$A.enqueueAction(action);
},
processCallbackErrors : function(response) {
console.log('ERROR');
for(var i=0; i < response.getError().length; i++) {
console.log(response.getError()[i]);
}
}
})
21 changes: 21 additions & 0 deletions src/aura/environmentMetadata/environmentMetadata.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
This file is part of the Simple Lightning Components project, released under the MIT License.
See LICENSE file or go to https://github.com/jongpie/LightningComponents for full license details.
-->
<aura:component extensible="true" controller="LightningMetadataController">

<!-- Public Attributes -->
<aura:attribute name="environmentMetadata" type="EnvironmentMetadata" description="The Environment metadata object returned from the controller" />

<!-- Public Functions -->
<aura:method name="fetch" action="{!c.doInit}" description="(Optional) Callback function to use after fetching the metadata">
<aura:attribute name="callback" type="function"/>
</aura:method>

<!-- Handlers -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />

<!-- Markup -->
{!v.body}

</aura:component>
5 changes: 5 additions & 0 deletions src/aura/environmentMetadata/environmentMetadata.cmp-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>41.0</apiVersion>
<description>environmentMetadata</description>
</AuraDefinitionBundle>
5 changes: 5 additions & 0 deletions src/aura/environmentMetadata/environmentMetadataController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
({
doInit : function(component, event, helper) {
helper.fetchEnvironmentMetadata(component, event);
}
})
25 changes: 25 additions & 0 deletions src/aura/environmentMetadata/environmentMetadataHelper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
({
fetchEnvironmentMetadata : function(component, event) {
var params = event.getParam('arguments');

var action = component.get('c.getEnvironmentMetadata');
action.setStorable();
action.setCallback(this, function(response) {
if(response.getState() === 'SUCCESS') {
var environmentMetadata = response.getReturnValue();
component.set('v.environmentMetadata', environmentMetadata);

if(params) params.callback(null, environmentMetadata);
} else if(response.getState() === 'ERROR') {
this.processCallbackErrors(response);
}
});
$A.enqueueAction(action);
},
processCallbackErrors : function(response) {
console.log('ERROR');
for(var i=0; i < response.getError().length; i++) {
console.log(response.getError()[i]);
}
}
})
18 changes: 7 additions & 11 deletions src/aura/fieldLabel/fieldLabel.cmp
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<!--
This file is part of the Simple Lightning Components project, released under the MIT License.
See LICENSE file or go to https://github.com/jongpie/LightningComponents for full license details.
-->
<aura:component extends="c.fieldMetadata">

<!-- Public Attributes -->
<aura:attribute name="label" type="String" />
<aura:attribute name="showHelpText" type="Boolean" default="true" />
<aura:attribute name="helpText" type="String" />

<!-- Private Attributes -->
<aura:attribute name="fieldMetadata" type="Object" access="private" />

<!-- Markup -->
<ui:outputText value="{!v.label}" />
<aura:if isTrue="{!and(v.showHelpText, v.helpText != null)}">
<lightning:helptext iconName="utility:info" content="{!v.helpText}" />
<ui:outputText value="{!v.fieldMetadata.label}" />
<aura:if isTrue="{!v.fieldMetadata.inlineHelpText != null}">
<lightning:helptext iconName="utility:info" content="{!v.fieldMetadata.inlineHelpText}" />
</aura:if>

</aura:component>
19 changes: 10 additions & 9 deletions src/aura/fieldMetadata/fieldMetadata.cmp
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<aura:component extensible="true" controller="LightningMetadataController">
<!--
This file is part of the Simple Lightning Components project, released under the MIT License.
See LICENSE file or go to https://github.com/jongpie/LightningComponents for full license details.
-->
<aura:component extends="c.sobjectMetadata" extensible="true" controller="LightningMetadataController">

<!-- Public Attributes -->
<aura:attribute name="sobjectName" type="String" required="true" description="The API name of the SObject" />
<aura:attribute name="fieldName" type="String" required="true" description="The API name of the field" />
<aura:attribute name="fieldApiName" type="String" required="true" description="The API name of the field" />
<aura:attribute name="fieldMetadata" type="FieldMetadata" description="The field metadata object returned from the controller" />

<!-- Public Methods -->
<!-- Public Functions -->
<aura:method name="fetch" action="{!c.doInit}" description="(Optional) Callback function to use after fetching the metadata">
<aura:attribute name="callback" type="function"/>
</aura:method>

<!-- Private Attributes -->
<aura:attribute name="fieldMetadata" type="Object" access="public" description="The field metadata object returned from the controller" />

<!-- Handlers -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.sobjectName}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.fieldName}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.sobjectApiName}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.fieldApiName}" action="{!c.doInit}" />

<!-- Markup -->
{!v.body}
Expand Down
13 changes: 6 additions & 7 deletions src/aura/fieldMetadata/fieldMetadataHelper.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
({
fetchFieldMetadata : function(component, event) {
var sobjectName = component.get('v.sobjectName');
var fieldName = component.get('v.fieldName');
var sobjectApiName = component.get('v.sobjectApiName');
var fieldApiName = component.get('v.fieldApiName');

if(!sobjectName || !fieldName) return;
if(!sobjectApiName || !fieldApiName) return;

var params = event.getParam('arguments');

var action = component.get('c.getFieldMetadata');
var action = component.get('c.getFieldMetadataByName');
action.setParams({
'sobjectName': component.get('v.sobjectName'),
'fieldName': component.get('v.fieldName')
sobjectApiName : sobjectApiName,
fieldApiName : fieldApiName
});
action.setStorable();
action.setCallback(this, function(response) {
if(response.getState() === 'SUCCESS') {
var fieldMetadata = response.getReturnValue();
component.set('v.fieldMetadata', fieldMetadata);
component.set('v.label', fieldMetadata.label);

if(params) params.callback(null, fieldMetadata);
} else if(response.getState() === 'ERROR') {
Expand Down
24 changes: 24 additions & 0 deletions src/aura/fieldSetMetadata/fieldSetMetadata.cmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
This file is part of the Simple Lightning Components project, released under the MIT License.
See LICENSE file or go to https://github.com/jongpie/LightningComponents for full license details.
-->
<aura:component extends="c.sobjectMetadata" extensible="true" controller="LightningMetadataController">

<!-- Public Attributes -->
<aura:attribute name="fieldSetApiName" type="String" required="true" description="The API name of the field set" />
<aura:attribute name="fieldSetMetadata" type="FieldSetMetadata" description="The field set metadata object returned from the controller" />

<!-- Public Methods -->
<aura:method name="fetch" action="{!c.doInit}" description="(Optional) Callback function to use after fetching the metadata">
<aura:attribute name="callback" type="function"/>
</aura:method>

<!-- Handlers -->
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.sobjectApiName}" action="{!c.doInit}" />
<aura:handler name="change" value="{!v.fieldSetApiName}" action="{!c.doInit}" />

<!-- Markup -->
{!v.body}

</aura:component>
5 changes: 5 additions & 0 deletions src/aura/fieldSetMetadata/fieldSetMetadata.cmp-meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<AuraDefinitionBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>41.0</apiVersion>
<description>fieldSetMetadata</description>
</AuraDefinitionBundle>
5 changes: 5 additions & 0 deletions src/aura/fieldSetMetadata/fieldSetMetadataController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
({
doInit : function(component, event, helper) {
helper.fetchFieldSetMetadata(component, event);
}
})
Loading

0 comments on commit 90c645a

Please sign in to comment.