Fixed an issue where tools settings changed by the users were not restored on application relaunch. #8988
parent
3e05f7a14f
commit
5abd9e3c5b
|
|
@ -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',
|
||||
|
|
@ -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, '');
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -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}/>
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
@ -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,
|
||||
|
|
@ -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)=>{
|
||||
|
|
@ -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=()=>{
|
||||
|
|
@ -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 = [
|
||||
|
|
@ -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 }),
|
||||
}));
|
||||
}
|
||||
}],
|
||||
];
|
||||
|
|
@ -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(()=>{
|
||||
|
|
@ -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>
|
||||
|
|
@ -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>
|
||||
</>)
|
||||
);
|
||||
|
|
@ -351,6 +400,7 @@ MainToolBar.propTypes = {
|
|||
notation: PropTypes.string,
|
||||
onNotationChange: PropTypes.func,
|
||||
connectionInfo: PropTypes.object,
|
||||
toolbarPrefs: PropTypes.object,
|
||||
};
|
||||
|
||||
const ColorButton = withColorPicker(PgIconButton);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
|
@ -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{
|
||||
|
|
@ -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)...');
|
||||
|
|
@ -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{
|
||||
|
|
@ -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{
|
||||
|
|
@ -802,6 +806,7 @@ export function SchemaDiffCompare({ params }) {
|
|||
}}
|
||||
filterParams={getFilterParams()}
|
||||
compareParams={compareOptions}
|
||||
filters={filterOptions}
|
||||
></SchemaDiffButtonComponent>
|
||||
</Grid>
|
||||
</Grid>
|
||||
|
|
|
|||
Loading…
Reference in New Issue