Skip to content

Commit

Permalink
Merge pull request #98 from jongpie/data-table-icon
Browse files Browse the repository at this point in the history
Added object icon to soqlDatatable
  • Loading branch information
tsalb authored Jun 24, 2021
2 parents 479c6f5 + ccf9738 commit f72e06a
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<template>
<c-message-service boundary={uniqueBoundary}></c-message-service>

<lightning-card>
<lightning-card icon-name={iconName}>
<div slot="title">
<slot name="title">
<template if:true={showRecordCount}> {title} {recordCountDisplay} </template>
Expand Down
1 change: 1 addition & 0 deletions utils-core/main/default/lwc/baseDatatable/baseDatatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export default class BaseDatatable extends LightningElement {
this._keyField = value;
}
@api title;
@api iconName;
@api showRecordCount = false;

// MessageService boundary, for when multiple instances are on same page
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
unique-boundary={uniqueBoundary}
is-save-to-server
key-field="Id"
icon-name={iconName}
title={title}
record-id={recordId}
show-record-count={showRecordCount}
Expand Down
16 changes: 15 additions & 1 deletion utils-core/main/default/lwc/soqlDatatable/soqlDatatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default class SoqlDatatable extends LightningElement {

@api isRecordBind = false;
@api title;
@api iconName;
@api showRecordCount = false;
@api showSearch = false;
@api showRefreshButton = false;
Expand Down Expand Up @@ -169,7 +170,10 @@ export default class SoqlDatatable extends LightningElement {
this._notifySingleError('getObjectInfo error', error);
} else if (data) {
this._objectInfo = data;
//console.log(this._objectInfo);

if (!this.iconName) {
this.iconName = this._extractCardIconNameFromObjectInfo(); // outputs 'standard:account'
}

// For cleaning columns on output
this._objectFieldsMap = new Map(Object.entries(this._objectInfo.fields));
Expand Down Expand Up @@ -351,6 +355,16 @@ export default class SoqlDatatable extends LightningElement {

// Private functions

_extractCardIconNameFromObjectInfo() {
// objectInfo iconUrl example: 'https://fun-momentum-3772-dev-ed.cs43.my.salesforce.com/img/icon/t4v35/standard/account_120.png';
if (this._objectInfo.themeInfo.iconUrl) {
let iconUrlFragments = this._objectInfo.themeInfo.iconUrl.split('/');
let iconType = iconUrlFragments[iconUrlFragments.length - 2]; // outputs 'standard'
let icon = iconUrlFragments[iconUrlFragments.length - 1].replace('_120.png', ''); // outputs 'account'
this.iconName = iconType + ':' + icon;
}
}

_getCleanRow(row) {
for (let fieldName in row) {
if (typeof row[fieldName] === 'object') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<targetConfigs>
<targetConfig targets="lightning__AppPage, lightning__HomePage">
<property name="title" label="Title" type="String"/>
<property name="iconName" label="Icon" type="String"/>
<property name="showRecordCount" label="Show Record Count" type="Boolean" default="false"/>
<property name="showSearch" label="Show Search" type="Boolean" default="false"/>
<property name="showRefreshButton" label="Show Refresh" type="Boolean" default="false"/>
Expand All @@ -32,6 +33,7 @@
<targetConfig targets="lightning__RecordPage">
<property name="isRecordBind" label="Enable $CurrentRecord API" type="Boolean" description="Allows merge of current record field values directly to SOQL. User must have FLS access." default="true"/>
<property name="title" label="Title" type="String"/>
<property name="iconName" label="Icon" type="String"/>
<property name="showRecordCount" label="Show Record Count" type="Boolean" default="false"/>
<property name="showSearch" label="Show Search" type="Boolean" default="false"/>
<property name="showRefreshButton" label="Show Refresh" type="Boolean" default="false"/>
Expand All @@ -52,6 +54,7 @@
<propertyType name="sObj" extends="SObject" label="Object"/>
<property name="recordId" label="Record Id" description="Must be a 15 or 18 digit SObject Id. Allows use of $recordId in your SOQL to merge to this value." type="String" role="inputOnly"/>
<property name="title" label="Title" type="String" role="inputOnly"/>
<property name="iconName" label="Icon" type="String" role="inputOnly"/>
<property name="showRecordCount" label="Show Record Count" type="Boolean" role="inputOnly" default="false"/>
<property name="showSearch" label="Show Search" type="Boolean" default="false"/>
<property name="queryString" label="SOQL String" type="String" default="SELECT ... FROM ..." description="Use $recordId in your SOQL to bind to the Record Id given. Alternatively, use a String Formula to merge flow variables to create Dynamic SOQL. $CurrentRecord API is not supported in Screen Flows." required="true" role="inputOnly"/>
Expand Down

0 comments on commit f72e06a

Please sign in to comment.