Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge main into feature/nov26-fix-percent #54

Open
wants to merge 12 commits into
base: feature/nov26-fix-percent
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,58 +1,5 @@
import { LightningElement, api } from 'lwc';
import LOCALE from '@salesforce/i18n/locale';
import CURRENCY from '@salesforce/i18n/currency';
import TIMEZONE from '@salesforce/i18n/timeZone';

// Not a complete list - see https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_Schema_DisplayType.htm
/*const TYPE_MAPPINGS = {
'Boolean': 'boolean',
'CURRENCY': 'currency',
'Date': 'date',
'DATETIME': 'date',
'Email': 'text',
'Double': 'number',
'Percent': 'percent',
'Phone': 'phone',
'Picklist': 'text',
'Reference': 'text',
'String': 'text',
'TextArea': 'text',
'URL': 'url'
};*/

function formatDateTimeLocale(dateStr, hasDate, hasTime) {
const options = {
timeZone: TIMEZONE
};
if (hasDate) {
options.dateStyle = 'medium';
}
if (hasTime) {
options.timeStyle = 'short';
}
return new Intl.DateTimeFormat(LOCALE, options).format(new Date(dateStr));
}

function formatCurrencyLocale(amount) {
return new Intl.NumberFormat(LOCALE, {
style: 'currency',
currency: CURRENCY,
currencyDisplay: 'symbol'
}).format(amount);
}

function formatDoubleLocale(amount, scale) {
return new Intl.NumberFormat(LOCALE, {
minimumFractionDigits: scale
}).format(amount);
}

function formatPercentLocale(amount) {
return new Intl.NumberFormat(LOCALE, {
style: 'percent',
minimumFractionDigits: 2
}).format(amount);
}
import { getFormattedStringForType } from 'c/stickySelectronUtils';

export default class StickySelectronDataCell extends LightningElement {
@api object;
Expand All @@ -70,32 +17,12 @@ export default class StickySelectronDataCell extends LightningElement {

get fieldValForObject() {
const inputVal = this.object?.[this.fieldName];
if (inputVal) {
if (this.sfType === 'DATETIME') {
const hasDate = true;
const hasTime = true;
return formatDateTimeLocale(inputVal, hasDate, hasTime);
}
if (this.sfType === 'DATE') {
const hasDate = true;
const hasTime = false;
return formatDateTimeLocale(inputVal, hasDate, hasTime);
}
if (this.sfType === 'TIME') {
const hasDate = false;
const hasTime = true;
return formatDateTimeLocale(inputVal, hasDate, hasTime);
}
if (this.sfType === 'CURRENCY') {
return formatCurrencyLocale(inputVal);
}
if (this.sfType === 'PERCENT') {
return formatPercentLocale(inputVal / 100);
}
if (this.sfType === 'DOUBLE') {
return formatDoubleLocale(inputVal, this.sfScale);
}
}
return inputVal;
const outputString = getFormattedStringForType(
inputVal,
this.sfType,
this.sfScale
);

return outputString;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
class="slds-float_left slds-var-m-top_xx-small slds-var-p-around_x-small slds-scrollable_y grid-main"
>
<!-- Spinner -->
<template if:true={isLoading}>
<template if:true={stillShowLoading}>
<div class="slds-var-p-around_x-large spinner">
<lightning-spinner
alternative-text="Loading"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { LightningElement, api, track } from 'lwc';
import getBulkFieldInfo from '@salesforce/apex/FieldLabelController.getBulkFieldInfo';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { getFormattedStringForType } from 'c/stickySelectronUtils';

// Note that sometimes we are dealing with a Proxy object and want to print it to console
// while debugging
Expand Down Expand Up @@ -36,6 +37,27 @@ export default class StickySelectronMain extends LightningElement {
@api initialListCount;
isLoading = false;

// We want to continue showing the loading icon if our LWC hasn't rendered yet,
// if the input list is empty, or if the input table field metadata hasn't finished yet
// Also we have to detect if the input list is empty because someone searched and there are no hits
// Note that we compare the inputTableFieldNames length to the fieldsOnLeft length - 1 because of the Select column that is in the fieldsOnLeft but
// not in the inputTableFieldNames
get stillShowLoading() {
const shouldShowLoading =
this.isLoading ||
this.workingInputObjList.length === 0 ||
this.inputTableFieldNames.length !== this.fieldsOnLeft.length - 1;
if (shouldShowLoading) {
const inp = this.template.querySelector('lightning-input');
const searchKey = inp?.value;
// If there is a search key set, we should not show the loading icon
if (searchKey && this.workingInputObjList.length === 0) {
return false;
}
}
return shouldShowLoading;
}

@api inputTableFieldNames;
@api selectedTableFieldNames;

Expand Down Expand Up @@ -332,7 +354,14 @@ export default class StickySelectronMain extends LightningElement {
fieldAPIName &&
recCopy[fieldAPIName] !== undefined
) {
valuesArray.push(recCopy[fieldAPIName]);
const valToAdd = recCopy[fieldAPIName];
valuesArray.push(
getFormattedStringForType(
valToAdd,
fieldObj.sfType,
fieldObj.sfScale
)
);
}
}

Expand All @@ -343,8 +372,15 @@ export default class StickySelectronMain extends LightningElement {
recs.push(rec);
break;
}
// Added logic to replace %, /, and $ from search key because
// we are searching just the values from Salesforce (not the HTML displayed)
} else if (typeof val === 'number') {
if (val.toString().includes(searchKey)) {
const searchKeyToCheck = searchKey
.replaceAll('%', '')
.replaceAll('/', '')
.replaceAll('$', '')
.replaceAll(',', '');
if (val.toString().includes(searchKeyToCheck)) {
recs.push(rec);
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import LOCALE from '@salesforce/i18n/locale';
import CURRENCY from '@salesforce/i18n/currency';
import TIMEZONE from '@salesforce/i18n/timeZone';

// Not a complete list - see https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_enum_Schema_DisplayType.htm
/*const TYPE_MAPPINGS = {
'Boolean': 'boolean',
'CURRENCY': 'currency',
'Date': 'date',
'DATETIME': 'date',
'Email': 'text',
'Double': 'number',
'Percent': 'percent',
'Phone': 'phone',
'Picklist': 'text',
'Reference': 'text',
'String': 'text',
'TextArea': 'text',
'URL': 'url'
};*/

function formatDateTimeLocale(dateStr, hasDate, hasTime) {
const options = {
timeZone: TIMEZONE
};
if (hasDate) {
// Note that setting to short will have a 2-digit year, but we want 4 digit
//options.dateStyle = 'short';

options.year = 'numeric';
options.month = '2-digit';
options.day = '2-digit';
}
// If we leave default formatting (not setting date and time options) then time is not shown
if (hasTime) {
// timeStyle short is the format we want, but since we need a 4 digit year, we need to set the time components manually
//options.timeStyle = 'short';

options.hour = '2-digit';
options.minute = '2-digit';
}
return new Intl.DateTimeFormat(LOCALE, options).format(new Date(dateStr));
}

function formatCurrencyLocale(amount) {
return new Intl.NumberFormat(LOCALE, {
style: 'currency',
currency: CURRENCY,
currencyDisplay: 'symbol'
}).format(amount);
}

function formatDoubleLocale(amount, scale) {
return new Intl.NumberFormat(LOCALE, {
minimumFractionDigits: scale
}).format(amount);
}

function formatPercentLocale(amount) {
return new Intl.NumberFormat(LOCALE, {
style: 'percent',
minimumFractionDigits: 2
}).format(amount);
}

function doesTypeNeedFormatting(sfType) {
return (
sfType === 'DATETIME' ||
sfType === 'DATE' ||
sfType === 'TIME' ||
sfType === 'CURRENCY' ||
sfType === 'PERCENT' ||
sfType === 'DOUBLE'
);
}

function getFormattedStringForType(inputVal, sfType, sfScale) {
if (doesTypeNeedFormatting(sfType)) {
// We may get a zero value from Apex that should still be rendered with our JS formatting
if (
inputVal ||
sfType === 'CURRENCY' ||
sfType === 'PERCENT' ||
sfType === 'DOUBLE'
) {
if (sfType === 'DATETIME') {
const hasDate = true;
const hasTime = true;
return formatDateTimeLocale(inputVal, hasDate, hasTime);
}
if (sfType === 'DATE') {
const hasDate = true;
const hasTime = false;
return formatDateTimeLocale(inputVal, hasDate, hasTime);
}
if (sfType === 'TIME') {
const hasDate = false;
const hasTime = true;
return formatDateTimeLocale(inputVal, hasDate, hasTime);
}
if (sfType === 'CURRENCY') {
return formatCurrencyLocale(inputVal);
}
if (sfType === 'PERCENT') {
return formatPercentLocale(inputVal / 100);
}
if (sfType === 'DOUBLE') {
return formatDoubleLocale(inputVal, sfScale);
}
}
}
return inputVal;
}

export {
formatDateTimeLocale,
formatCurrencyLocale,
formatDoubleLocale,
formatPercentLocale,
doesTypeNeedFormatting,
getFormattedStringForType
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>61.0</apiVersion>
<isExposed>false</isExposed>
</LightningComponentBundle>
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
<queriedFields>ssCurrency__c</queriedFields>
<queriedFields>ssDateTime__c</queriedFields>
<queriedFields>AnnualRevenue</queriedFields>
<queriedFields>NewCurrency__c</queriedFields>
<queriedFields>CreatedDate</queriedFields>
</recordLookups>
<screens>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>NewCurrency__c</field>
<field>ssCurrency__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
Expand All @@ -41,6 +41,10 @@
<behavior>Edit</behavior>
<field>ssDate__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ssDateTime__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ssTime__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
<behavior>Edit</behavior>
<field>NumberOfEmployees</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>NewCurrency__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ssDouble__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>NewCurrency__c</field>
<field>ssCurrency__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
Expand All @@ -53,6 +53,10 @@
<behavior>Edit</behavior>
<field>ssDate__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ssDateTime__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ssTime__c</field>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@
<behavior>Edit</behavior>
<field>AnnualRevenue</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>NewCurrency__c</field>
</layoutItems>
<layoutItems>
<behavior>Edit</behavior>
<field>ssDouble__c</field>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<CustomField xmlns="http://soap.sforce.com/2006/04/metadata">
<fullName>ssDateTime__c</fullName>
<description>Help field for sticky selectron dev</description>
<label>ssDateTime</label>
<required>false</required>
<trackFeedHistory>false</trackFeedHistory>
<type>DateTime</type>
</CustomField>
Loading