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

Added automatic saving for settings and persistent storage for image filter settings #9032

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from

Conversation

klakhov
Copy link
Contributor

@klakhov klakhov commented Jan 31, 2025

Motivation and context

  • Removed save button on the settings modal, now settings are auto saved
  • Added serialization for image processing filters so they can be restored automatically

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
  • I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)

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.

@klakhov klakhov added the ui/ux label Jan 31, 2025
@klakhov klakhov requested a review from bsekachev as a code owner January 31, 2025 12:17
@codecov-commenter
Copy link

codecov-commenter commented Feb 3, 2025

Codecov Report

Attention: Patch coverage is 84.12698% with 10 lines in your changes missing coverage. Please review.

Project coverage is 73.94%. Comparing base (fb3bde4) to head (2582dcd).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #9032      +/-   ##
===========================================
+ Coverage    73.91%   73.94%   +0.03%     
===========================================
  Files          428      428              
  Lines        44530    44593      +63     
  Branches      3881     3894      +13     
===========================================
+ Hits         32915    32975      +60     
- Misses       11615    11618       +3     
Components Coverage Δ
cvat-ui 77.49% <84.12%> (+0.05%) ⬆️
cvat-server 71.00% <0.00%> (ø)

@klakhov klakhov requested a review from nmanovic as a code owner February 4, 2025 06:44
onClose();
}, [onClose, settings, shortcuts]);
updateCachedSettings(settings, shortcuts);
}, [setSettingsInitialized, settings, shortcuts]);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
}, [setSettingsInitialized, settings, shortcuts]);
}, [settingsInitialized, settings, shortcuts]);

Comment on lines +494 to +521
const settingsForSaving: any = {
shortcuts: {
keyMap: {},
},
imageFilters: [],
};
const supportedImageFilters = [ImageFilterAlias.GAMMA_CORRECTION];
for (const [key, value] of Object.entries(settings)) {
if (['player', 'workspace'].includes(key)) {
settingsForSaving[key] = value;
}
if (key === 'imageFilters') {
const filters = [];
for (const filter of value) {
if (supportedImageFilters.includes(filter.alias)) {
filters.push(filter.modifier.toJSON());
}
}
settingsForSaving.imageFilters = filters;
}
}
for (const [key] of Object.entries(shortcuts.keyMap)) {
if (key in shortcuts.defaultState) {
settingsForSaving.shortcuts.keyMap[key] = {
sequences: shortcuts.keyMap[key].sequences,
};
}
}
Copy link
Member

Choose a reason for hiding this comment

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

What do you think about some refactoring?

Suggested change
const settingsForSaving: any = {
shortcuts: {
keyMap: {},
},
imageFilters: [],
};
const supportedImageFilters = [ImageFilterAlias.GAMMA_CORRECTION];
for (const [key, value] of Object.entries(settings)) {
if (['player', 'workspace'].includes(key)) {
settingsForSaving[key] = value;
}
if (key === 'imageFilters') {
const filters = [];
for (const filter of value) {
if (supportedImageFilters.includes(filter.alias)) {
filters.push(filter.modifier.toJSON());
}
}
settingsForSaving.imageFilters = filters;
}
}
for (const [key] of Object.entries(shortcuts.keyMap)) {
if (key in shortcuts.defaultState) {
settingsForSaving.shortcuts.keyMap[key] = {
sequences: shortcuts.keyMap[key].sequences,
};
}
}
const supportedImageFilters = [ImageFilterAlias.GAMMA_CORRECTION];
const settingsForSaving = {
player: settings.player,
workspace: settings.workspace,
shortcuts: {
keyMap: Object.entries(shortcuts.keyMap).reduce(() => { ...TODO ...}),
},
imageFilters: settings.imageFilters.filter((imageFilter) => supportedImageFilters.includes(filter.alias)).map((imageFilter) => imageFilter.modifier.toJSON()),
};


export function restoreSettingsAsync(): ThunkAction {
return async (dispatch, getState): Promise<void> => {
const state: CombinedState = getState();
Copy link
Member

@bsekachev bsekachev Feb 11, 2025

Choose a reason for hiding this comment

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

I understand that you just copypasted the code, but the current implementation looks mind blowing. So, if you have ideas how it can be refactored, you are welcome

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

Successfully merging this pull request may close these issues.

3 participants