From 33c1015414f2c82d467b95e044a1a9aec8548d63 Mon Sep 17 00:00:00 2001 From: Vincent Semrau Date: Mon, 25 Oct 2021 13:49:30 +0200 Subject: [PATCH] overwrited default column preferences with cached preferences --- src/lib/ColumnPreferences.js | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/src/lib/ColumnPreferences.js b/src/lib/ColumnPreferences.js index 56f279ba2b..a9c691d0ef 100644 --- a/src/lib/ColumnPreferences.js +++ b/src/lib/ColumnPreferences.js @@ -74,8 +74,29 @@ export function getColumnSort(sortBy, appId, className) { export function getOrder(cols, appId, className, defaultPrefs) { let prefs = getPreferences(appId, className) || [ { name: 'objectId', width: DEFAULT_WIDTH, visible: true, cached: true } ]; + if (defaultPrefs) { - prefs = defaultPrefs; + + // Check that every default pref is in the prefs array. + defaultPrefs.forEach(defaultPrefsItem => { + // If the default pref is not in the prefs: Add it. + if (!prefs.find(prefsItem => defaultPrefsItem.name === prefsItem.name)) { + prefs.push(defaultPrefsItem); + } + }); + + // Iterate over the current prefs + prefs = prefs.map((prefsItem) => { + // Get the default prefs item. + const defaultPrefsItem = defaultPrefs.find(defaultPrefsItem => defaultPrefsItem.name === prefsItem.name) || {}; + // The values from the prefsItem object will overwrite those from the defaultPrefsItem object. + return { + // Set default width if not given. + width: DEFAULT_WIDTH, + ...defaultPrefsItem, + ...prefsItem, + } + }); } let order = [].concat(prefs); let seen = {};