-
Notifications
You must be signed in to change notification settings - Fork 849
Expand file tree
/
Copy pathSchemaDiffModule.js
More file actions
117 lines (104 loc) · 4.02 KB
/
SchemaDiffModule.js
File metadata and controls
117 lines (104 loc) · 4.02 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
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2026, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
import ReactDOM from 'react-dom/client';
import gettext from 'sources/gettext';
import url_for from 'sources/url_for';
import pgWindow from 'sources/window';
import * as commonUtils from 'sources/utils';
import getApiInstance from '../../../../static/js/api_instance';
import Theme from '../../../../static/js/Theme';
import ModalProvider from '../../../../static/js/helpers/ModalProvider';
import SchemaDiffComponent from './components/SchemaDiffComponent';
import { AllPermissionTypes, BROWSER_PANELS } from '../../../../browser/static/js/constants';
import { NotifierProvider } from '../../../../static/js/helpers/Notifier';
import usePreferences, { listenPreferenceBroadcast } from '../../../../preferences/static/js/store';
import pgAdmin from 'sources/pgadmin';
import { PgAdminProvider } from '../../../../static/js/PgAdminProvider';
import { ApplicationStateProvider } from '../../../../settings/static/ApplicationStateProvider';
export default class SchemaDiff {
static instance;
static panelTitleCount = 1;
static getInstance(...args) {
if (!SchemaDiff.instance) {
SchemaDiff.instance = new SchemaDiff(...args);
}
return SchemaDiff.instance;
}
constructor(pgAdmin, pgBrowser) {
this.pgAdmin = pgAdmin;
this.pgBrowser = pgBrowser;
this.api = getApiInstance();
}
init() {
let self = this;
if (self.initialized)
return;
self.initialized = true;
// Define the nodes on which the menus to be appear
self.pgBrowser.add_menus([{
name: 'schema_diff',
module: self,
applies: ['tools'],
callback: 'launchSchemaDiff',
priority: 1,
label: gettext('Schema Diff'),
enable: true,
below: true,
permission: AllPermissionTypes.TOOLS_SCHEMA_DIFF,
}]);
}
launchSchemaDiff(params={}) {
let panelTitle = SchemaDiff.panelTitleCount > 1 ? gettext('Schema Diff - %s', SchemaDiff.panelTitleCount) : gettext('Schema Diff');
SchemaDiff.panelTitleCount++;
const trans_id = commonUtils.getRandomInt(1, 9999999);
let url_params = {
'trans_id': trans_id,
'editor_title': panelTitle,
},
baseUrl = url_for('schema_diff.panel', url_params);
let browserPreferences = usePreferences.getState().getPreferencesForModule('browser');
let openInNewTab = browserPreferences.new_browser_tab_open;
// Extract bgcolor and fgcolor from server icon
let bgcolor = null;
let fgcolor = null;
let serverId = null;
const selectedItem = pgAdmin.Browser.tree?.selected();
if (selectedItem) {
const selectedNodeInfo = pgAdmin.Browser.tree?.getTreeNodeHierarchy(selectedItem);
({ bgcolor, fgcolor } = commonUtils.getServerColors(selectedNodeInfo?.server?.icon));
serverId = selectedNodeInfo?.server?._id;
}
pgAdmin.Browser.Events.trigger(
'pgadmin:tool:show',
`${BROWSER_PANELS.SCHEMA_DIFF_TOOL}_${trans_id}`,
baseUrl,
{...params},
{title: panelTitle, icon: 'pg-font-icon icon-compare', manualClose: false, renamable: true, bgcolor: bgcolor, fgcolor: fgcolor, server_id: serverId},
Boolean(openInNewTab?.includes('schema_diff'))
);
return true;
}
async load(container, trans_id, params) {
pgAdmin.Browser.keyboardNavigation.init();
await listenPreferenceBroadcast();
const root = ReactDOM.createRoot(container);
root.render(
<Theme>
<PgAdminProvider value={pgAdmin}>
<ApplicationStateProvider>
<ModalProvider>
<NotifierProvider pgAdmin={pgAdmin} pgWindow={pgWindow} />
<SchemaDiffComponent params={{ transId: trans_id, pgAdmin: pgWindow.pgAdmin, params:params }}></SchemaDiffComponent>
</ModalProvider>
</ApplicationStateProvider>
</PgAdminProvider>
</Theme>
);
}
}