Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 14:27:31 +05:30
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2025-01-01 11:26:42 +05:30
|
|
|
// Copyright (C) 2013 - 2025, The pgAdmin Development Team
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 14:27:31 +05:30
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
import {
|
|
|
|
SCHEMA_STATE_ACTIONS, getDepChange,
|
|
|
|
} from './common';
|
|
|
|
|
|
|
|
const getDeferredDepChange = (currPath, newState, oldState, action) => {
|
|
|
|
if(action.deferredDepChange) {
|
|
|
|
return action.deferredDepChange(currPath, newState, {
|
|
|
|
type: action.type,
|
|
|
|
path: action.path,
|
|
|
|
value: action.value,
|
|
|
|
depChange: action.depChange,
|
|
|
|
oldState: _.cloneDeep(oldState),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The main function which manipulates the session state based on actions.
|
|
|
|
*
|
|
|
|
* The state is managed based on path array of a particular key.
|
|
|
|
* For Eg. if the state is
|
|
|
|
* {
|
|
|
|
* key1: {
|
|
|
|
* ckey1: [
|
|
|
|
* {a: 0, b: 0},
|
|
|
|
* {a: 1, b: 1}
|
|
|
|
* ]
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* The path for b in first row will be '[key1, ckey1, 0, b]'.
|
|
|
|
* The path for second row of ckey1 will be '[key1, ckey1, 1]'.
|
|
|
|
*
|
|
|
|
* The path for key1 is '[key1]'.
|
|
|
|
* The state starts with path '[]'.
|
|
|
|
*/
|
|
|
|
export const sessDataReducer = (state, action) => {
|
|
|
|
let data = _.cloneDeep(state);
|
|
|
|
let rows, cid, deferredList;
|
|
|
|
data.__deferred__ = data.__deferred__ || [];
|
|
|
|
|
|
|
|
switch(action.type) {
|
|
|
|
case SCHEMA_STATE_ACTIONS.INIT:
|
|
|
|
data = action.payload;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHEMA_STATE_ACTIONS.BULK_UPDATE:
|
|
|
|
rows = _.get(data, action.path) || [];
|
|
|
|
rows.forEach((row) => { row[action.id] = false; });
|
|
|
|
_.set(data, action.path, rows);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHEMA_STATE_ACTIONS.SET_VALUE:
|
|
|
|
_.set(data, action.path, action.value);
|
|
|
|
// If there is any dep listeners get the changes.
|
|
|
|
data = getDepChange(action.path, data, state, action);
|
2024-09-18 07:48:09 +05:30
|
|
|
deferredList = getDeferredDepChange(
|
|
|
|
action.path, _.cloneDeep(data), state, action
|
|
|
|
);
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 14:27:31 +05:30
|
|
|
data.__deferred__ = deferredList || [];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHEMA_STATE_ACTIONS.ADD_ROW:
|
|
|
|
// Create id to identify a row uniquely, usefull when getting diff.
|
|
|
|
cid = _.uniqueId('c');
|
|
|
|
action.value['cid'] = cid;
|
|
|
|
|
|
|
|
if (action.addOnTop) {
|
|
|
|
rows = [].concat(action.value).concat(_.get(data, action.path) || []);
|
|
|
|
} else {
|
|
|
|
rows = (_.get(data, action.path) || []).concat(action.value);
|
|
|
|
}
|
|
|
|
|
|
|
|
_.set(data, action.path, rows);
|
|
|
|
|
|
|
|
// If there is any dep listeners get the changes.
|
|
|
|
data = getDepChange(action.path, data, state, action);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SCHEMA_STATE_ACTIONS.DELETE_ROW:
|
|
|
|
rows = _.get(data, action.path)||[];
|
|
|
|
rows.splice(action.value, 1);
|
|
|
|
|
|
|
|
_.set(data, action.path, rows);
|
|
|
|
|
|
|
|
// If there is any dep listeners get the changes.
|
|
|
|
data = getDepChange(action.path, data, state, action);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2025-01-24 13:58:21 +05:30
|
|
|
case SCHEMA_STATE_ACTIONS.MOVE_ROW: {
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 14:27:31 +05:30
|
|
|
rows = _.get(data, action.path)||[];
|
2025-01-24 13:58:21 +05:30
|
|
|
let row = rows[action.oldIndex];
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 14:27:31 +05:30
|
|
|
rows.splice(action.oldIndex, 1);
|
|
|
|
rows.splice(action.newIndex, 0, row);
|
|
|
|
|
|
|
|
_.set(data, action.path, rows);
|
|
|
|
|
|
|
|
break;
|
2025-01-24 13:58:21 +05:30
|
|
|
}
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 14:27:31 +05:30
|
|
|
case SCHEMA_STATE_ACTIONS.CLEAR_DEFERRED_QUEUE:
|
|
|
|
data.__deferred__ = [];
|
|
|
|
return data;
|
|
|
|
|
|
|
|
case SCHEMA_STATE_ACTIONS.DEFERRED_DEPCHANGE:
|
2024-09-18 20:55:01 +05:30
|
|
|
data = getDepChange(action.path, _.cloneDeep(data), state, action);
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 14:27:31 +05:30
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.__changeId = (data.__changeId || 0) + 1;
|
|
|
|
|
|
|
|
return data;
|
|
|
|
};
|
|
|
|
|