This repository was archived by the owner on May 17, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.js
More file actions
155 lines (130 loc) · 5.33 KB
/
index.js
File metadata and controls
155 lines (130 loc) · 5.33 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import React from 'react';
import ReactDOM from 'react-dom';
import app from 'hadron-app';
import AppRegistry from 'hadron-app-registry';
import { AppContainer } from 'react-hot-loader';
import { activate } from 'plugin';
import ConnectedDocumentList from 'components/connected-document-list';
import { activate as statusActivate } from '@mongodb-js/compass-status';
import { activate as activateQueryBar } from '@mongodb-js/compass-query-bar';
import configureStore, { setDataProvider } from 'stores';
import configureActions from 'actions';
window.jQuery = require('jquery');
// Import global less file. Note: these styles WILL NOT be used in compass, as compass provides its own set
// of global styles. If you are wishing to style a given component, you should be writing a less file per
// component as per the CSS Modules ICSS spec. @see src/components/toggle-button for an example.
import 'bootstrap/less/bootstrap.less';
import 'less/index.less';
const DB = 'echo';
const COLL = 'bands';
const appRegistry = new AppRegistry();
global.hadronApp = app;
global.hadronApp.appRegistry = appRegistry;
// Activate our plugin with the Hadron App Registry
const QueryChangedStore = require('./stores/query-changed-store');
const TextWriteButton = require('./components/text-write-button');
const OptionWriteSelector = require('./components/option-write-selector');
appRegistry.registerStore('Query.ChangedStore', QueryChangedStore);
appRegistry.registerComponent('DeploymentAwareness.TextWriteButton', TextWriteButton);
appRegistry.registerComponent('DeploymentAwareness.OptionWriteSelector', OptionWriteSelector);
statusActivate(appRegistry);
activate(appRegistry);
appRegistry.onActivated();
// Since we are using HtmlWebpackPlugin WITHOUT a template,
// we should create our own root node in the body element before rendering into it.
const root = document.createElement('div');
root.style = 'height: 100vh';
root.id = 'root';
document.body.appendChild(root);
const localAppRegistry = new AppRegistry();
activateQueryBar(localAppRegistry);
const queryBarRole = localAppRegistry.getRole('Query.QueryBar')[0];
const queryBarActions = queryBarRole.configureActions();
const queryBarStore = queryBarRole.configureStore({
localAppRegistry: localAppRegistry,
serverVersion: '4.2.0',
actions: queryBarActions
});
localAppRegistry.registerStore(queryBarRole.storeName, queryBarStore);
localAppRegistry.registerAction(queryBarRole.actionName, queryBarActions);
const actions = configureActions();
const store = configureStore({
actions: actions,
localAppRegistry: localAppRegistry,
globalAppRegistry: appRegistry,
namespace: `${DB}.${COLL}`,
isReadonly: false
});
// Create a HMR enabled render function
const render = Component => {
// if needing to debug the Status Plugin within this component, uncomment
// this line and a <Status/> div to the below render function.
// const Status = global.hadronApp.appRegistry.getRole('Application.Status')[0].component;
ReactDOM.render(
<AppContainer>
<Component store={store} actions={actions} />
</AppContainer>,
document.getElementById('root')
);
};
// For initialization events to happen in isolation, uncomment the
// following lines as needed in the same places they are commented out.
//
// // Application was initialized.
// appRegistry.emit('application-initialized', '1.11.0-dev');
// Render our plugin - don't remove the following line.
render(ConnectedDocumentList);
// // Data service initialization and connection.
import Connection from 'mongodb-connection-model';
import DataService from 'mongodb-data-service';
const connection = new Connection({
hostname: '127.0.0.1',
port: 27017,
ns: DB,
mongodb_database_name: 'admin'
});
const dataService = new DataService(connection);
appRegistry.emit('data-service-initialized', dataService);
dataService.connect((error, ds) => {
if (!error) appRegistry.emit('compass:status:done');
setDataProvider(store, error, ds);
localAppRegistry.emit('query-changed', { ns: `${DB}.${COLL}` });
// global.hadronApp.appRegistry.emit('instance-refreshed', { instance: {
// dataLake: {
// isDataLake: true, version: '2'
// },
// build: { version: '1' }
// }});
});
// For automatic switching to specific namespaces, uncomment below as needed.
// appRegistry.emit('database-changed', 'database');
// For plugins based on query execution, comment out below:
// const query = {
// filter: { name: 'testing' },
// project: { name: 1 },
// sort: { name: -1 },
// skip: 0,
// limit: 20,
// ns: 'database.collection'
// }
// appRegistry.emit('query-applied', query);
if (module.hot) {
/**
* Warning from React Router, caused by react-hot-loader.
* The warning can be safely ignored, so filter it from the console.
* Otherwise you'll see it every time something changes.
* See https://github.com/gaearon/react-hot-loader/issues/298
*/
const orgError = console.error; // eslint-disable-line no-console
console.error = (message) => { // eslint-disable-line no-console
if (message && message.indexOf('You cannot change <Router routes>;') === -1) {
// Log the error as normally
orgError.apply(console, [message]);
}
};
module.hot.accept('plugin', () => {
// Because Webpack 2 has built-in support for ES2015 modules,
// you won't need to re-require your app root in module.hot.accept
render(ConnectedDocumentList);
});
}