Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: manual column preferences are overwritten by columnPreference option on page refresh #1881

Merged
merged 2 commits into from
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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