2022-03-21 13:29:26 +05:30
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2025-01-01 11:26:42 +05:30
// Copyright (C) 2013 - 2025, The pgAdmin Development Team
2022-03-21 13:29:26 +05:30
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import gettext from 'sources/gettext' ;
2024-06-06 17:13:12 +05:30
import { styled } from '@mui/material/styles' ;
2022-03-23 13:28:35 +05:30
import _ from 'lodash' ;
2022-03-21 13:29:26 +05:30
import url _for from 'sources/url_for' ;
2022-03-23 13:28:35 +05:30
import React , { useEffect , useMemo } from 'react' ;
2022-03-21 13:29:26 +05:30
import { FileType } from 'react-aspen' ;
2024-04-09 08:21:14 +05:30
import { Box } from '@mui/material' ;
2022-03-21 13:29:26 +05:30
import PropTypes from 'prop-types' ;
2025-01-08 17:22:11 +05:30
import CloseIcon from '@mui/icons-material/CloseRounded' ;
import HTMLReactParser from 'html-react-parser/lib/index' ;
2022-03-21 13:29:26 +05:30
import SchemaView from '../../../../static/js/SchemaView' ;
import getApiInstance from '../../../../static/js/api_instance' ;
2024-04-09 08:21:14 +05:30
import CloseSharpIcon from '@mui/icons-material/CloseSharp' ;
import HelpIcon from '@mui/icons-material/HelpRounded' ;
import SaveSharpIcon from '@mui/icons-material/SaveSharp' ;
2024-08-30 12:24:24 +05:30
import SettingsBackupRestoreIcon from '@mui/icons-material/SettingsBackupRestore' ;
2022-03-21 13:29:26 +05:30
import pgAdmin from 'sources/pgadmin' ;
import { DefaultButton , PgIconButton , PrimaryButton } from '../../../../static/js/components/Buttons' ;
import BaseUISchema from 'sources/SchemaView/base_schema.ui' ;
import { getBinaryPathSchema } from '../../../../browser/server_groups/servers/static/js/binary_path.ui' ;
2023-10-23 17:43:17 +05:30
import usePreferences from '../store' ;
2024-09-18 16:43:57 +05:30
import { getBrowser } from '../../../../static/js/utils' ;
2022-03-21 13:29:26 +05:30
2024-06-06 17:13:12 +05:30
const StyledBox = styled ( Box ) ( ( { theme } ) => ( {
'& .PreferencesComponent-root' : {
display : 'flex' ,
flexDirection : 'column' ,
flexGrow : 1 ,
height : '100%' ,
backgroundColor : theme . palette . background . default ,
overflow : 'hidden' ,
'&$disabled' : {
color : '#ddd' ,
} ,
'& .PreferencesComponent-body' : {
borderColor : theme . otherVars . borderColor ,
display : 'flex' ,
flexGrow : 1 ,
height : '100%' ,
minHeight : 0 ,
overflow : 'hidden' ,
'& .PreferencesComponent-treeContainer' : {
flexBasis : '25%' ,
alignItems : 'flex-start' ,
paddingLeft : '5px' ,
minHeight : 0 ,
flexGrow : 1 ,
'& .PreferencesComponent-tree' : {
height : '100%' ,
flexGrow : 1
} ,
} ,
'& .PreferencesComponent-preferencesContainer' : {
flexBasis : '75%' ,
padding : '5px' ,
borderColor : theme . otherVars . borderColor + '!important' ,
borderLeft : '1px solid' ,
position : 'relative' ,
height : '100%' ,
paddingTop : '5px' ,
overflow : 'auto' ,
2024-06-17 15:45:40 +05:30
'& .PreferencesComponent-preferencesContainerBackground' : {
backgroundColor : theme . palette . background . default ,
}
2024-06-06 17:13:12 +05:30
} ,
} ,
'& .PreferencesComponent-footer' : {
borderTop : ` 1px solid ${ theme . otherVars . inputBorderColor } !important ` ,
padding : '0.5rem' ,
display : 'flex' ,
width : '100%' ,
background : theme . otherVars . headerBg ,
'& .PreferencesComponent-actionBtn' : {
alignItems : 'flex-start' ,
} ,
'& .PreferencesComponent-buttonMargin' : {
marginLeft : '0.5em'
} ,
} ,
2025-01-08 17:22:11 +05:30
} ,
'& .Alert-footer' : {
display : 'flex' ,
justifyContent : 'flex-end' ,
padding : '0.5rem' ,
... theme . mixins . panelBorder . top ,
} ,
'& .Alert-margin' : {
marginLeft : '0.25rem' ,
2024-06-06 17:13:12 +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
2022-03-21 13:29:26 +05:30
class PreferencesSchema extends BaseUISchema {
constructor ( initValues = { } , schemaFields = [ ] ) {
super ( {
... initValues
} ) ;
this . schemaFields = schemaFields ;
this . category = '' ;
}
get idAttribute ( ) {
return '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 14:27:31 +05:30
categoryUpdated ( ) {
this . state ? . validate ( this . sessData ) ;
2022-03-21 13:29:26 +05:30
}
get baseFields ( ) {
return this . schemaFields ;
}
}
2024-09-18 16:43:57 +05:30
async function reloadPgAdmin ( ) {
let { name : browser } = getBrowser ( ) ;
if ( browser == 'Electron' ) {
await window . electronUI . log ( 'test' ) ;
await window . electronUI . reloadApp ( ) ;
} else {
location . reload ( ) ;
}
}
2022-03-21 13:29:26 +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
function RightPanel ( { schema , refreshKey , ... props } ) {
const schemaViewRef = React . useRef ( null ) ;
2022-03-21 13:29:26 +05:30
let initData = ( ) => new Promise ( ( resolve , reject ) => {
try {
resolve ( props . initValues ) ;
} catch ( error ) {
2024-06-17 18:22:38 +05:30
reject ( error instanceof Error ? error : Error ( gettext ( 'Something went wrong' ) ) ) ;
2022-03-21 13:29:26 +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
useEffect ( ( ) => {
const timeID = setTimeout ( ( ) => {
const focusableElement = schemaViewRef . current ? . querySelector (
'button, a, input, select, textarea, [tabindex]:not([tabindex="-1"])'
) ;
if ( focusableElement ) focusableElement . focus ( ) ;
} , 50 ) ;
return ( ) => clearTimeout ( timeID ) ;
} , [ refreshKey ] ) ;
2022-03-21 13:29:26 +05:30
return (
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
< div ref = { schemaViewRef } >
< SchemaView
formType = { 'dialog' }
getInitData = { initData }
viewHelperProps = { { mode : 'edit' } }
schema = { schema }
showFooter = { false }
isTabView = { false }
formClassName = 'PreferencesComponent-preferencesContainerBackground'
onDataChange = { ( isChanged , changedData ) => {
props . onDataChange ( changedData ) ;
} }
/ >
< / div >
2022-03-21 13:29:26 +05:30
) ;
}
RightPanel . propTypes = {
schema : PropTypes . object ,
2024-10-01 16:32:04 +05:30
refreshKey : PropTypes . number ,
2022-03-21 13:29:26 +05:30
initValues : PropTypes . object ,
onDataChange : PropTypes . func
} ;
export default function PreferencesComponent ( { ... props } ) {
2024-06-06 17:13:12 +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
const [ refreshKey , setRefreshKey ] = React . useState ( 0 ) ;
2022-03-21 13:29:26 +05:30
const [ disableSave , setDisableSave ] = React . useState ( true ) ;
const prefSchema = React . useRef ( new PreferencesSchema ( { } , [ ] ) ) ;
const prefChangedData = React . useRef ( { } ) ;
const prefTreeInit = React . useRef ( false ) ;
const [ prefTreeData , setPrefTreeData ] = React . useState ( null ) ;
const [ initValues , setInitValues ] = React . useState ( { } ) ;
const [ loadTree , setLoadTree ] = React . useState ( 0 ) ;
const api = getApiInstance ( ) ;
2022-03-24 16:08:13 +05:30
const firstTreeElement = React . useRef ( '' ) ;
2023-10-23 17:43:17 +05:30
const preferencesStore = usePreferences ( ) ;
2022-03-21 13:29:26 +05:30
useEffect ( ( ) => {
const pref _url = url _for ( 'preferences.index' ) ;
api ( {
url : pref _url ,
method : 'GET' ,
} ) . then ( ( res ) => {
let preferencesData = [ ] ;
let preferencesTreeData = [ ] ;
let preferencesValues = { } ;
res . data . forEach ( node => {
2022-08-14 07:09:45 +05:30
let id = crypto . getRandomValues ( new Uint16Array ( 1 ) ) ;
2022-03-21 13:29:26 +05:30
let tdata = {
'id' : id . toString ( ) ,
'label' : node . label ,
'_label' : node . label ,
2024-03-14 18:12:28 +05:30
'name' : node . name ,
2022-03-21 13:29:26 +05:30
'icon' : '' ,
'inode' : true ,
'type' : 2 ,
'_type' : node . label . toLowerCase ( ) ,
'_id' : id ,
'_pid' : null ,
'childrenNodes' : [ ] ,
'expanded' : true ,
'isExpanded' : true ,
} ;
2022-03-24 16:08:13 +05:30
if ( firstTreeElement . current . length == 0 ) {
firstTreeElement . current = node . label ;
}
2022-03-21 13:29:26 +05:30
node . children . forEach ( subNode => {
2022-08-14 07:09:45 +05:30
let sid = crypto . getRandomValues ( new Uint16Array ( 1 ) ) ;
2022-03-21 13:29:26 +05:30
let nodeData = {
'id' : sid . toString ( ) ,
'label' : subNode . label ,
'_label' : subNode . label ,
2023-03-24 15:44:43 +05:30
'name' : subNode . name ,
2022-03-21 13:29:26 +05:30
'icon' : '' ,
'inode' : false ,
'_type' : subNode . label . toLowerCase ( ) ,
'_id' : sid ,
'_pid' : node . id ,
'type' : 1 ,
'expanded' : false ,
} ;
2022-03-23 13:28:35 +05:30
addNote ( node , subNode , nodeData , preferencesData ) ;
setPreferences ( node , subNode , nodeData , preferencesValues , preferencesData ) ;
2022-03-21 13:29:26 +05:30
tdata [ 'childrenNodes' ] . push ( nodeData ) ;
} ) ;
// set Preferences Tree data
preferencesTreeData . push ( tdata ) ;
} ) ;
setPrefTreeData ( preferencesTreeData ) ;
setInitValues ( preferencesValues ) ;
// set Preferences schema
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
prefSchema . current = new PreferencesSchema (
preferencesValues , preferencesData ,
) ;
2022-03-21 13:29:26 +05:30
} ) . catch ( ( err ) => {
2023-10-23 17:43:17 +05:30
pgAdmin . Browser . notifier . alert ( err ) ;
2022-03-21 13:29:26 +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
function setPreferences (
node , subNode , nodeData , preferencesValues , preferencesData
) {
2022-03-29 16:27:33 +05:30
let addBinaryPathNote = false ;
2022-03-23 13:28:35 +05:30
subNode . preferences . forEach ( ( element ) => {
let note = '' ;
let type = getControlMappedForType ( element . type ) ;
if ( type === 'file' ) {
note = gettext ( 'Enter the directory in which the psql, pg_dump, pg_dumpall, and pg_restore utilities can be found for the corresponding database server version. The default path will be used for server versions that do not have a path specified.' ) ;
element . type = 'collection' ;
element . schema = getBinaryPathSchema ( ) ;
element . canAdd = false ;
element . canDelete = false ;
element . canEdit = false ;
element . editable = false ;
element . disabled = true ;
preferencesValues [ element . id ] = JSON . parse ( element . value ) ;
2022-03-29 16:27:33 +05:30
if ( addBinaryPathNote ) {
addNote ( node , subNode , nodeData , preferencesData , note ) ;
}
addBinaryPathNote = true ;
2022-03-23 13:28:35 +05:30
}
else if ( type == 'select' ) {
setControlProps ( element ) ;
element . type = type ;
preferencesValues [ element . id ] = element . value ;
setThemesOptions ( element ) ;
}
else if ( type === 'keyboardShortcut' ) {
getKeyboardShortcuts ( element , preferencesValues , node ) ;
} else if ( type === 'threshold' ) {
element . type = 'threshold' ;
let _val = element . value . split ( '|' ) ;
preferencesValues [ element . id ] = { 'warning' : _val [ 0 ] , 'alert' : _val [ 1 ] } ;
2022-03-24 16:08:13 +05:30
} else if ( subNode . label == gettext ( 'Results grid' ) && node . label == gettext ( 'Query Tool' ) ) {
2022-03-23 13:28:35 +05:30
setResultsOptions ( element , subNode , preferencesValues , type ) ;
} else {
element . type = type ;
preferencesValues [ element . id ] = element . value ;
}
delete element . value ;
element . visible = false ;
element . helpMessage = element ? . help _str ? element . help _str : null ;
preferencesData . push ( element ) ;
element . parentId = nodeData [ 'id' ] ;
} ) ;
}
function setResultsOptions ( element , subNode , preferencesValues , type ) {
if ( element . name == 'column_data_max_width' ) {
let size _control _id = null ;
subNode . preferences . forEach ( ( _el ) => {
if ( _el . name == 'column_data_auto_resize' ) {
size _control _id = _el . id ;
}
2022-04-07 17:36:56 +05:30
2022-03-23 13:28:35 +05:30
} ) ;
element . disabled = ( state ) => {
return state [ size _control _id ] != 'by_data' ;
} ;
}
element . type = type ;
preferencesValues [ element . id ] = element . value ;
}
function setThemesOptions ( element ) {
if ( element . name == 'theme' ) {
element . type = 'theme' ;
element . options . forEach ( ( opt ) => {
if ( opt . value == element . value ) {
opt . selected = true ;
} else {
opt . selected = false ;
}
2024-07-16 10:25:48 +05:30
opt . preview _src = opt . preview _src && url _for ( 'static' , { filename : opt . preview _src } ) ;
2022-03-23 13:28:35 +05:30
} ) ;
}
}
function setControlProps ( element ) {
if ( element . control _props !== undefined ) {
element . controlProps = element . control _props ;
} else {
element . controlProps = { } ;
}
}
function getKeyboardShortcuts ( element , preferencesValues , node ) {
element . type = 'keyboardShortcut' ;
element . canAdd = false ;
element . canDelete = false ;
element . canEdit = false ;
element . editable = false ;
2023-10-23 17:43:17 +05:30
if ( preferencesStore . getPreferences ( node . label . toLowerCase ( ) , element . name ) ? . value ) {
let temp = preferencesStore . getPreferences ( node . label . toLowerCase ( ) , element . name ) . value ;
2022-03-23 13:28:35 +05:30
preferencesValues [ element . id ] = temp ;
} else {
preferencesValues [ element . id ] = element . value ;
}
}
function addNote ( node , subNode , nodeData , preferencesData , note = '' ) {
// Check and add the note for the element.
2022-03-24 16:08:13 +05:30
if ( subNode . label == gettext ( 'Nodes' ) && node . label == gettext ( 'Browser' ) ) {
2023-03-28 22:20:14 +05:30
note = [ gettext ( 'This settings is to Show/Hide nodes in the object explorer.' ) ] . join ( '' ) ;
2022-03-23 13:28:35 +05:30
} else {
2022-03-24 16:08:13 +05:30
note = [ note ] . join ( '' ) ;
2022-03-23 13:28:35 +05:30
}
if ( note && note . length > 0 ) {
2022-04-07 17:36:56 +05:30
//Add Note for Nodes
2022-03-23 13:28:35 +05:30
preferencesData . push (
{
id : _ . uniqueId ( 'note' ) + subNode . 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 14:27:31 +05:30
type : 'note' ,
text : note ,
'parentId' : nodeData [ 'id' ] ,
2022-03-23 13:28:35 +05:30
visible : false ,
} ,
) ;
}
}
2022-03-21 13:29:26 +05:30
2022-09-27 14:28:31 +05:30
function selectChildNode ( item , prefTreeInit ) {
if ( item . isExpanded && item . _children && item . _children . length > 0 && prefTreeInit . current && event . code !== 'ArrowUp' ) {
pgAdmin . Browser . ptree . tree . setActiveFile ( item . _children [ 0 ] , true ) ;
}
}
2022-03-21 13:29:26 +05:30
useEffect ( ( ) => {
2022-03-31 11:46:34 +05:30
let firstElement = null ;
2022-03-21 13:29:26 +05:30
// Listen selected preferences tree node event and show the appropriate components in right panel.
2022-03-31 11:46:34 +05:30
pgAdmin . Browser . Events . on ( 'preferences:tree:selected' , ( event , item ) => {
2022-03-21 13:29:26 +05:30
if ( item . type == FileType . File ) {
prefSchema . current . schemaFields . forEach ( ( field ) => {
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
field . visible = field . parentId === item . _metadata . data . id &&
! field ? . hidden ;
2022-03-31 11:46:34 +05:30
if ( field . visible && _ . isNull ( firstElement ) ) {
firstElement = field ;
}
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
field . labelTooltip =
item . _parent . _metadata . data . name . toLowerCase ( ) + ':' +
item . _metadata . data . name + ':' + field . name ;
2022-03-21 13:29:26 +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
prefSchema . current . categoryUpdated ( item . _metadata . data . id ) ;
setLoadTree ( Date . now ( ) ) ;
setRefreshKey ( Date . now ( ) ) ;
2022-03-21 13:29:26 +05:30
}
else {
2022-09-27 14:28:31 +05:30
selectChildNode ( item , prefTreeInit ) ;
2022-03-21 13:29:26 +05:30
}
} ) ;
// Listen open preferences tree node event to default select first child node on parent node selection.
2022-03-31 11:46:34 +05:30
pgAdmin . Browser . Events . on ( 'preferences:tree:opened' , ( event , item ) => {
2022-03-23 13:28:35 +05:30
pgAdmin . Browser . ptree . tree . setActiveFile ( item . _children [ 0 ] , true ) ;
2022-03-21 13:29:26 +05:30
} ) ;
// Listen added preferences tree node event to expand the newly added node on tree load.
2022-09-27 14:28:31 +05:30
pgAdmin . Browser . Events . on ( 'preferences:tree:added' , addPrefTreeNode ) ;
2022-03-23 13:28:35 +05:30
} , [ ] ) ;
2022-03-21 13:29:26 +05:30
2022-09-27 14:28:31 +05:30
function addPrefTreeNode ( event , item ) {
if ( item . _parent . _fileName == firstTreeElement . current && item . _parent . isExpanded && ! prefTreeInit . current ) {
pgAdmin . Browser . ptree . tree . setActiveFile ( item . _parent . _children [ 0 ] , true ) ;
}
else if ( item . type == FileType . Directory ) {
// Check the if newely added node is Directoy and call toggle to expand the node.
pgAdmin . Browser . ptree . tree . toggleDirectory ( item ) ;
}
}
2022-03-21 13:29:26 +05:30
function getControlMappedForType ( type ) {
switch ( type ) {
case 'text' :
return 'text' ;
case 'input' :
return 'text' ;
case 'boolean' :
return 'switch' ;
case 'node' :
return 'switch' ;
case 'integer' :
return 'numeric' ;
case 'numeric' :
return 'numeric' ;
case 'date' :
return 'datetimepicker' ;
case 'datetime' :
return 'datetimepicker' ;
case 'options' :
return 'select' ;
case 'select' :
return 'select' ;
case 'select2' :
return 'select' ;
case 'multiline' :
return 'multiline' ;
case 'switch' :
return 'switch' ;
case 'keyboardshortcut' :
return 'keyboardShortcut' ;
case 'radioModern' :
return 'toggle' ;
case 'selectFile' :
return 'file' ;
case 'threshold' :
return 'threshold' ;
default :
2024-01-25 16:51:40 +05:30
if ( console ? . warn ) {
2022-03-21 13:29:26 +05:30
// Warning for developer only.
console . warn (
'Hmm.. We don\'t know how to render this type - \'\'' + type + '\' of control.'
) ;
}
return 'input' ;
}
}
2022-03-23 13:28:35 +05:30
function getCollectionValue ( _metadata , value , initVals ) {
2022-03-21 13:29:26 +05:30
let val = value ;
if ( typeof ( value ) == 'object' ) {
if ( _metadata [ 0 ] . type == 'collection' && _metadata [ 0 ] . schema ) {
if ( 'binaryPath' in value . changed [ 0 ] ) {
let pathData = [ ] ;
let pathVersions = [ ] ;
value . changed . forEach ( ( chValue ) => {
pathVersions . push ( chValue . version ) ;
} ) ;
2022-03-23 13:28:35 +05:30
getPathData ( initVals , pathData , _metadata , value , pathVersions ) ;
2022-03-21 13:29:26 +05:30
val = JSON . stringify ( pathData ) ;
} else {
let key _val = {
'char' : value . changed [ 0 ] [ 'key' ] ,
'key_code' : value . changed [ 0 ] [ 'code' ] ,
} ;
value . changed [ 0 ] [ 'key' ] = key _val ;
val = value . changed [ 0 ] ;
}
} else if ( 'warning' in value ) {
val = value [ 'warning' ] + '|' + value [ 'alert' ] ;
} else if ( value ? . changed && value . changed . length > 0 ) {
val = JSON . stringify ( value . changed ) ;
}
}
return val ;
}
2022-03-23 13:28:35 +05:30
function getPathData ( initVals , pathData , _metadata , value , pathVersions ) {
initVals [ _metadata [ 0 ] . id ] . forEach ( ( initVal ) => {
if ( pathVersions . includes ( initVal . version ) ) {
pathData . push ( value . changed [ pathVersions . indexOf ( initVal . version ) ] ) ;
}
else {
pathData . push ( initVal ) ;
}
} ) ;
}
function savePreferences ( data , initVal ) {
2022-03-21 13:29:26 +05:30
let _data = [ ] ;
for ( const [ key , value ] of Object . entries ( data . current ) ) {
2024-08-02 09:59:01 +05:30
let _metadata = prefSchema . current . schemaFields . filter (
( el ) => { return el . id == key ; }
) ;
2022-03-21 13:29:26 +05:30
if ( _metadata . length > 0 ) {
2022-03-23 13:28:35 +05:30
let val = getCollectionValue ( _metadata , value , initVal ) ;
2022-03-21 13:29:26 +05:30
_data . push ( {
'category_id' : _metadata [ 0 ] [ 'cid' ] ,
'id' : parseInt ( key ) ,
'mid' : _metadata [ 0 ] [ 'mid' ] ,
'name' : _metadata [ 0 ] [ 'name' ] ,
'value' : val ,
} ) ;
}
}
if ( _data . length > 0 ) {
2024-12-16 14:52:56 +05:30
// Check whether layout is changed from Workspace to Classic.
let layoutPref = _data . find ( x => x . name === 'layout' ) ;
// If layout is changed then raise the warning to close all the connections.
if ( ! _ . isUndefined ( layoutPref ) && layoutPref . value == 'classic' ) {
pgAdmin . Browser . notifier . confirm (
gettext ( 'Layout changed' ) ,
` ${ gettext ( 'Switching from Workspace to Classic layout will disconnect all server connections and refresh the entire page.' ) }
$ { gettext ( 'To avoid losing unsaved data, click Cancel to manually review and close your connections.' ) }
$ { gettext ( 'Note that if you choose Cancel, any changes to your preferences will not be saved.' ) } < br > < br >
$ { gettext ( 'Do you want to continue?' ) } ` ,
function ( ) {
save ( _data , data , true ) ;
} ,
function ( ) {
return true ;
} ,
gettext ( 'Continue' ) ,
gettext ( 'Cancel' )
) ;
} else {
save ( _data , data ) ;
}
2022-03-21 13:29:26 +05:30
}
}
function checkRefreshRequired ( pref , requires _refresh ) {
if ( pref . name == 'user_language' ) {
requires _refresh = true ;
}
return requires _refresh ;
}
2024-12-16 14:52:56 +05:30
function save ( save _data , data , layout _changed = false ) {
2022-03-21 13:29:26 +05:30
api ( {
url : url _for ( 'preferences.index' ) ,
method : 'PUT' ,
data : save _data ,
} ) . then ( ( ) => {
2024-12-16 14:52:56 +05:30
// If layout is changed then only refresh the object explorer.
if ( layout _changed ) {
api ( {
url : url _for ( 'workspace.layout_changed' ) ,
method : 'DELETE' ,
data : save _data ,
} ) . then ( ( ) => {
pgAdmin . Browser . tree . destroy ( ) . then (
( ) => {
pgAdmin . Browser . Events . trigger (
'pgadmin-browser:tree:destroyed' , undefined , undefined
) ;
return true ;
}
) ;
} ) ;
} else {
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'
) ;
} ) ;
let requires _refresh = false ;
for ( const [ key ] of Object . entries ( data . current ) ) {
let pref = preferencesStore . getPreferenceForId ( Number ( key ) ) ;
requires _refresh = checkRefreshRequired ( pref , requires _refresh ) ;
}
2022-03-21 13:29:26 +05:30
2024-12-16 14:52:56 +05:30
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?'
) ,
function ( ) {
pgAdmin . Browser . tree . destroy ( ) . then (
( ) => {
pgAdmin . Browser . Events . trigger (
'pgadmin-browser:tree:destroyed' , undefined , undefined
) ;
return true ;
}
) ;
} ,
function ( ) {
return true ;
} ,
gettext ( 'Refresh' ) ,
gettext ( 'Later' )
) ;
}
2023-05-23 14:37:16 +05:30
2024-12-16 14:52:56 +05:30
if ( requires _refresh ) {
pgAdmin . Browser . notifier . confirm (
gettext ( 'Refresh required' ) ,
gettext ( 'A page refresh is required. Do you wish to refresh the page now?' ) ,
function ( ) {
/* If user clicks Yes */
reloadPgAdmin ( ) ;
return true ;
} ,
function ( ) { props . closeModal ( ) ; } ,
gettext ( 'Refresh' ) ,
gettext ( 'Later' )
) ;
}
2022-03-21 13:29:26 +05:30
}
// Refresh preferences cache
2023-10-23 17:43:17 +05:30
preferencesStore . cache ( ) ;
2022-03-23 13:28:35 +05:30
props . closeModal ( ) ;
2022-03-21 13:29:26 +05:30
} ) . catch ( ( err ) => {
2023-10-23 17:43:17 +05:30
pgAdmin . Browser . notifier . alert ( err . response . data ) ;
2022-03-21 13:29:26 +05:30
} ) ;
}
const onDialogHelp = ( ) => {
window . open ( url _for ( 'help.static' , { 'filename' : 'preferences.html' } ) , 'pgadmin_help' ) ;
} ;
2024-08-30 12:24:24 +05:30
const reset = ( ) => {
2025-01-08 17:22:11 +05:30
const text = ` ${ gettext ( 'All preferences will be reset to their default values.' ) } <br><br> ${ gettext ( 'Do you want to proceed?' ) } <br><br>
$ { gettext ( 'Note:' ) } < br > < ul style = "padding-left:20px" > < li style = "list-style-type:disc" > $ { gettext ( 'The object explorer tree will be refreshed automatically to reflect the changes.' ) } < / li >
< li style = "list-style-type:disc" > $ { gettext ( 'If the application language changes, a reload of the application will be required. You can choose to reload later at your convenience.' ) } < / li > < / ul > ` ;
pgAdmin . Browser . notifier . showModal (
2024-08-30 12:24:24 +05:30
gettext ( 'Reset all preferences' ) ,
2025-01-08 17:22:11 +05:30
( closeModal ) => {
const onClick = ( reset ) => {
resetPrefsToDefault ( reset ) ;
closeModal ( ) ;
} ;
return (
< StyledBox display = "flex" flexDirection = "column" height = "100%" >
< Box flexGrow = "1" p = { 2 } >
{ HTMLReactParser ( text ) }
< / Box >
< Box className = 'Alert-footer' >
< DefaultButton className = 'Alert-margin' startIcon = { < CloseIcon / > } onClick = { ( ) => closeModal ( ) } > { 'Cancel' } < / DefaultButton >
< DefaultButton className = 'Alert-margin' startIcon = { < SaveSharpIcon / > } onClick = { ( ) => onClick ( true ) } > { gettext ( 'Save & Reload' ) } < / DefaultButton >
< PrimaryButton className = 'Alert-margin' startIcon = { < SaveSharpIcon / > } onClick = { ( ) => onClick ( false ) } > { gettext ( 'Save & Reload Later' ) } < / PrimaryButton >
< / Box >
< / StyledBox >
) ;
} ,
{ isFullScreen : false , isResizeable : false , showFullScreen : false , isFullWidth : false , showTitle : true } ,
2024-08-30 12:24:24 +05:30
) ;
} ;
const resetPrefsToDefault = ( refresh = false ) => {
api ( {
url : url _for ( 'preferences.index' ) ,
method : 'DELETE'
} ) . then ( ( ) => {
if ( refresh ) {
2024-09-18 16:43:57 +05:30
reloadPgAdmin ( ) ;
2024-08-30 12:24:24 +05:30
return true ;
}
preferencesStore . cache ( ) ;
pgAdmin . Browser . tree . destroy ( ) . then (
( ) => {
pgAdmin . Browser . Events . trigger (
'pgadmin-browser:tree:destroyed' , undefined , undefined
) ;
return true ;
}
) ;
props . closeModal ( ) ;
} ) . catch ( ( err ) => {
pgAdmin . Browser . notifier . alert ( err . response . data ) ;
} ) ;
} ;
2022-03-21 13:29:26 +05:30
return (
2024-06-06 17:13:12 +05:30
< StyledBox height = { '100%' } >
< Box className = 'PreferencesComponent-root' >
< Box className = 'PreferencesComponent-body' >
< Box className = 'PreferencesComponent-treeContainer' >
< Box className = 'PreferencesComponent-tree' id = { 'treeContainer' } tabIndex = { 0 } >
2022-03-23 13:28:35 +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
useMemo (
( ) => ( prefTreeData && props . renderTree ( prefTreeData ) ) ,
[ prefTreeData ]
)
2022-03-23 13:28:35 +05:30
}
< / Box >
2022-03-21 13:29:26 +05:30
< / Box >
2024-06-06 17:13:12 +05:30
< Box className = 'PreferencesComponent-preferencesContainer' >
2022-03-21 13:29:26 +05:30
{
2023-03-24 15:44:43 +05:30
prefSchema . current && loadTree > 0 &&
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
< RightPanel
schema = { prefSchema . current } initValues = { initValues }
refreshKey = { refreshKey }
onDataChange = { ( changedData ) => {
Object . keys ( changedData ) . length > 0 ?
setDisableSave ( false ) : setDisableSave ( true ) ;
prefChangedData . current = changedData ;
} }
> < / RightPanel >
2022-03-21 13:29:26 +05:30
}
< / Box >
< / Box >
2024-06-06 17:13:12 +05:30
< Box className = 'PreferencesComponent-footer' >
2022-03-21 13:29:26 +05:30
< Box >
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
< PgIconButton
data - test = "dialog-help" onClick = { onDialogHelp }
icon = { < HelpIcon / > } title = { gettext ( 'Help for this dialog.' ) }
/ >
2022-03-21 13:29:26 +05:30
< / Box >
2024-06-06 17:13:12 +05:30
< Box className = 'PreferencesComponent-actionBtn' marginLeft = "auto" >
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
< DefaultButton className = 'PreferencesComponent-buttonMargin'
onClick = { reset } startIcon = { < SettingsBackupRestoreIcon / > } >
2024-08-30 12:24:24 +05:30
{ gettext ( 'Reset all preferences' ) }
< / DefaultButton >
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
< DefaultButton className = 'PreferencesComponent-buttonMargin'
onClick = { ( ) => { props . closeModal ( ) ; } }
startIcon = {
< CloseSharpIcon onClick = { ( ) => { props . closeModal ( ) ; } } / >
} >
2022-03-21 13:29:26 +05:30
{ gettext ( 'Cancel' ) }
< / DefaultButton >
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
< PrimaryButton
className = 'PreferencesComponent-buttonMargin'
startIcon = { < SaveSharpIcon / > }
disabled = { disableSave }
onClick = { ( ) => {
savePreferences ( prefChangedData , initValues ) ;
} } >
2022-03-21 13:29:26 +05:30
{ gettext ( 'Save' ) }
< / PrimaryButton >
< / Box >
< / Box >
< / B o x >
2024-06-06 17:13:12 +05:30
< / StyledBox >
2022-03-21 13:29:26 +05:30
) ;
}
PreferencesComponent . propTypes = {
schema : PropTypes . array ,
initValues : PropTypes . object ,
closeModal : PropTypes . func ,
renderTree : PropTypes . func
} ;