2021-08-23 03:10:14 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2024-01-01 02:43:48 -06:00
|
|
|
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2021-08-23 03:10:14 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2022-01-28 05:50:34 -06:00
|
|
|
import { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/SchemaView';
|
2021-08-23 03:10:14 -05:00
|
|
|
import _ from 'lodash';
|
|
|
|
import { getNodeTableSchema, LikeSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
|
|
|
|
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
|
2022-01-28 05:50:34 -06:00
|
|
|
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
2023-10-23 07:13:17 -05:00
|
|
|
import pgAdmin from '../fake_pgadmin';
|
2021-08-23 03:10:14 -05:00
|
|
|
|
|
|
|
function getFieldDepChange(schema, id) {
|
|
|
|
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
|
|
|
}
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
describe('TableSchema', () => {
|
|
|
|
|
|
|
|
const createTableSchemaObject = () => getNodeTableSchema({
|
|
|
|
server: {
|
|
|
|
_id: 1,
|
|
|
|
},
|
|
|
|
schema: {
|
|
|
|
_label: 'public',
|
|
|
|
}
|
|
|
|
}, {}, {
|
|
|
|
Nodes: {table: {}},
|
|
|
|
serverInfo: {
|
|
|
|
1: {
|
|
|
|
user: {
|
|
|
|
name: 'Postgres',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
let schemaObj = createTableSchemaObject();
|
2021-08-23 03:10:14 -05:00
|
|
|
let getInitData = ()=>Promise.resolve({});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
beforeAll(() => {
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(nodeAjax, 'getNodeAjaxOptions').mockReturnValue(Promise.resolve([]));
|
|
|
|
jest.spyOn(nodeAjax, 'getNodeListByName').mockReturnValue(Promise.resolve([]));
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
beforeEach(() => {
|
2022-01-28 05:50:34 -06:00
|
|
|
genericBeforeEach();
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('create', async () => {
|
|
|
|
await getCreateView(createTableSchemaObject());
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('edit', async () => {
|
|
|
|
await getEditView(createTableSchemaObject(), getInitData);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('properties', async () => {
|
|
|
|
await getPropertiesView(createTableSchemaObject(), getInitData);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('getTableOid', () => {
|
2021-08-23 03:10:14 -05:00
|
|
|
schemaObj.inheritedTableList = [
|
|
|
|
{label: 'tab1', tid: 140391},
|
|
|
|
{label: 'tab2', tid: 180191}
|
|
|
|
];
|
|
|
|
expect(schemaObj.getTableOid('tab2')).toBe(180191);
|
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('canEditDeleteRowColumns', () => {
|
2021-08-23 03:10:14 -05:00
|
|
|
expect(schemaObj.canEditDeleteRowColumns({inheritedfrom: 1234})).toBe(false);
|
|
|
|
expect(schemaObj.canEditDeleteRowColumns({inheritedfrom: null})).toBe(true);
|
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('LikeSchema typname change', () => {
|
2021-08-23 03:10:14 -05:00
|
|
|
let likeSchemaObj = new LikeSchema([]);
|
|
|
|
/* Dummy */
|
|
|
|
likeSchemaObj.top = new LikeSchema([]);
|
|
|
|
let depResp = getFieldDepChange(likeSchemaObj, 'like_relation')({typname: 'type1'}, ['typname']);
|
|
|
|
expect(depResp).toEqual({
|
|
|
|
like_relation: null,
|
|
|
|
like_default_value: false,
|
|
|
|
like_constraints: false,
|
|
|
|
like_indexes: false,
|
|
|
|
like_storage: false,
|
|
|
|
like_comments: false,
|
2023-08-07 00:50:04 -05:00
|
|
|
like_compression: false,
|
|
|
|
like_generated: false,
|
|
|
|
like_identity: false,
|
|
|
|
like_statistics: false
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
describe('typname change', () => {
|
2021-08-23 03:10:14 -05:00
|
|
|
let confirmSpy;
|
|
|
|
let deferredDepChange;
|
|
|
|
let oftypeColumns = [
|
|
|
|
{name: 'id'}
|
|
|
|
];
|
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 03:57:31 -05:00
|
|
|
beforeEach(() => {
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(schemaObj, 'changeColumnOptions');
|
|
|
|
jest.spyOn(schemaObj, 'getTableOid').mockReturnValue(140391);
|
|
|
|
confirmSpy = jest.spyOn(pgAdmin.Browser.notifier, 'confirm');
|
2021-08-23 03:10:14 -05:00
|
|
|
deferredDepChange = _.find(schemaObj.fields, (f)=>f.id=='typname')?.deferredDepChange;
|
|
|
|
schemaObj.ofTypeTables = [
|
|
|
|
{label: 'type1', oftype_columns: oftypeColumns}
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2022-01-28 05:50:34 -06:00
|
|
|
let onDepChangeAction = (depChange, done)=> {
|
|
|
|
expect(depChange()).toEqual({
|
|
|
|
columns: oftypeColumns,
|
|
|
|
primary_key: [],
|
|
|
|
foreign_key: [],
|
|
|
|
exclude_constraint: [],
|
|
|
|
unique_constraint: [],
|
|
|
|
partition_keys: [],
|
|
|
|
partitions: [],
|
|
|
|
});
|
|
|
|
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(oftypeColumns);
|
|
|
|
done();
|
|
|
|
};
|
|
|
|
|
2021-08-23 03:10:14 -05:00
|
|
|
it('initial selection with OK', (done)=>{
|
|
|
|
let state = {typname: 'type1'};
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
typname: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
onDepChangeAction(depChange, done);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
/* Press OK */
|
2023-10-23 07:13:17 -05:00
|
|
|
confirmSpy.mock.calls[0][2]();
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('initial selection with Cancel', (done)=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
confirmSpy.mockClear();
|
2021-08-23 03:10:14 -05:00
|
|
|
let state = {typname: 'type1'};
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
typname: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
|
|
|
expect(depChange()).toEqual({
|
|
|
|
typname: null,
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
/* Press Cancel */
|
2023-10-23 07:13:17 -05:00
|
|
|
confirmSpy.mock.calls[0][3]();
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('later selection', (done)=>{
|
|
|
|
let state = {typname: 'type1'};
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
typname: 'typeold',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
onDepChangeAction(depChange, done);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('empty', (done)=>{
|
|
|
|
let state = {typname: null};
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
typname: null,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
|
|
|
expect(depChange()).toBeUndefined();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
describe('coll_inherits change', () => {
|
2021-08-23 03:10:14 -05:00
|
|
|
let deferredDepChange;
|
|
|
|
let inheritCol = {name: 'id'};
|
2022-01-28 05:50:34 -06:00
|
|
|
let onRemoveAction = (depChange, state, done)=> {
|
|
|
|
let finalCols = [{name: 'desc'}];
|
|
|
|
expect(depChange(state)).toEqual({
|
|
|
|
adding_inherit_cols: false,
|
|
|
|
columns: finalCols,
|
|
|
|
});
|
|
|
|
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(finalCols);
|
|
|
|
done();
|
|
|
|
};
|
2021-08-23 03:10:14 -05:00
|
|
|
|
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 03:57:31 -05:00
|
|
|
beforeEach(() => {
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(schemaObj, 'changeColumnOptions');
|
|
|
|
jest.spyOn(schemaObj, 'getTableOid').mockReturnValue(140391);
|
|
|
|
jest.spyOn(schemaObj, 'getColumns').mockReturnValue(Promise.resolve([inheritCol]));
|
2021-08-23 03:10:14 -05:00
|
|
|
deferredDepChange = _.find(schemaObj.fields, (f)=>f.id=='coll_inherits')?.deferredDepChange;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add first selection', (done)=>{
|
|
|
|
let state = {columns: [], coll_inherits: ['table1']};
|
|
|
|
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
coll_inherits: [],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
|
|
|
let finalCols = [newCol];
|
|
|
|
expect(depChange(state)).toEqual({
|
|
|
|
adding_inherit_cols: false,
|
|
|
|
columns: finalCols,
|
|
|
|
});
|
|
|
|
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(finalCols);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('add more', (done)=>{
|
|
|
|
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
|
|
|
let state = {columns: [newCol], coll_inherits: ['table1', 'table2']};
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
coll_inherits: ['table1'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
2021-10-21 00:29:52 -05:00
|
|
|
let finalCols = [newCol];
|
2021-08-23 03:10:14 -05:00
|
|
|
expect(depChange(state)).toEqual({
|
|
|
|
adding_inherit_cols: false,
|
2021-10-21 00:29:52 -05:00
|
|
|
columns: [newCol],
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(finalCols);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('remove one table', (done)=>{
|
|
|
|
inheritCol.inheritedid = 140391;
|
|
|
|
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
|
|
|
let state = {columns: [{name: 'desc'}, newCol], coll_inherits: ['table1']};
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
coll_inherits: ['table1', 'table2'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
onRemoveAction(depChange, state, done);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('remove all', (done)=>{
|
|
|
|
inheritCol.inheritedid = 140391;
|
|
|
|
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
|
|
|
let state = {columns: [{name: 'desc'}, newCol], coll_inherits: []};
|
|
|
|
let deferredPromise = deferredDepChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
coll_inherits: ['table1'],
|
|
|
|
},
|
|
|
|
});
|
|
|
|
deferredPromise.then((depChange)=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
onRemoveAction(depChange, state, done);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('depChange', () => {
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(schemaObj, 'getTableOid').mockReturnValue(140391);
|
2021-08-23 03:10:14 -05:00
|
|
|
let state = {};
|
|
|
|
|
|
|
|
state.is_partitioned = true;
|
|
|
|
state.coll_inherits = ['table1'];
|
|
|
|
expect(getFieldDepChange(schemaObj, 'coll_inherits')(state, ['is_partitioned'], null, {
|
|
|
|
type: SCHEMA_STATE_ACTIONS.SET_VALUE,
|
|
|
|
path: ['is_partitioned'],
|
|
|
|
})).toEqual({
|
|
|
|
coll_inherits: [],
|
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(schemaObj, 'getServerVersion').mockReturnValue(100000);
|
2021-08-23 03:10:14 -05:00
|
|
|
schemaObj.constraintsObj.top = schemaObj;
|
|
|
|
expect(getFieldDepChange(schemaObj.constraintsObj, 'primary_key')({is_partitioned: true})).toEqual({
|
|
|
|
primary_key: []
|
|
|
|
});
|
|
|
|
expect(getFieldDepChange(schemaObj.constraintsObj, 'foreign_key')({is_partitioned: true})).toEqual({
|
|
|
|
foreign_key: []
|
|
|
|
});
|
|
|
|
expect(getFieldDepChange(schemaObj.constraintsObj, 'unique_constraint')({is_partitioned: true})).toEqual({
|
|
|
|
unique_constraint: []
|
|
|
|
});
|
|
|
|
expect(getFieldDepChange(schemaObj.constraintsObj, 'exclude_constraint')({is_partitioned: true})).toEqual({
|
|
|
|
exclude_constraint: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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 03:57:31 -05:00
|
|
|
it('validate', () => {
|
2021-08-23 03:10:14 -05:00
|
|
|
let state = {is_partitioned: true};
|
2023-10-23 07:13:17 -05:00
|
|
|
let setError = jest.fn();
|
2021-08-23 03:10:14 -05:00
|
|
|
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('partition_keys', 'Please specify at least one key for partitioned table.');
|
|
|
|
|
|
|
|
state.partition_keys = [{key: 'id'}];
|
|
|
|
expect(schemaObj.validate(state, setError)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|