-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
base: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
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
|
tests/cypress/e2e/actions_tasks/case_68_saving_settings_local_storage.js
Show resolved
Hide resolved
cvat-ui/src/components/header/settings-modal/shortcut-settings.tsx
Outdated
Show resolved
Hide resolved
cvat-ui/src/components/header/settings-modal/settings-modal.tsx
Outdated
Show resolved
Hide resolved
|
onClose(); | ||
}, [onClose, settings, shortcuts]); | ||
updateCachedSettings(settings, shortcuts); | ||
}, [setSettingsInitialized, settings, shortcuts]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, [setSettingsInitialized, settings, shortcuts]); | |
}, [settingsInitialized, settings, shortcuts]); |
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, | ||
}; | ||
} | ||
} |
There was a problem hiding this comment.
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?
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(); |
There was a problem hiding this comment.
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
Motivation and context
save
button on the settings modal, now settings are auto savedHow has this been tested?
Checklist
develop
branchLicense
Feel free to contact the maintainers if that's a concern.