Skip to content

Commit

Permalink
Fix #35 More records returned and improved browser functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Raspikabek committed May 4, 2019
1 parent be45e9c commit b2c3e81
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
Expand Up @@ -12,7 +12,15 @@
<p>
<template for:each={tagsToDisplay} for:item="item">
<div key={item.id}>
<c-tag-badge record-id={item.id} onselected={handleBadgeSelected}></c-tag-badge>
<c-tag-badge
onselected={handleBadgeSelected}
inbound-label={item.fields.Name.value}
inbound-icon={item.fields.Icon__c.value}
inbound-is-active={item.fields.Is_Active__c.value}
inbound-label-color={item.fields.Label_Color__c.value}
inbound-tag-color={item.fields.Tag_Color__c.value}
inbound-internal-value={item.fields.Internal_Value__c.value} >
</c-tag-badge>
</div>
</template>
</p>
Expand Down
@@ -1,11 +1,14 @@
/* eslint-disable @lwc/lwc/no-async-operation */
import { LightningElement, track, api, wire } from 'lwc';
import { getListUi } from 'lightning/uiListApi';
import { isNullOrWhiteSpace } from 'c/utils';
import TAG_ANYTHING_OBJECT from '@salesforce/schema/Tag_Anything__c';

const PLACEHOLDER_DEFAULT = 'Search Tag by Label';
const LISTVIEWAPINAME_DEFAULT = 'All';
const DELAY = 300;
const PAGESIZE = 2000;
const FIELDS_REQUIRED = [ 'Name', 'Is_Active__c', 'Label_Color__c', 'Tag_Color__c', 'Icon__c', 'Internal_Value__c' ];

export default class TagAnythingBrowser extends LightningElement {
@api placeholder = PLACEHOLDER_DEFAULT;
Expand All @@ -16,8 +19,14 @@ export default class TagAnythingBrowser extends LightningElement {
@track error;

_tagRecords;
_tagRecordsMap = {};

@wire(getListUi, { objectApiName: TAG_ANYTHING_OBJECT, listViewApiName: '$listView' })
@wire(getListUi, {
objectApiName: TAG_ANYTHING_OBJECT,
listViewApiName: '$listView',
pageSize: PAGESIZE,
fields: FIELDS_REQUIRED
})
wiredRecord({ error, data }) {
if (error) {
this.error = 'Unknown error';
Expand All @@ -31,18 +40,20 @@ export default class TagAnythingBrowser extends LightningElement {
}
else if (data) {
this._tagRecords = data.records.records;
this.prepareMapOfRecords(this._tagRecords, 'Internal_Value__c');
}
}

handleBadgeSelected(evt) {
this.dispatchEvent(new CustomEvent('badgeselected', { detail: evt.detail }));
console.log(JSON.stringify(this._tagRecordsMap[evt.detail]));
this.dispatchEvent(new CustomEvent('badgeselected', { detail: this._tagRecordsMap[evt.detail] }));
}

handleKeyUp(evt) {
window.clearTimeout(this.delayTimeout);
const query_term = evt.target.value;
this.delayTimeout = setTimeout(() => {
if (this.isNullOrWhiteSpace(query_term)) {
if (isNullOrWhiteSpace(query_term)) {
this.tagsToDisplay = [];
}
else {
Expand All @@ -61,8 +72,9 @@ export default class TagAnythingBrowser extends LightningElement {
return items_to_return;
}

// Probably this method could be inside a Utitlities.js
isNullOrWhiteSpace(string_value) {
return !string_value || string_value.length === 0 || /^\s*$/.test(string_value);
prepareMapOfRecords(records, key_field) {
for (let item of records) {
this._tagRecordsMap[item.fields[key_field].value] = item;
}
}
}
11 changes: 9 additions & 2 deletions force-app/main/default/lwc/tagBadge/tagBadge.js
Expand Up @@ -7,8 +7,9 @@ import ICON_FIELD from '@salesforce/schema/Tag_Anything__c.Icon__c';
import IS_ACTIVE_FIELD from '@salesforce/schema/Tag_Anything__c.Is_Active__c';
import LABEL_COLOR_FIELD from '@salesforce/schema/Tag_Anything__c.Label_Color__c';
import TAG_COLOR_FIELD from '@salesforce/schema/Tag_Anything__c.Tag_Color__c';
import INTERNAL_VALUE from '@salesforce/schema/Tag_Anything__c.Internal_Value__c';

const fields = [ NAME_FIELD, ICON_FIELD, IS_ACTIVE_FIELD, LABEL_COLOR_FIELD, TAG_COLOR_FIELD ];
const fields = [ NAME_FIELD, ICON_FIELD, IS_ACTIVE_FIELD, LABEL_COLOR_FIELD, TAG_COLOR_FIELD, INTERNAL_VALUE ];

export default class TagBadge extends LightningElement {
@api recordId;
Expand All @@ -18,6 +19,7 @@ export default class TagBadge extends LightningElement {
@api inboundIsActive = false;
@api inboundLabelColor = '#FFF';
@api inboundTagColor = '#EAEAEA';
@api inboundInternalValue = '';
@wire(getRecord, { recordId: '$recordId', fields })
wiredRecord;
Expand Down Expand Up @@ -59,7 +61,12 @@ export default class TagBadge extends LightningElement {
handleBadgeClick() {
if (!this.disableClick) {
this.dispatchEvent(new CustomEvent('selected', { detail: this.wiredRecord.data }));
if (!isNullOrWhiteSpace(this.recordId)) {
this.dispatchEvent(new CustomEvent('selected', { detail: this.wiredRecord.data }));
}
else {
this.dispatchEvent(new CustomEvent('selected', { detail: this.inboundInternalValue }));
}
}
}
}

0 comments on commit b2c3e81

Please sign in to comment.