Skip to content

Commit

Permalink
overwrited default column preferences with cached preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
vince1995 committed Oct 25, 2021
1 parent 306e7a9 commit 33c1015
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/lib/ColumnPreferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};
Expand Down

0 comments on commit 33c1015

Please sign in to comment.