Skip to content

Commit

Permalink
fix: manual column preferences are overwritten by columnPreference op…
Browse files Browse the repository at this point in the history
…tion on page refresh (#1881)
  • Loading branch information
vince1995 authored Oct 27, 2021
1 parent 6917ef7 commit 7232b0b
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 7232b0b

Please sign in to comment.