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

Bugfix custom lookup #76

Merged
merged 3 commits into from
Feb 24, 2021
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lwc-utils",
"version": "1.5.3",
"version": "1.5.4",
"scripts": {
"eslint:validate": "eslint **/lwc/**/*.js",
"prettier:validate": "prettier --check '**/*.{cls,cmp,component,css,html,js,json,md,page,trigger,xml,yaml,yml}'",
Expand Down
30 changes: 7 additions & 23 deletions sfdx-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
"path": "utils-core",
"default": true,
"package": "LWC Utils",
"versionName": "ver 1.5.3",
"versionNumber": "1.5.3.NEXT",
"versionName": "ver 1.5.4",
"versionNumber": "1.5.4.NEXT",
"postInstallUrl": "https://github.com/tsalb/lwc-utils/releases",
"releaseNotesUrl": "https://github.com/tsalb/lwc-utils/releases"
},
{
"path": "utils-recipes",
"default": false,
"package": "LWC Utils Recipes",
"versionName": "ver 1.5.1",
"versionNumber": "1.5.1.NEXT",
"versionName": "ver 1.5.4",
"versionNumber": "1.5.4.NEXT",
"postInstallUrl": "https://github.com/tsalb/lwc-utils/releases",
"releaseNotesUrl": "https://github.com/tsalb/lwc-utils/releases",
"dependencies": [
{
"package": "LWC Utils@1.5.3-1"
"package": "LWC Utils@1.5.4-1"
}
]
}
Expand All @@ -29,26 +29,10 @@
"sourceApiVersion": "51.0",
"packageAliases": {
"LWC Utils Recipes": "0Ho1Q000000blJnSAI",
"LWC Utils Recipes@1.0.0-0": "04t1Q000001QhP3QAK",
"LWC Utils Recipes@1.0.1-1": "04t1Q000001QhTFQA0",
"LWC Utils Recipes@1.1.0-2": "04t1Q000001QhWnQAK",
"LWC Utils Recipes@1.2.0-1": "04t1Q000001QhvYQAS",
"LWC Utils Recipes@1.4.0-1": "04t1Q000001Qhy3QAC",
"LWC Utils Recipes@1.5.0-1": "04t1Q000001Qi0xQAC",
"LWC Utils Recipes@1.5.1-1": "04t1Q000001Qi2PQAS",
"LWC Utils Recipes@1.5.4-1": "04t1Q000001Qi2jQAC",
"LWC Utils": "0Ho1Q000000blJiSAI",
"LWC Utils@1.0.0-0": "04t1Q000001QhOyQAK",
"LWC Utils@1.0.1-1": "04t1Q000001QhRsQAK",
"LWC Utils@1.0.2-1": "04t1Q000001QhTAQA0",
"LWC Utils@1.1.0-1": "04t1Q000001QhWdQAK",
"LWC Utils@1.1.1-2": "04t1Q000001QhnjQAC",
"LWC Utils@1.2.0-1": "04t1Q000001QhtwQAC",
"LWC Utils@1.2.1-1": "04t1Q000001QhvEQAS",
"LWC Utils@1.3.0-1": "04t1Q000001QhvTQAS",
"LWC Utils@1.4.0-3": "04t1Q000001QhyDQAS",
"LWC Utils@1.5.0-1": "04t1Q000001Qi0sQAC",
"LWC Utils@1.5.1-2": "04t1Q000001Qi2KQAS",
"LWC Utils@1.5.2-1": "04t1Q000001Qi2UQAS",
"LWC Utils@1.5.3-1": "04t1Q000001Qi2ZQAS"
"LWC Utils@1.5.4-1": "04t1Q000001Qi2eQAC"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<targetConfig targets="lightning__AppPage, lightning__HomePage">
<property name="title" label="Title" type="String"/>
<property name="showRecordCount" label="Show Record Count" type="Boolean" default="false"/>
<property name="actionConfigDevName" label="Action Configuration" type="String" description="Configure table and row actions with a record in Play_Datatable_Config__mdt"/>
<property name="lookupConfigDevName" label="Lookup Configuration" type="String" description="Configure inline edit lookup search behavior with a record in Play_Datatable_Config__mdt"/>
<property name="actionConfigDevName" label="Action Configuration" type="String" description="Configure table and row actions with a record in Datatable_Config__mdt"/>
<property name="lookupConfigDevName" label="Lookup Configuration" type="String" description="Configure inline edit lookup search behavior with a record in Datatable_Config__mdt"/>
<property name="useRelativeMaxHeight" label="Limit Height (Relative to screen)" type="Boolean" description="Force table height to 60% of the vertical screen space. To set a custom percentage, use this in conjunction with Custom Relative Max Height" default="false"/>
<property name="customRelativeMaxHeight" label="Custom Relative Max Height" type="String" description="Set custom max height (0-100) relative to the vertical screen space. Limit Height must first be enabled." default=""/>
<property name="useLoadStyleHackForOverflow" label=".Allow Overflow (EXPERIMENTAL)" type="Boolean" description="Enable this when your datatable has a small number of rows but you need in-line edit. This will override any custom table heights and allow for picklist and lookup edit menus to display on top of th edatatable. However, you may experience some weird CSS issues." default="false"/>
Expand Down
42 changes: 7 additions & 35 deletions utils-core/main/default/lwc/datatable/datatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,6 @@ export default class Datatable extends LightningElement {
this._draftValuesMap = new Map();
this._draftSuccessIds = new Set();
this._fuseData = undefined;
this._hasEditablePicklist = false;
this._hasEditableLookup = false;
this._originalTableData = [];
}

Expand All @@ -313,8 +311,6 @@ export default class Datatable extends LightningElement {

// private - global search
_fuseData;
_hasEditablePicklist = false;
_hasEditableLookup = false;
_originalTableData = [];

// For future enhancements
Expand All @@ -324,7 +320,6 @@ export default class Datatable extends LightningElement {
this._notifySingleError('getObjectInfo error', error);
} else if (data) {
this._objectInfo = data;
//console.log(this._objectInfo);
}
}

Expand All @@ -335,7 +330,6 @@ export default class Datatable extends LightningElement {
this._notifySingleError('getActionConfig error', error);
} else if (data) {
this._actionConfigs = data;
//console.log(this._actionConfigs);

// Table Actions
this.primaryConfig = this._actionConfigs.find(cfg => cfg.Type__c === TABLE_ACTION_STRING && cfg.Order__c === 1);
Expand Down Expand Up @@ -364,6 +358,7 @@ export default class Datatable extends LightningElement {
this._notifySingleError('getLookupEditConfig error', error);
} else if (data) {
this._lookupConfigData = data;
this._initializeLookupConfigData();
}
}

Expand Down Expand Up @@ -396,15 +391,13 @@ export default class Datatable extends LightningElement {

// Keeps lexical scope correct
handleEditableCellRendered = () => {
// This event is emitted from every editable cell, which is why needs to be debounced
window.clearTimeout(this._delayEditableCellRendered);
// eslint-disable-next-line @lwc/lwc/no-async-operation
this._delayEditableCellRendered = setTimeout(() => {
if (this._hasEditableLookup) {
this._initializeLookupConfigData();
}
if (this._hasEditablePicklist) {
this._initializeRecordTypeIdData();
}
// Editable cells need these even if the pencil icon is not enabled
this._initializeLookupConfigData();
this._initializeRecordTypeIdData();
}, 500);
};

Expand Down Expand Up @@ -525,7 +518,6 @@ export default class Datatable extends LightningElement {
}
}
};
//console.log(flowPayload);
this.messageService.dialogService(flowPayload);
}

Expand Down Expand Up @@ -660,11 +652,8 @@ export default class Datatable extends LightningElement {
this._draftValuesMap.set(draft[this.keyField], { ...changedData, ...draft });
});

//console.log(this._draftValuesMap);

if (this._draftValuesMap.size > 0) {
this.draftValues = [...this._draftValuesMap.values()];
//console.log(this.draftValues);
}
}

Expand All @@ -678,10 +667,8 @@ export default class Datatable extends LightningElement {
// Avoid using the event because the payload doesn't have name compound fields
async handleSave() {
if (!this.isSaveToServer) {
//console.log(this.draftValues);
// For collectionDatatable we just write user values to tableData, regardless of validation
const rowKeyToDraftValuesMap = new Map(this.draftValues.map(draft => [draft[this.keyField], draft]));
//console.log(rowKeyToDraftValuesMap);
// Sets draft values directly onto tableData
this.tableData = this.tableData.map(row => {
const rowDraftValues = rowKeyToDraftValuesMap.get(row[this.keyField]);
Expand Down Expand Up @@ -709,15 +696,10 @@ export default class Datatable extends LightningElement {
])
);

//console.log(rowKeyToRowNumberMap);
//console.log(this.draftValues);

// On partial save rows, this helps signal which rows succeeded by clearing them out
this.showSpinner = true;
const saveResults = await tableService.updateDraftValues(this.draftValues, rowKeyToRowNumberMap);

//console.log(saveResults);

if (saveResults.errors.rows && Object.keys(saveResults.errors.rows).length) {
this.saveErrors = saveResults.errors;
}
Expand Down Expand Up @@ -777,18 +759,8 @@ export default class Datatable extends LightningElement {
}
}
if (col.type === 'customLookup') {
// Initiate apex wire adapter here before editable cells fully render
// Warm the getLookupConfig wire adapter before editable cells fully render
this._lookupConfigDevName = this.lookupConfigDevName || DATATABLE_LOOKUP_CONFIG_DEFAULT;
// Supports global search
if (col.editable && !this._hasEditableLookup) {
this._hasEditableLookup = true;
}
}
if (col.type === 'customPicklist') {
// Supports global search
if (col.editable && !this._hasEditablePicklist) {
this._hasEditablePicklist = true;
}
}
finalColumns.push(col);
}
Expand Down Expand Up @@ -865,7 +837,6 @@ export default class Datatable extends LightningElement {

_getRowActions(row, doneCallback) {
let actions = [];
//console.log(this.rowActionConfigs);
// These are pre-sorted by order by server
this.rowActionConfigs.forEach(cfg => {
// "Native" actions
Expand Down Expand Up @@ -940,6 +911,7 @@ export default class Datatable extends LightningElement {
}

_initializeLookupConfigData() {
// Calling function assumes this._lookupConfigData is populated
this.messageService.publish({ key: 'lookupconfigload', value: { lookupConfigs: this._lookupConfigData } });
}

Expand Down