Skip to content

EspoCRM – Open Source CRM Application

list view: fetch only visible columns

Yuri Kuznetsov94b15e8e8ea3
diff --git a/client/src/helpers/list/select-provider.js b/client/src/helpers/list/select-provider.js
index 485caf8c66..61fed0496d 100644
--- a/client/src/helpers/list/select-provider.js
+++ b/client/src/helpers/list/select-provider.js
@@ -26,18 +26,34 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
+import {inject} from 'di';
+import LayoutManager from 'layout-manager';
+import Metadata from 'metadata';
+import FieldManager from 'field-manager';
+
class SelectProvider {
+
/**
- * @param {module:layout-manager} layoutManager
- * @param {module:metadata} metadata
- * @param {module:field-manager} fieldManager
+ * @type {LayoutManager}
+ * @private
*/
- constructor(layoutManager, metadata, fieldManager) {
- this.layoutManager = layoutManager;
- this.metadata = metadata;
- this.fieldManager = fieldManager;
- }
+ @inject(LayoutManager)
+ layoutManager
+
+ /**
+ * @type {Metadata}
+ * @private
+ */
+ @inject(Metadata)
+ metadata
+
+ /**
+ * @type {FieldManager}
+ * @private
+ */
+ @inject(FieldManager)
+ fieldManager
/**
* Get select attributes.
@@ -61,27 +77,30 @@ class SelectProvider {
*
* @param {string} entityType
* @param {module:views/record/list~columnDefs[]} listLayout
+ * @param {import('helpers/list/settings').default} [settings]
* @return {string[]}
*/
- getFromLayout(entityType, listLayout) {
- let list = [];
+ getFromLayout(entityType, listLayout, settings) {
+ const list = [];
listLayout.forEach(item => {
if (!item.name) {
return;
}
+ if (settings?.isColumnHidden(item.name, item.hidden)) {
+ console.log(item.name);
+ return;
+ }
+
const field = item.name;
- const fieldType = this.metadata.get(['entityDefs', entityType, 'fields', field, 'type']);
+ const type = this.metadata.get(`entityDefs.${entityType}.fields.${field}.type`);
- if (!fieldType) {
+ if (!type) {
return;
}
- list = [
- this.fieldManager.getEntityTypeFieldAttributeList(entityType, field),
- ...list
- ];
+ list.push(...this.fieldManager.getEntityTypeFieldAttributeList(entityType, field));
});
return list;
diff --git a/client/src/views/admin/extensions/index.js b/client/src/views/admin/extensions/index.js
index ce7ec5759b..0ca2bf20bd 100644
--- a/client/src/views/admin/extensions/index.js
+++ b/client/src/views/admin/extensions/index.js
@@ -88,11 +88,7 @@ class IndexExtensionsView extends View {
}
setup() {
- const selectProvider = new SelectProvider(
- this.getHelper().layoutManager,
- this.getHelper().metadata,
- this.getHelper().fieldManager
- );
+ const selectProvider = new SelectProvider();
this.wait(
this.getCollectionFactory()
diff --git a/client/src/views/record/kanban.js b/client/src/views/record/kanban.js
index 7989651cd5..b3bebeeb3d 100644
--- a/client/src/views/record/kanban.js
+++ b/client/src/views/record/kanban.js
@@ -1456,6 +1456,14 @@ class KanbanRecordView extends ListRecordView {
async afterSettingsChange(options) {
this._internalLayout = null;
+ if (options.action === 'toggleColumn' || options.action === 'resetToDefault') {
+ const selectAttributes = await this.getSelectAttributeList();
+
+ if (selectAttributes) {
+ this.collection.data.select = selectAttributes.join(',');
+ }
+ }
+
Espo.Ui.notifyWait();
await this.collection.fetch({maxSize: this.collection.maxSize});
diff --git a/client/src/views/record/list.js b/client/src/views/record/list.js
index 1209d1f39a..c9c466a3e9 100644
--- a/client/src/views/record/list.js
+++ b/client/src/views/record/list.js
@@ -2609,31 +2609,25 @@ class ListRecordView extends View {
return null;
}
- if (this.listLayout) {
- const attributeList = this.fetchAttributeListFromLayout();
-
- callback(attributeList);
-
- return attributeList;
- }
-
- return await (
- new Promise(resolve => {
+ if (!this.listLayout) {
+ await new Promise(resolve => {
this._loadListLayout(listLayout => {
this.listLayout = listLayout;
- let attributeList = this.fetchAttributeListFromLayout();
+ resolve();
+ });
+ });
+ }
- if (this.mandatorySelectAttributeList) {
- attributeList = attributeList.concat(this.mandatorySelectAttributeList);
- }
+ const attributeList = this.fetchAttributeListFromLayout();
- callback(attributeList);
+ if (this.mandatorySelectAttributeList) {
+ attributeList.push(...this.mandatorySelectAttributeList);
+ }
- resolve(attributeList);
- });
- })
- );
+ callback(attributeList);
+
+ return attributeList;
}
/**
@@ -2641,13 +2635,9 @@ class ListRecordView extends View {
* @return {string[]}
*/
fetchAttributeListFromLayout() {
- const selectProvider = new SelectProvider(
- this.getHelper().layoutManager,
- this.getHelper().metadata,
- this.getHelper().fieldManager
- );
+ const selectProvider = new SelectProvider();
- return selectProvider.getFromLayout(this.entityType, this.listLayout);
+ return selectProvider.getFromLayout(this.entityType, this.listLayout, this._listSettingsHelper);
}
/**
@@ -3739,6 +3729,14 @@ class ListRecordView extends View {
return;
}
+ if (options.action === 'toggleColumn' || options.action === 'resetToDefault') {
+ const selectAttributes = await this.getSelectAttributeList();
+
+ if (selectAttributes) {
+ this.collection.data.select = selectAttributes.join(',');
+ }
+ }
+
if (
options.action === 'toggleColumn' &&
!this._listSettingsHelper.getHiddenColumnMap()[options.column] &&
@@ -3759,7 +3757,7 @@ class ListRecordView extends View {
await this.collection.fetch();
- Espo.Ui.notify(false);
+ Espo.Ui.notify();
}
/**