Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export default class ERDTool extends React.Component {
this.fmUtilsObj = new FileManagerUtils(this.apiObj, {modal: this.context});
this.restore = props.params.restore == 'true';
this.eventBus = new EventBus();
this.toolbarPrefs = null;

_.bindAll(this, ['onLoadDiagram', 'onSaveDiagram', 'onSQLClick',
'onImageClick', 'onSearchNode', 'onAddNewNode', 'onEditTable', 'onCloneNode', 'onDeleteNode', 'onNoteClick',
Expand Down Expand Up @@ -408,6 +409,7 @@ export default class ERDTool extends React.Component {

restoreToolContent = async (toolContent) => {
if(toolContent){
this.toolbarPrefs = toolContent.connectionInfo?.preferences || {};
if(toolContent?.modifiedExternally){
toolContent = await this.fmUtilsObj.warnFileReload(toolContent?.fileName, toolContent?.data, '');
}
Expand All @@ -420,7 +422,7 @@ export default class ERDTool extends React.Component {
this.registerModelEvents();
if(toolContent.fileName)this.setState({current_file: toolContent.fileName});
this.setState({dirty: true});
this.eventBus.fireEvent(ERD_EVENTS.DIRTY, true, toolContent.data);
this.eventBus.fireEvent(ERD_EVENTS.DIRTY, true, toolContent.data, null, this.toolbarPrefs);
}
}
};
Expand Down Expand Up @@ -1086,6 +1088,7 @@ export default class ERDTool extends React.Component {
<MainToolBar preferences={this.state.preferences} eventBus={this.eventBus}
fillColor={this.state.fill_color} textColor={this.state.text_color}
notation={this.state.cardinality_notation} onNotationChange={this.onNotationChange} connectionInfo={this.props.params}
toolbarPrefs={this.toolbarPrefs}
/>
<FloatingNote open={this.state.note_open} onClose={this.onNoteClose}
anchorEl={this.noteRefEle} noteNode={this.state.note_node} appendTo={this.diagramContainerRef.current} rows={8}/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//
//////////////////////////////////////////////////////////////
import React, {useCallback, useEffect, useState} from 'react';
import _ from 'lodash';
import { styled } from '@mui/material/styles';
import { Box, useTheme } from '@mui/material';
import { PgButtonGroup, PgIconButton } from '../../../../../../static/js/components/Buttons';
Expand Down Expand Up @@ -51,7 +52,7 @@ const StyledBox = styled(Box)(({theme}) => ({
...theme.mixins.panelBorder.bottom,
}));

export function MainToolBar({preferences, eventBus, fillColor, textColor, notation, onNotationChange, connectionInfo}) {
export function MainToolBar({preferences, eventBus, fillColor, textColor, notation, onNotationChange, connectionInfo, toolbarPrefs}) {
const theme = useTheme();
const [buttonsDisabled, setButtonsDisabled] = useState({
'save': true,
Expand All @@ -72,6 +73,7 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
const notationMenuRef = React.useRef(null);
const isDirtyRef = React.useRef(null);
const [checkedMenuItems, setCheckedMenuItems] = React.useState({});
const notationRef = React.useRef(notation);
const modal = useModal();

const setDisableButton = useCallback((name, disable=true)=>{
Expand All @@ -86,6 +88,15 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
[e.value]: newVal,
};
});
setSaveERDData((prev)=>{
return {
...prev,
toolbarPrefs: {
...prev?.toolbarPrefs,
[e.value]: !prev?.toolbarPrefs?.[e.value],
},
};
});
}, []);

const onHelpClick=()=>{
Expand All @@ -111,15 +122,31 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
};

useEffect(()=>{
if(preferences) {
if(!_.isUndefined(toolbarPrefs) && !_.isNull(toolbarPrefs) && Object.keys(toolbarPrefs).length > 0) {
/* Apply toolbar prefs */
if(!_.isUndefined(toolbarPrefs.sql_with_drop)) {
setCheckedMenuItems((prev)=>({
...prev,
sql_with_drop: toolbarPrefs.sql_with_drop,
}));
}
if(!_.isUndefined(toolbarPrefs.cardinality)) {
notationRef.current = toolbarPrefs.cardinality;
onNotationChange({'value': toolbarPrefs.cardinality});
} else {
notationRef.current = notation;
}
}
else if(preferences) {
/* Get the prefs first time */
if(_.isUndefined(checkedMenuItems.sql_with_drop)) {
setCheckedMenuItems({
sql_with_drop: preferences.sql_with_drop,
});
}
notationRef.current = notation;
}
}, [preferences]);
}, [preferences, toolbarPrefs, notation, onNotationChange]);

useEffect(()=>{
const events = [
Expand All @@ -134,11 +161,17 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
[ERD_EVENTS.ANY_ITEM_SELECTED, (selected)=>{
setDisableButton('drop-table', !selected);
}],
[ERD_EVENTS.DIRTY, (isDirty, data, fileName)=>{
[ERD_EVENTS.DIRTY, (isDirty, data, fileName, toolbarPrefs)=>{
isDirtyRef.current = isDirty;
setDisableButton('save', !isDirty);
if((isDirty || fileName) && isSaveToolDataEnabled('ERD')){
setSaveERDData({data, fileName, isDirty});
setSaveERDData((prev) => ({
...prev,
data,
fileName,
isDirty,
...(toolbarPrefs !== undefined && { toolbarPrefs }),
}));
}
}],
];
Expand All @@ -153,8 +186,10 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
}, []);

const [saveERDData, setSaveERDData] = useState(null);
useDelayDebounce(({data, fileName, isDirty})=>{
saveToolData('ERD', {...connectionInfo,'open_file_name':fileName, 'is_editor_dirty': isDirty}, connectionInfo.trans_id, data);
useDelayDebounce((saveData)=>{
if(saveData?.data !== undefined){
saveToolData('ERD', {...connectionInfo, 'open_file_name': saveData.fileName, 'is_editor_dirty': saveData.isDirty, 'preferences': saveData.toolbarPrefs}, connectionInfo.trans_id, saveData.data);
}
}, saveERDData, 500);

useEffect(()=>{
Expand All @@ -167,6 +202,20 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
};
}, [checkedMenuItems['sql_with_drop']]);

const onCardinalityNotationChange = useCallback((e)=>{
setSaveERDData((prev)=>{
return {
...prev,
toolbarPrefs: {
...prev?.toolbarPrefs,
cardinality: e.value,
},
};
});
notationRef.current = e.value;
onNotationChange(e);
}, [onNotationChange]);

return (
(<>
<StyledBox>
Expand Down Expand Up @@ -336,8 +385,8 @@ export function MainToolBar({preferences, eventBus, fillColor, textColor, notati
label={gettext('Cardinality Notation')}

>
<PgMenuItem hasCheck closeOnCheck value="crows" checked={notation == 'crows'} onClick={onNotationChange}>{gettext('Crow\'s Foot Notation')}</PgMenuItem>
<PgMenuItem hasCheck closeOnCheck value="chen" checked={notation == 'chen'} onClick={onNotationChange}>{gettext('Chen Notation')}</PgMenuItem>
<PgMenuItem hasCheck closeOnCheck value="crows" checked={notationRef.current == 'crows'} onClick={onCardinalityNotationChange}>{gettext('Crow\'s Foot Notation')}</PgMenuItem>
<PgMenuItem hasCheck closeOnCheck value="chen" checked={notationRef.current == 'chen'} onClick={onCardinalityNotationChange}>{gettext('Chen Notation')}</PgMenuItem>
</PgMenu>
</>)
);
Expand All @@ -351,6 +400,7 @@ MainToolBar.propTypes = {
notation: PropTypes.string,
onNotationChange: PropTypes.func,
connectionInfo: PropTypes.object,
toolbarPrefs: PropTypes.object,
};

const ColorButton = withColorPicker(PgIconButton);
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const Root = styled('div')(({theme}) => ({
},
}));

export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowIds, onServerSchemaChange, rows, compareParams, filterParams = [FILTER_NAME.DIFFERENT, FILTER_NAME.SOURCE_ONLY, FILTER_NAME.TARGET_ONLY] }) {
export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowIds, onServerSchemaChange, rows, compareParams, filterParams, filters }) {
const filterRef = useRef(null);
const compareRef = useRef(null);

Expand Down Expand Up @@ -103,8 +103,13 @@ export function SchemaDiffButtonComponent({ sourceData, targetData, selectedRowI
schemaDiffCtx?.preferences_schema_diff?.ignore_grants && prefCompareOptions.push(MENUS_COMPARE_CONSTANT.COMPARE_IGNORE_GRANTS);
setSelectedCompare(prefCompareOptions);
}
}, [schemaDiffCtx.preferences_schema_diff]);
}, [schemaDiffCtx.preferences_schema_diff, compareParams]);

useEffect(() => {
if (!_.isUndefined(filters) && !_.isEmpty(filters)) {
setSelectedFilters(filters);
}
}, [filters]);

const selectFilterOption = (option) => {
let newOptions = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,11 @@ export function SchemaDiffCompare({ params }) {
if(params.params?.restore == 'true'){
async function fetchData() {
const response = await getToolContent(params.transId);
oldSchemaDiffData.current = response?.data;
oldSchemaDiffData.current = response;
if(response?.connectionInfo?.preferences){
setCompareOptions(response?.connectionInfo?.preferences?.compareParams);
setFilterOptions(response?.connectionInfo?.preferences?.filterParams);
}
}
fetchData();
}
Expand All @@ -152,7 +156,7 @@ export function SchemaDiffCompare({ params }) {

useEffect(()=>{
if(oldSchemaDiffData.current){
_.each(oldSchemaDiffData.current,(d)=>{
_.each(oldSchemaDiffData.current.data,(d)=>{
if(d.diff_type == TYPE.SOURCE){
setSelectedSourceSid(d.selectedSourceSid);
}else{
Expand Down Expand Up @@ -294,7 +298,7 @@ export function SchemaDiffCompare({ params }) {
{ diff_type: TYPE.SOURCE, selectedSourceSid: sourceData.sid, selectedSourceDid:sourceData.did, selectedSourceScid: sourceData.scid},
{ diff_type: TYPE.TARGET, selectedTargetSid:targetData.sid, selectedTargetDid:targetData.did, selectedTargetScid:targetData.scid },
];
saveToolData('schema_diff', null, params.transId, toolData);
saveToolData('schema_diff', {preferences:{compareParams, filterParams}}, params.transId, toolData);
}

setLoaderText('Comparing objects... (this may take a few minutes)...');
Expand Down Expand Up @@ -678,7 +682,7 @@ export function SchemaDiffCompare({ params }) {

useEffect(()=>{
if(oldSchemaDiffData.current){
_.each(oldSchemaDiffData.current,(d)=>{
_.each(oldSchemaDiffData.current?.data,(d)=>{
if(d.diff_type == TYPE.SOURCE){
setSelectedSourceDid(d.selectedSourceDid);
}else{
Expand All @@ -702,7 +706,7 @@ export function SchemaDiffCompare({ params }) {

useEffect(()=>{
if(oldSchemaDiffData.current){
_.each(oldSchemaDiffData.current,(d)=>{
_.each(oldSchemaDiffData.current?.data,(d)=>{
if(d.diff_type == TYPE.SOURCE){
setSelectedSourceScid(d.selectedSourceScid);
}else{
Expand Down Expand Up @@ -802,6 +806,7 @@ export function SchemaDiffCompare({ params }) {
}}
filterParams={getFilterParams()}
compareParams={compareOptions}
filters={filterOptions}
></SchemaDiffButtonComponent>
</Grid>
</Grid>
Expand Down
Loading