Skip to content

Commit ffdc39a

Browse files
committed
Revert "COMPASS-1101: Use CRUD from External Package (#1190)"
This reverts commit 19f1aeb.
1 parent 19f1aeb commit ffdc39a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+6129
-3
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"packages": [
3939
"node_modules/@mongodb-js/compass-serverstats",
4040
"node_modules/@mongodb-js/compass-document-validation",
41-
"node_modules/@mongodb-js/compass-deployment-awareness",
42-
"node_modules/@mongodb-js/compass-crud"
41+
"node_modules/@mongodb-js/compass-deployment-awareness"
4342
],
4443
"styles": [
4544
"index"
@@ -114,7 +113,6 @@
114113
"dependencies": {
115114
"@mongodb-js/compass-deployment-awareness": "3.0.0",
116115
"@mongodb-js/compass-document-validation": "4.0.3",
117-
"@mongodb-js/compass-crud": "0.0.5",
118116
"@mongodb-js/compass-serverstats": "9.1.1",
119117
"ampersand-collection": "^1.5.0",
120118
"ampersand-collection-filterable": "^0.2.1",

src/app/index.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
@import "../internal-packages/collection/styles/index.less";
1919
@import "../internal-packages/collection-stats/styles/index.less";
2020
@import "../internal-packages/chart/styles/index.less";
21+
@import "../internal-packages/crud/styles/index.less";
2122
@import "../internal-packages/database-ddl/styles/index.less";
2223
@import "../internal-packages/home/styles/index.less";
2324
@import "../internal-packages/status/styles/index.less";
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# Compass CRUD Package
2+
3+
Provide functionality shown in the "Documents" tab in the collection view.
4+
5+
## Available Resources in the App Registry
6+
7+
### Components
8+
9+
#### Definitions
10+
11+
| Key | Description |
12+
|---------------------|------------------------------|
13+
| `CRUD.Document` | Renders a single document. |
14+
| `CRUD.DocumentList` | Renders a list of documents. |
15+
16+
### Actions
17+
18+
| Key | Description |
19+
|----------------|-------------------------------|
20+
| `CRUD.Actions` | All the CRUD related actions. |
21+
22+
### Stores
23+
24+
| Key | Description
25+
|-------------------------------|---------------------------------------------------------|
26+
| `CRUD.InsertDocumentStore` | Triggers when a document is inserted. |
27+
| `CRUD.ResetDocumentListStore` | Triggers when the query filter is reset. |
28+
| `CRUD.LoadMoreDocumentsStore` | Triggers when more documents are fetched via scrolling. |
29+
30+
## Usage
31+
32+
Render an editable document in a React component.
33+
34+
```jsx
35+
const app = require('hadron-app');
36+
const React = require('react');
37+
38+
class MyComponent extends React.Component {
39+
constructor(props) {
40+
super(props);
41+
this.Document = app.appRegistry.getRole('CRUD.Document')[0].component;
42+
}
43+
render() {
44+
return (<this.Document doc={this.props.document} editable />);
45+
}
46+
}
47+
```
48+
49+
Render a non-editable pre-expanded document in a React component.
50+
51+
```jsx
52+
const app = require('hadron-app');
53+
const React = require('react');
54+
55+
class MyComponent extends React.Component {
56+
constructor(props) {
57+
super(props);
58+
this.Document = app.appRegistry.getRole('CRUD.Document')[0].component;
59+
}
60+
render() {
61+
return (<this.Document doc={this.props.document} expandAll />);
62+
}
63+
}
64+
```
65+
66+
Listen to the various CRUD actions.
67+
68+
```javascript
69+
const app = require('hadron-app');
70+
const CrudActions = app.appRegistry.getAction('CRUD.Actions');
71+
72+
CrudActions.documentRemoved.listen((id) => {
73+
console.log(`Document with _id ${id} removed.`);
74+
});
75+
76+
CrudActions.openInsertDocumentDialog((doc, clone) => {
77+
if (clone) {
78+
console.log('Opening insert dialog with cloned document');
79+
}
80+
});
81+
82+
CrudActions.insertDocument((doc) => {
83+
console.log('Inserting document into db');
84+
});
85+
```
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
const app = require('hadron-app');
2+
const Document = require('./lib/component/document');
3+
const DocumentList = require('./lib/component/document-list');
4+
const Actions = require('./lib/actions');
5+
const InsertDocumentStore = require('./lib/store/insert-document-store');
6+
const ResetDocumentListStore = require('./lib/store/reset-document-list-store');
7+
const LoadMoreDocumentsStore = require('./lib/store/load-more-documents-store');
8+
const {
9+
StandardEditor,
10+
DateEditor,
11+
StringEditor,
12+
Int32Editor,
13+
DoubleEditor,
14+
NullEditor,
15+
UndefinedEditor,
16+
ObjectIDEditor
17+
} = require('./lib/component/editor');
18+
19+
const COLLECTION_TAB_ROLE = {
20+
component: DocumentList,
21+
name: 'DOCUMENTS',
22+
order: 1
23+
};
24+
25+
const DOCUMENT_ROLE = {
26+
component: Document,
27+
name: 'STANDARD',
28+
order: 1
29+
};
30+
31+
const STANDARD_EDITOR_ROLE = {
32+
component: StandardEditor
33+
};
34+
35+
const DATE_EDITOR_ROLE = {
36+
component: DateEditor
37+
};
38+
39+
const DOUBLE_EDITOR_ROLE = {
40+
component: DoubleEditor
41+
};
42+
43+
const STRING_EDITOR_ROLE = {
44+
component: StringEditor
45+
};
46+
47+
const INT32_EDITOR_ROLE = {
48+
component: Int32Editor
49+
};
50+
51+
const NULL_EDITOR_ROLE = {
52+
component: NullEditor
53+
};
54+
55+
const UNDEFINED_EDITOR_ROLE = {
56+
component: UndefinedEditor
57+
};
58+
59+
const OBJECT_ID_EDITOR_ROLE = {
60+
component: ObjectIDEditor
61+
};
62+
63+
/**
64+
* Activate all the components in the CRUD package.
65+
*/
66+
function activate(appRegistry) {
67+
appRegistry.registerRole('Collection.Tab', COLLECTION_TAB_ROLE);
68+
appRegistry.registerRole('CRUD.Document', DOCUMENT_ROLE);
69+
appRegistry.registerRole('CRUD.Editor.Standard', STANDARD_EDITOR_ROLE);
70+
appRegistry.registerRole('CRUD.Editor.Date', DATE_EDITOR_ROLE);
71+
appRegistry.registerRole('CRUD.Editor.Double', DOUBLE_EDITOR_ROLE);
72+
appRegistry.registerRole('CRUD.Editor.String', STRING_EDITOR_ROLE);
73+
appRegistry.registerRole('CRUD.Editor.Int32', INT32_EDITOR_ROLE);
74+
appRegistry.registerRole('CRUD.Editor.Null', NULL_EDITOR_ROLE);
75+
appRegistry.registerRole('CRUD.Editor.Undefined', UNDEFINED_EDITOR_ROLE);
76+
appRegistry.registerRole('CRUD.Editor.ObjectID', OBJECT_ID_EDITOR_ROLE);
77+
appRegistry.registerAction('CRUD.Actions', Actions);
78+
appRegistry.registerStore('CRUD.InsertDocumentStore', InsertDocumentStore);
79+
appRegistry.registerStore('CRUD.ResetDocumentListStore', ResetDocumentListStore);
80+
appRegistry.registerStore('CRUD.LoadMoreDocumentsStore', LoadMoreDocumentsStore);
81+
}
82+
83+
/**
84+
* Deactivate all the components in the CRUD package.
85+
*/
86+
function deactivate() {
87+
app.appRegistry.deregisterRole('Collection.Tab', COLLECTION_TAB_ROLE);
88+
app.appRegistry.deregisterRole('CRUD.Document', DOCUMENT_ROLE);
89+
app.appRegistry.deregisterRole('CRUD.Editor.Standard', STANDARD_EDITOR_ROLE);
90+
app.appRegistry.deregisterRole('CRUD.Editor.Date', DATE_EDITOR_ROLE);
91+
app.appRegistry.deregisterRole('CRUD.Editor.Double', DOUBLE_EDITOR_ROLE);
92+
app.appRegistry.deregisterRole('CRUD.Editor.String', STRING_EDITOR_ROLE);
93+
app.appRegistry.deregisterRole('CRUD.Editor.Int32', INT32_EDITOR_ROLE);
94+
app.appRegistry.deregisterRole('CRUD.Editor.Null', NULL_EDITOR_ROLE);
95+
app.appRegistry.deregisterRole('CRUD.Editor.Undefined', UNDEFINED_EDITOR_ROLE);
96+
app.appRegistry.deregisterRole('CRUD.Editor.ObjectID', OBJECT_ID_EDITOR_ROLE);
97+
app.appRegistry.deregisterAction('CRUD.Actions');
98+
app.appRegistry.deregisterStore('CRUD.InsertDocumentStore');
99+
app.appRegistry.deregisterStore('CRUD.ResetDocumentListStore');
100+
app.appRegistry.deregisterStore('CRUD.LoadMoreDocumentsStore');
101+
}
102+
103+
module.exports.activate = activate;
104+
module.exports.deactivate = deactivate;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const fs = require('fs');
2+
const Reflux = require('reflux');
3+
const debug = require('debug')('mongodb-compass:crud:actions');
4+
5+
const Actions = Reflux.createActions([
6+
'documentRemoved',
7+
'openInsertDocumentDialog',
8+
'closeInsertDocumentDialog',
9+
'insertDocument',
10+
'fileDropped',
11+
'refreshDocuments',
12+
'closeAllMenus',
13+
'fetchNextDocuments',
14+
'elementInvalid',
15+
'elementValid'
16+
]);
17+
18+
document.ondragover = document.ondrop = (ev) => {
19+
ev.preventDefault();
20+
};
21+
22+
document.body.ondrop = (ev) => {
23+
ev.preventDefault();
24+
const file = ev.dataTransfer.files[0];
25+
if (file) {
26+
const path = file.path;
27+
fs.readFile(path, 'utf-8', (error, data) => {
28+
if (error) {
29+
debug(`Error opening file '${path}': ${error.message}`);
30+
}
31+
try {
32+
Actions.openInsertDocumentDialog(JSON.parse(data), false);
33+
} catch (e) {
34+
debug(`File ${path} is not a single parseable JSON document: ${e.message}`);
35+
}
36+
});
37+
}
38+
};
39+
40+
module.exports = Actions;
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
const React = require('react');
2+
const PropTypes = require('prop-types');
3+
const { IconButton } = require('hadron-react-buttons');
4+
5+
/**
6+
* Override once the button to be able to update.
7+
*/
8+
class UpdatableIconButton extends IconButton {
9+
10+
/**
11+
* By default should always need to to re-render itself.
12+
*
13+
* @returns {Boolean} Always true.
14+
*/
15+
shouldComponentUpdate() {
16+
return true;
17+
}
18+
}
19+
20+
/**
21+
* Component for actions on the document.
22+
*/
23+
class DocumentActions extends React.Component {
24+
25+
/**
26+
* Instantiate the actions.
27+
*
28+
* @param {Object} props - The properties.
29+
*/
30+
constructor(props) {
31+
super(props);
32+
this.state = { allExpanded: props.allExpanded };
33+
}
34+
35+
/**
36+
* Set the state when new props are received.
37+
*
38+
* @param {Object} nextProps - The new props.
39+
*/
40+
componentWillReceiveProps(nextProps) {
41+
if (nextProps.allExpanded !== this.state.allExpanded) {
42+
this.setState({ allExpanded: nextProps.allExpanded });
43+
}
44+
}
45+
46+
/**
47+
* Render the expand all button.
48+
*
49+
* @returns {React.Component} The expand all button.
50+
*/
51+
renderExpandAll() {
52+
const title = this.state.allExpanded ? 'Collapse All' : 'Expand All';
53+
const iconClass = this.state.allExpanded ? 'fa-angle-down' : 'fa-angle-right';
54+
return (
55+
<UpdatableIconButton
56+
title={title}
57+
clickHandler={this.props.expandAll}
58+
className="document-actions-button document-actions-expand-button btn btn-default btn-xs"
59+
iconClassName={`document-actions-button-icon fa ${iconClass}`}
60+
dataTestId="expand-all-button" />
61+
);
62+
}
63+
64+
/**
65+
* Render the actions.
66+
*
67+
* @returns {Component} The actions component.
68+
*/
69+
render() {
70+
return (
71+
<div className="document-actions">
72+
<div className="document-actions-left">
73+
{this.renderExpandAll()}
74+
</div>
75+
<div className="document-actions-right">
76+
<IconButton
77+
title="Edit Document"
78+
className="document-actions-button btn btn-default btn-xs"
79+
iconClassName="document-actions-button-icon fa fa-pencil"
80+
dataTestId="edit-document-button"
81+
clickHandler={this.props.edit} />
82+
<IconButton
83+
title="Clone Document"
84+
className="document-actions-button btn btn-default btn-xs"
85+
iconClassName="document-actions-button-icon fa fa-clone"
86+
dataTestId="clone-document-button"
87+
clickHandler={this.props.clone} />
88+
<IconButton
89+
title="Delete Document"
90+
className="document-actions-button btn btn-default btn-xs"
91+
iconClassName="document-actions-button-icon fa fa-trash-o"
92+
dataTestId="delete-document-button"
93+
clickHandler={this.props.remove} />
94+
</div>
95+
</div>
96+
);
97+
}
98+
}
99+
100+
DocumentActions.displayName = 'DocumentActions';
101+
102+
DocumentActions.propTypes = {
103+
edit: PropTypes.func.isRequired,
104+
remove: PropTypes.func.isRequired,
105+
clone: PropTypes.func.isRequired,
106+
allExpanded: PropTypes.bool.isRequired,
107+
expandAll: PropTypes.func.isRequired
108+
};
109+
110+
module.exports = DocumentActions;

0 commit comments

Comments
 (0)