Skip to content

Commit 9961ce2

Browse files
authored
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.
1 parent e3ffbc6 commit 9961ce2

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,7 +2,7 @@ const React = require('react');
22
const app = require('ampersand-app');
33
const ExplainBody = require('./explain-body');
44
const ExplainHeader = require('./explain-header');
5-
5+
const StatusRow = app.appRegistry.getComponent('App.StatusRow');
66
// const debug = require('debug')('mongodb-compass:explain');
77

88
/**
@@ -20,6 +20,11 @@ const ExplainHeader = require('./explain-header');
2020
* .explain-json (mutually exclusive with .explain-tree)
2121
*/
2222

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

2530
constructor(props) {
@@ -31,7 +36,15 @@ class CompassExplain extends React.Component {
3136
this.queryBar = app.appRegistry.getComponent('Query.QueryBar');
3237
}
3338

34-
renderComponent() {
39+
renderWarning(warning) {
40+
return (
41+
<StatusRow style="warning">
42+
{warning}
43+
</StatusRow>
44+
);
45+
}
46+
47+
renderContent() {
3548
return (
3649
<div className="column-container with-refinebar">
3750
<div className="column main">
@@ -54,24 +67,26 @@ class CompassExplain extends React.Component {
5467
);
5568
}
5669

57-
renderReadonly() {
58-
return (
59-
<div className="compass-explain-notice">
60-
Explain plans on readonly views are not supported.
61-
</div>
62-
);
63-
}
64-
6570
/**
6671
* Render Explain.
6772
*
6873
* @returns {React.Component} The Explain view.
6974
*/
7075
render() {
76+
let content;
77+
78+
if (this.CollectionStore.isReadonly()) {
79+
content = this.renderWarning(READ_ONLY_WARNING);
80+
} else if (this.props.explainState === 'initial') {
81+
content = this.renderWarning(COLLECTION_SCAN_WARNING);
82+
} else {
83+
content = this.renderContent();
84+
}
85+
7186
return (
7287
<div className="compass-explain header-margin">
7388
<this.queryBar />
74-
{this.CollectionStore.isReadonly() ? this.renderReadonly() : this.renderComponent()}
89+
{content}
7590
</div>
7691
);
7792
}

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)