Skip to content

Commit 72ddc0b

Browse files
rueckstiessThomas Rueckstiess
authored andcommitted
COMPASS-292 explain view zero state (#617)
* add App.StatusRow component (shared component) and styles. * remove explain's own StatusRow and use App.StatusRow * replace index notice with App.StatusRow for consistency. * remove validation notice and replace with App.StatusRow Note: Validation had its own StatusRow component. I renamed that to ValidationStatusRow, including styles. Eventually, the two status rows should be unified if possible. # Conflicts: # src/internal-packages/explain/lib/components/compass-explain.jsx
1 parent 18f57ee commit 72ddc0b

File tree

16 files changed

+78
-63
lines changed

16 files changed

+78
-63
lines changed

src/internal-packages/app/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const app = require('ampersand-app');
22
const StoreConnector = require('./lib/components/store-connector');
33
const SortableTable = require('./lib/components/sortable-table');
44
const TabNavBar = require('./lib/components/tab-nav-bar');
5+
const StatusRow = require('./lib/components/status-row');
56
const InstanceActions = require('./lib/actions/instance-actions');
67
const InstanceStore = require('./lib/stores/instance-store');
78
const CollectionStore = require('./lib/stores/collection-store');
@@ -15,6 +16,7 @@ function activate() {
1516
app.appRegistry.registerComponent('App.SortableTable', SortableTable);
1617
app.appRegistry.registerComponent('App.ModalStatusMessage', ModalStatusMessage);
1718
app.appRegistry.registerComponent('App.TabNavBar', TabNavBar);
19+
app.appRegistry.registerComponent('App.StatusRow', StatusRow);
1820
app.appRegistry.registerAction('App.InstanceActions', InstanceActions);
1921
app.appRegistry.registerStore('App.InstanceStore', InstanceStore);
2022
app.appRegistry.registerStore('App.CollectionStore', CollectionStore);
@@ -28,6 +30,7 @@ function deactivate() {
2830
app.appRegistry.deregisterComponent('App.SortableTable');
2931
app.appRegistry.deregisterComponent('App.ModalStatusMessage');
3032
app.appRegistry.deregisterComponent('App.TabNavBar');
33+
app.appRegistry.deregisterComponent('App.StatusRow');
3134
app.appRegistry.deregisterAction('App.InstanceActions');
3235
app.appRegistry.deregisterStore('App.InstanceStore');
3336
app.appRegistry.deregisterStore('App.CollectionStore');

src/internal-packages/explain/lib/components/shared/status-row.jsx renamed to src/internal-packages/app/lib/components/status-row.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,27 @@ class StatusRow extends React.Component {
88
* @returns {React.Component} The component.
99
*/
1010
render() {
11+
let className = 'status-row';
12+
if (this.props.style !== 'default') {
13+
className += ` status-row-has-${this.props.style}`;
14+
}
1115
return (
12-
<div className="status-row">
13-
{this.props.children}
16+
<div className={className}>
17+
{this.props.children}
1418
</div>
1519
);
1620
}
1721
}
1822

1923
StatusRow.propTypes = {
24+
style: React.PropTypes.oneOf(['default', 'warning', 'error']),
2025
children: React.PropTypes.node
2126
};
2227

28+
StatusRow.defaultProps = {
29+
style: 'default'
30+
};
31+
2332
StatusRow.displayName = 'StatusRow';
2433

2534
module.exports = StatusRow;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@import './sortable-table.less';
22
@import './modal-status-message.less';
33
@import './tab-nav-bar.less';
4+
@import './status-row.less';
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
.status-row {
2+
display: flex;
3+
flex-wrap: nowrap;
4+
align-items: center;
5+
padding: 5px 12px;
6+
7+
min-height: 26px;
8+
border-bottom: 1px solid @gray7;
9+
10+
font-size: 13px;
11+
font-weight: 200;
12+
13+
background-color: @gray8;
14+
color: #000;
15+
span, div, p {
16+
display: inline-block;
17+
}
18+
}
19+
20+
.status-row-has-warning {
21+
background-color: #FEE9C3;
22+
color: #7F6A4E;
23+
}

src/internal-packages/explain/lib/components/compass-explain.jsx

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const React = require('react');
22
const app = require('ampersand-app');
33
const ExplainBody = require('./explain-body');
44
const ExplainHeader = require('./explain-header');
5-
65
const ExplainActions = require('../actions');
6+
const StatusRow = app.appRegistry.getComponent('App.StatusRow');
77

88
// const debug = require('debug')('mongodb-compass:explain');
99

@@ -22,6 +22,11 @@ const ExplainActions = require('../actions');
2222
* .explain-json (mutually exclusive with .explain-tree)
2323
*/
2424

25+
const READ_ONLY_WARNING = 'Explain plans on readonly views are not supported.';
26+
27+
const COLLECTION_SCAN_WARNING = 'To prevent unintended collection scans, please'
28+
+ ' enter your query first before applying and viewing your explain plan.';
29+
2530
class CompassExplain extends React.Component {
2631

2732
constructor(props) {
@@ -34,7 +39,15 @@ class CompassExplain extends React.Component {
3439
this.queryBar = app.appRegistry.getComponent('Query.QueryBar');
3540
}
3641

37-
renderComponent() {
42+
renderWarning(warning) {
43+
return (
44+
<StatusRow style="warning">
45+
{warning}
46+
</StatusRow>
47+
);
48+
}
49+
50+
renderContent() {
3851
return (
3952
<div className="column-container with-refinebar">
4053
<div className="column main">
@@ -57,24 +70,26 @@ class CompassExplain extends React.Component {
5770
);
5871
}
5972

60-
renderReadonly() {
61-
return (
62-
<div className="compass-explain-notice">
63-
Explain plans on readonly views are not supported.
64-
</div>
65-
);
66-
}
67-
6873
/**
6974
* Render Explain.
7075
*
7176
* @returns {React.Component} The Explain view.
7277
*/
7378
render() {
79+
let content;
80+
81+
if (this.CollectionStore.isReadonly()) {
82+
content = this.renderWarning(READ_ONLY_WARNING);
83+
} else if (this.props.explainState === 'initial') {
84+
content = this.renderWarning(COLLECTION_SCAN_WARNING);
85+
} else {
86+
content = this.renderContent();
87+
}
88+
7489
return (
7590
<div className="compass-explain header-margin">
7691
<this.queryBar />
77-
{this.CollectionStore.isReadonly() ? this.renderReadonly() : this.renderComponent()}
92+
{content}
7893
</div>
7994
);
8095
}

src/internal-packages/explain/lib/components/explain-header.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
const React = require('react');
22
const ExplainSummary = require('./explain-summary');
3+
const app = require('ampersand-app');
34

45
const ViewSwitcher = require('./shared/view-switcher');
5-
const StatusRow = require('./shared/status-row');
6+
const StatusRow = app.appRegistry.getComponent('App.StatusRow');
67

78
const ExplainActions = require('../actions');
89

src/internal-packages/explain/styles/compass-explain.less

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
.compass-explain {
22

3-
&-notice {
4-
color: steelblue;
5-
background-color: #b0e0e6;
6-
border-radius: 5px;
7-
padding: 15px;
8-
margin-bottom: 10px;
9-
}
10-
113
// hacks for json view on explain tab
124
ol.document-list li.document-list-item ol.document-property-body li.document-property.array ol.document-property-body .document-property-key,
135
ol.document-list li.document-list-item ol.document-property-body li.document-property.object ol.document-property-body .document-property-key {

src/internal-packages/explain/styles/index.less

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@
1010

1111
// shared components
1212
@import './shared/view-switcher.less';
13-
@import './shared/status-row.less';
1413
@import './shared/palette.less';

src/internal-packages/explain/styles/shared/status-row.less

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/internal-packages/indexes/lib/component/indexes.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const IndexList = require('./index-list');
44
const CreateIndexButton = require('./create-index-button');
55
const LoadIndexesStore = require('../store/load-indexes-store');
66
const app = require('ampersand-app');
7+
const StatusRow = app.appRegistry.getComponent('App.StatusRow');
78

89
/**
910
* Component for the indexes.
@@ -67,9 +68,9 @@ class Indexes extends React.Component {
6768

6869
renderReadonly() {
6970
return (
70-
<div className="index-container-notice">
71+
<StatusRow style="warning">
7172
Readonly views may not contain indexes.
72-
</div>
73+
</StatusRow>
7374
);
7475
}
7576

0 commit comments

Comments
 (0)