Skip to content

Commit 6bcf13f

Browse files
committed
overwrite default column preferences with cached preferences
1 parent 306e7a9 commit 6bcf13f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/lib/ColumnPreferences.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,29 @@ export function getColumnSort(sortBy, appId, className) {
7474
export function getOrder(cols, appId, className, defaultPrefs) {
7575

7676
let prefs = getPreferences(appId, className) || [ { name: 'objectId', width: DEFAULT_WIDTH, visible: true, cached: true } ];
77+
7778
if (defaultPrefs) {
78-
prefs = defaultPrefs;
79+
80+
// Check that every default pref is in the prefs array.
81+
defaultPrefs.forEach(defaultPrefsItem => {
82+
// If the default pref is not in the prefs: Add it.
83+
if (!prefs.find(prefsItem => defaultPrefsItem.name === prefsItem.name)) {
84+
prefs.push(defaultPrefsItem);
85+
}
86+
});
87+
88+
// Iterate over the current prefs
89+
prefs = prefs.map((prefsItem) => {
90+
// Get the default prefs item.
91+
const defaultPrefsItem = defaultPrefs.find(defaultPrefsItem => defaultPrefsItem.name === prefsItem.name) || {};
92+
// The values from the prefsItem object will overwrite those from the defaultPrefsItem object.
93+
return {
94+
// Set default width if not given.
95+
width: DEFAULT_WIDTH,
96+
...defaultPrefsItem,
97+
...prefsItem,
98+
}
99+
});
79100
}
80101
let order = [].concat(prefs);
81102
let seen = {};

0 commit comments

Comments
 (0)