forked from pgadmin-org/pgadmin4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSchemaPropertiesView.jsx
More file actions
130 lines (117 loc) · 4.29 KB
/
SchemaPropertiesView.jsx
File metadata and controls
130 lines (117 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2025, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import React, { useEffect, useMemo } from 'react';
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
import InfoIcon from '@mui/icons-material/InfoRounded';
import EditIcon from '@mui/icons-material/Edit';
import { Box } from '@mui/material';
import Accordion from '@mui/material/Accordion';
import AccordionSummary from '@mui/material/AccordionSummary';
import AccordionDetails from '@mui/material/AccordionDetails';
import PropTypes from 'prop-types';
import { usePgAdmin } from 'sources/PgAdminProvider';
import gettext from 'sources/gettext';
import { PgIconButton, PgButtonGroup } from 'sources/components/Buttons';
import CustomPropTypes from 'sources/custom_prop_types';
import { FieldControl } from './FieldControl';
import { FormLoader } from './FormLoader';
import { SchemaStateContext } from './SchemaState';
import { StyledBox } from './StyledComponents';
import { useSchemaState } from './hooks';
import { createFieldControls } from './utils';
/* If its the properties tab */
export default function SchemaPropertiesView({
getInitData, viewHelperProps, schema={}, updatedData, ...props
}) {
const pgAdmin = usePgAdmin();
const Notifier = pgAdmin.Browser.notifier;
// Schema data state manager
const {schemaState} = useSchemaState({
schema: schema, getInitData: getInitData, immutableData: updatedData,
viewHelperProps: viewHelperProps, onDataChange: null,
});
useEffect(() => {
if (schemaState.errors?.response)
Notifier.pgRespErrorNotify(schemaState.errors.response);
}, [schemaState.errors?.name]);
const finalTabs = useMemo(
() => createFieldControls({
schema, schemaState, viewHelperProps, dataDispatch: null, accessPath: []
}),
[schema._id, schemaState, viewHelperProps]
);
if (!finalTabs) return <></>;
return useMemo(
() => <StyledBox>
<SchemaStateContext.Provider value={schemaState}>
<FormLoader/>
<Box className='Properties-toolbar'>
<PgButtonGroup size="small">
<PgIconButton
data-test="help" onClick={() => props.onHelp(true, false)}
icon={<InfoIcon />} disabled={props.disableSqlHelp}
title="SQL help for this object type." />
<PgIconButton data-test="edit"
onClick={props.onEdit} icon={<EditIcon />}
title={gettext('Edit object...')} />
</PgButtonGroup>
</Box>
<Box className={'Properties-form'}>
<Box>
{finalTabs.map((group)=>{
let id = group.id.replace(' ', '');
return (
<Accordion key={id}>
<AccordionSummary
expandIcon={<ExpandMoreIcon />}
aria-controls={`${id}-content`}
id={`${id}-header`}
>
{group.label}
</AccordionSummary>
<AccordionDetails className={group.className}>
<Box style={{width: '100%'}}>
{
group.controls.map(
(item, idx) => <FieldControl
item={item} key={`${item.controlProps.id}-${idx}`} schemaId={schema._id}
/>
)
}
</Box>
</AccordionDetails>
</Accordion>
);
})}
</Box>
</Box>
</SchemaStateContext.Provider>
</StyledBox>,
[schema._id]
);
}
SchemaPropertiesView.propTypes = {
getInitData: PropTypes.func.isRequired,
updatedData: PropTypes.object,
viewHelperProps: PropTypes.shape({
mode: PropTypes.string.isRequired,
serverInfo: PropTypes.shape({
type: PropTypes.string,
version: PropTypes.number,
}),
inCatalog: PropTypes.bool,
keepCid: PropTypes.bool,
}).isRequired,
schema: CustomPropTypes.schemaUI,
onHelp: PropTypes.func,
disableSqlHelp: PropTypes.bool,
onEdit: PropTypes.func,
resetKey: PropTypes.any,
itemNodeData: PropTypes.object
};