Introduce custom React Hook useSchemaState to simplify SchemaView component. #7776

Changes include: 
- Simplify current SchemaView code
- Add ability to reuse the schema data & state management implementation outside the SchemaDialogView component.
- Further split components in small and manageable separate files.
- Removed the 'DepListenerContext' context as there was no need for separate context.
- Added a reload functionality in the 'useSchemaState'
- Changes in feature tests.
This commit is contained in:
Ashesh Vashi
2024-08-02 09:59:01 +05:30
committed by GitHub
parent 546806c40c
commit 52af8d3e49
20 changed files with 2190 additions and 1570 deletions

View File

@@ -491,7 +491,9 @@ export default function PreferencesComponent({ ...props }) {
function savePreferences(data, initVal) {
let _data = [];
for (const [key, value] of Object.entries(data.current)) {
let _metadata = prefSchema.current.schemaFields.filter((el) => { return el.id == key; });
let _metadata = prefSchema.current.schemaFields.filter(
(el) => { return el.id == key; }
);
if (_metadata.length > 0) {
let val = getCollectionValue(_metadata, value, initVal);
_data.push({
@@ -525,7 +527,11 @@ export default function PreferencesComponent({ ...props }) {
data: save_data,
}).then(() => {
let requiresTreeRefresh = save_data.some((s)=>{
return s.name=='show_system_objects'||s.name=='show_empty_coll_nodes'||s.name.startsWith('show_node_')||s.name=='hide_shared_server'||s.name=='show_user_defined_templates';
return (
s.name=='show_system_objects' || s.name=='show_empty_coll_nodes' ||
s.name.startsWith('show_node_') || s.name=='hide_shared_server' ||
s.name=='show_user_defined_templates'
);
});
let requires_refresh = false;
for (const [key] of Object.entries(data.current)) {
@@ -536,11 +542,15 @@ export default function PreferencesComponent({ ...props }) {
if (requiresTreeRefresh) {
pgAdmin.Browser.notifier.confirm(
gettext('Object explorer refresh required'),
gettext('An object explorer refresh is required. Do you wish to refresh it now?'),
gettext(
'An object explorer refresh is required. Do you wish to refresh it now?'
),
function () {
pgAdmin.Browser.tree.destroy().then(
() => {
pgAdmin.Browser.Events.trigger('pgadmin-browser:tree:destroyed', undefined, undefined);
pgAdmin.Browser.Events.trigger(
'pgadmin-browser:tree:destroyed', undefined, undefined
);
return true;
}
);