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

Saving settings to local storage #3017

Merged
merged 5 commits into from
Mar 29, 2021
Merged

Saving settings to local storage #3017

merged 5 commits into from
Mar 29, 2021

Conversation

ActiveChooN
Copy link
Contributor

@ActiveChooN ActiveChooN commented Mar 25, 2021

Motivation and context

This PR provide saving user settings to local storage. Resolved #1209

How has this been tested?

Manually

Checklist

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.
  • I have updated the license header for each file (see an example below)
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

@ActiveChooN ActiveChooN added enhancement New feature or request need test labels Mar 25, 2021
@coveralls
Copy link

coveralls commented Mar 25, 2021

Coverage Status

Coverage increased (+0.008%) to 74.974% when pulling 14719bc on dk/saving-settings into 57385fa on develop.

@bsekachev bsekachev self-assigned this Mar 26, 2021
CHANGELOG.md Outdated Show resolved Hide resolved
Comment on lines +46 to +64
try {
const newSettings: any = {};
const loadedSettings = JSON.parse(localStorage.getItem('clientSettings') as string);
for (const [sectionKey, section] of Object.entries(settings)) {
for (const [key, value] of Object.entries(section)) {
let settedValue = value;
if (sectionKey in loadedSettings && key in loadedSettings[sectionKey]) {
settedValue = loadedSettings[sectionKey][key];
}
if (!(sectionKey in newSettings)) newSettings[sectionKey] = {};
newSettings[sectionKey][key] = settedValue;
}
}
dispatch(setSettings(newSettings));
} catch {
notification.error({
message: 'Failed to load settings from local storage',
});
}
Copy link
Member

@bsekachev bsekachev Mar 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not to do it in defaultState for settings reducer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First of all, code for saving and restoring settings is placed in the same place. Secondly, we will try to load settings after first render, so it's a very small time gain for the first render, i guess. And it will be easier to modify this solution for server side config loading, for example.

Comment on lines +76 to +83
<Tooltip title='Will save settings from this page and appearance settings on standard workspace page in browser'>
<Button type='primary' onClick={onSaveSettings}>
Save
</Button>
</Tooltip>
<Button type='default' onClick={onClose}>
Close
</Button>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update dock. Do we need button close? We have "X" and also click everywhere out of the modal closes the modal

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's default behaviour for the modal element.

@bsekachev bsekachev merged commit f5277f9 into develop Mar 29, 2021
@bsekachev bsekachev deleted the dk/saving-settings branch March 30, 2021 07:54
@ActiveChooN
Copy link
Contributor Author

@TOsmanov, hi, can you adjust documentation according this new feature, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Saving settings on the server
3 participants