diff --git a/src/internal-packages/app/index.js b/src/internal-packages/app/index.js index 1264a306c99..54b168a89c0 100644 --- a/src/internal-packages/app/index.js +++ b/src/internal-packages/app/index.js @@ -2,6 +2,7 @@ const app = require('ampersand-app'); const StoreConnector = require('./lib/components/store-connector'); const SortableTable = require('./lib/components/sortable-table'); const TabNavBar = require('./lib/components/tab-nav-bar'); +const StatusRow = require('./lib/components/status-row'); const InstanceActions = require('./lib/actions/instance-actions'); const InstanceStore = require('./lib/stores/instance-store'); const CollectionStore = require('./lib/stores/collection-store'); @@ -15,6 +16,7 @@ function activate() { app.appRegistry.registerComponent('App.SortableTable', SortableTable); app.appRegistry.registerComponent('App.ModalStatusMessage', ModalStatusMessage); app.appRegistry.registerComponent('App.TabNavBar', TabNavBar); + app.appRegistry.registerComponent('App.StatusRow', StatusRow); app.appRegistry.registerAction('App.InstanceActions', InstanceActions); app.appRegistry.registerStore('App.InstanceStore', InstanceStore); app.appRegistry.registerStore('App.CollectionStore', CollectionStore); @@ -28,6 +30,7 @@ function deactivate() { app.appRegistry.deregisterComponent('App.SortableTable'); app.appRegistry.deregisterComponent('App.ModalStatusMessage'); app.appRegistry.deregisterComponent('App.TabNavBar'); + app.appRegistry.deregisterComponent('App.StatusRow'); app.appRegistry.deregisterAction('App.InstanceActions'); app.appRegistry.deregisterStore('App.InstanceStore'); app.appRegistry.deregisterStore('App.CollectionStore'); diff --git a/src/internal-packages/explain/lib/components/shared/status-row.jsx b/src/internal-packages/app/lib/components/status-row.jsx similarity index 52% rename from src/internal-packages/explain/lib/components/shared/status-row.jsx rename to src/internal-packages/app/lib/components/status-row.jsx index 7c7e6e2b542..db575bcc5f5 100644 --- a/src/internal-packages/explain/lib/components/shared/status-row.jsx +++ b/src/internal-packages/app/lib/components/status-row.jsx @@ -8,18 +8,27 @@ class StatusRow extends React.Component { * @returns {React.Component} The component. */ render() { + let className = 'status-row'; + if (this.props.style !== 'default') { + className += ` status-row-has-${this.props.style}`; + } return ( -
- {this.props.children} +
+ {this.props.children}
); } } StatusRow.propTypes = { + style: React.PropTypes.oneOf(['default', 'warning', 'error']), children: React.PropTypes.node }; +StatusRow.defaultProps = { + style: 'default' +}; + StatusRow.displayName = 'StatusRow'; module.exports = StatusRow; diff --git a/src/internal-packages/app/styles/index.less b/src/internal-packages/app/styles/index.less index 273b79c20c3..77558548ff3 100644 --- a/src/internal-packages/app/styles/index.less +++ b/src/internal-packages/app/styles/index.less @@ -1,3 +1,4 @@ @import './sortable-table.less'; @import './modal-status-message.less'; @import './tab-nav-bar.less'; +@import './status-row.less'; diff --git a/src/internal-packages/app/styles/status-row.less b/src/internal-packages/app/styles/status-row.less new file mode 100644 index 00000000000..129c0b709a1 --- /dev/null +++ b/src/internal-packages/app/styles/status-row.less @@ -0,0 +1,23 @@ +.status-row { + display: flex; + flex-wrap: nowrap; + align-items: center; + padding: 5px 12px; + + min-height: 26px; + border-bottom: 1px solid @gray7; + + font-size: 13px; + font-weight: 200; + + background-color: @gray8; + color: #000; + span, div, p { + display: inline-block; + } +} + +.status-row-has-warning { + background-color: #FEE9C3; + color: #7F6A4E; +} diff --git a/src/internal-packages/explain/lib/components/compass-explain.jsx b/src/internal-packages/explain/lib/components/compass-explain.jsx index b3acecf2fe1..2c3c5a47176 100644 --- a/src/internal-packages/explain/lib/components/compass-explain.jsx +++ b/src/internal-packages/explain/lib/components/compass-explain.jsx @@ -2,7 +2,7 @@ const React = require('react'); const app = require('ampersand-app'); const ExplainBody = require('./explain-body'); const ExplainHeader = require('./explain-header'); - +const StatusRow = app.appRegistry.getComponent('App.StatusRow'); // const debug = require('debug')('mongodb-compass:explain'); /** @@ -20,6 +20,11 @@ const ExplainHeader = require('./explain-header'); * .explain-json (mutually exclusive with .explain-tree) */ +const READ_ONLY_WARNING = 'Explain plans on readonly views are not supported.'; + +const COLLECTION_SCAN_WARNING = 'To prevent unintended collection scans, please' + + ' enter your query first before applying and viewing your explain plan.'; + class CompassExplain extends React.Component { constructor(props) { @@ -31,7 +36,15 @@ class CompassExplain extends React.Component { this.queryBar = app.appRegistry.getComponent('Query.QueryBar'); } - renderComponent() { + renderWarning(warning) { + return ( + + {warning} + + ); + } + + renderContent() { return (
@@ -54,24 +67,26 @@ class CompassExplain extends React.Component { ); } - renderReadonly() { - return ( -
- Explain plans on readonly views are not supported. -
- ); - } - /** * Render Explain. * * @returns {React.Component} The Explain view. */ render() { + let content; + + if (this.CollectionStore.isReadonly()) { + content = this.renderWarning(READ_ONLY_WARNING); + } else if (this.props.explainState === 'initial') { + content = this.renderWarning(COLLECTION_SCAN_WARNING); + } else { + content = this.renderContent(); + } + return (
- {this.CollectionStore.isReadonly() ? this.renderReadonly() : this.renderComponent()} + {content}
); } diff --git a/src/internal-packages/explain/lib/components/explain-header.jsx b/src/internal-packages/explain/lib/components/explain-header.jsx index 05f4b7cc047..54d35f15f45 100644 --- a/src/internal-packages/explain/lib/components/explain-header.jsx +++ b/src/internal-packages/explain/lib/components/explain-header.jsx @@ -1,8 +1,9 @@ const React = require('react'); const ExplainSummary = require('./explain-summary'); +const app = require('ampersand-app'); const ViewSwitcher = require('./shared/view-switcher'); -const StatusRow = require('./shared/status-row'); +const StatusRow = app.appRegistry.getComponent('App.StatusRow'); const ExplainActions = require('../actions'); diff --git a/src/internal-packages/explain/styles/compass-explain.less b/src/internal-packages/explain/styles/compass-explain.less index 61fc0352d18..dcabe7037aa 100644 --- a/src/internal-packages/explain/styles/compass-explain.less +++ b/src/internal-packages/explain/styles/compass-explain.less @@ -1,13 +1,5 @@ .compass-explain { - &-notice { - color: steelblue; - background-color: #b0e0e6; - border-radius: 5px; - padding: 15px; - margin-bottom: 10px; - } - // hacks for json view on explain tab ol.document-list li.document-list-item ol.document-property-body li.document-property.array ol.document-property-body .document-property-key, ol.document-list li.document-list-item ol.document-property-body li.document-property.object ol.document-property-body .document-property-key { diff --git a/src/internal-packages/explain/styles/index.less b/src/internal-packages/explain/styles/index.less index f824d06ebcd..003bd8d6fb8 100644 --- a/src/internal-packages/explain/styles/index.less +++ b/src/internal-packages/explain/styles/index.less @@ -10,5 +10,4 @@ // shared components @import './shared/view-switcher.less'; -@import './shared/status-row.less'; @import './shared/palette.less'; diff --git a/src/internal-packages/explain/styles/shared/status-row.less b/src/internal-packages/explain/styles/shared/status-row.less deleted file mode 100644 index 3a6bcef820b..00000000000 --- a/src/internal-packages/explain/styles/shared/status-row.less +++ /dev/null @@ -1,14 +0,0 @@ -.status-row { - display: flex; - flex-wrap: nowrap; - align-items: center; - padding: 0 12px; - - min-height: 26px; - background-color: @gray8; - border-bottom: 1px solid #eaebeb; - - span, div, p { - display: inline-block; - } -} diff --git a/src/internal-packages/indexes/lib/component/indexes.jsx b/src/internal-packages/indexes/lib/component/indexes.jsx index e41bb1a1a1a..f9af4877f2b 100644 --- a/src/internal-packages/indexes/lib/component/indexes.jsx +++ b/src/internal-packages/indexes/lib/component/indexes.jsx @@ -4,6 +4,7 @@ const IndexList = require('./index-list'); const CreateIndexButton = require('./create-index-button'); const LoadIndexesStore = require('../store/load-indexes-store'); const app = require('ampersand-app'); +const StatusRow = app.appRegistry.getComponent('App.StatusRow'); /** * Component for the indexes. @@ -67,9 +68,9 @@ class Indexes extends React.Component { renderReadonly() { return ( -
+ Readonly views may not contain indexes. -
+ ); } diff --git a/src/internal-packages/indexes/styles/index.less b/src/internal-packages/indexes/styles/index.less index f6ad45adf6b..9832cf9344d 100644 --- a/src/internal-packages/indexes/styles/index.less +++ b/src/internal-packages/indexes/styles/index.less @@ -20,14 +20,6 @@ .index-container { - &-notice { - color: steelblue; - background-color: #b0e0e6; - border-radius: 5px; - padding: 15px; - margin-bottom: 10px; - } - .column-container { .column.main { &::-webkit-scrollbar { diff --git a/src/internal-packages/validation/lib/components/common/status-row.jsx b/src/internal-packages/validation/lib/components/common/status-row.jsx index 6b795137e77..c47357cb480 100644 --- a/src/internal-packages/validation/lib/components/common/status-row.jsx +++ b/src/internal-packages/validation/lib/components/common/status-row.jsx @@ -10,7 +10,7 @@ class StatusRow extends React.Component { */ render() { return ( - + {this.props.children} diff --git a/src/internal-packages/validation/lib/components/validation.jsx b/src/internal-packages/validation/lib/components/validation.jsx index 3745f1158b7..a4f629b1321 100644 --- a/src/internal-packages/validation/lib/components/validation.jsx +++ b/src/internal-packages/validation/lib/components/validation.jsx @@ -1,10 +1,11 @@ const app = require('ampersand-app'); const React = require('react'); const ValidationActions = require('../actions'); -const StatusRow = require('./common/status-row'); +const ValidationStatusRow = require('./common/status-row'); const ViewSwitcher = require('./common/view-switcher'); const RuleBuilder = require('./rule-builder'); const JSONView = require('./json-view'); +const StatusRow = app.appRegistry.getComponent('App.StatusRow'); const Grid = require('react-bootstrap').Grid; @@ -69,7 +70,7 @@ class Validation extends React.Component { return ( - + - + {view} ); @@ -85,9 +86,9 @@ class Validation extends React.Component { renderReadonly() { return ( -
+ Document validation rules may not be added to readonly views. -
+ ); } diff --git a/src/internal-packages/validation/styles/index.less b/src/internal-packages/validation/styles/index.less index 6056a1148e5..66be4862f8d 100644 --- a/src/internal-packages/validation/styles/index.less +++ b/src/internal-packages/validation/styles/index.less @@ -1,9 +1,9 @@ // import your less files here, one per component @import './validation.less'; @import './view-switcher.less'; -@import './status-row.less'; @import './rule-builder.less'; @import './json-view.less'; @import './option-selector.less'; @import './editable.less'; @import './json-input.less'; +@import './validation-status-row.less'; diff --git a/src/internal-packages/validation/styles/status-row.less b/src/internal-packages/validation/styles/validation-status-row.less similarity index 89% rename from src/internal-packages/validation/styles/status-row.less rename to src/internal-packages/validation/styles/validation-status-row.less index 257382a825a..2fe8e873ea7 100644 --- a/src/internal-packages/validation/styles/status-row.less +++ b/src/internal-packages/validation/styles/validation-status-row.less @@ -1,4 +1,4 @@ -.status-row { +.validation-status-row { display: flex; flex-wrap: nowrap; align-items: center; diff --git a/src/internal-packages/validation/styles/validation.less b/src/internal-packages/validation/styles/validation.less index 28d99918823..91942a743cb 100644 --- a/src/internal-packages/validation/styles/validation.less +++ b/src/internal-packages/validation/styles/validation.less @@ -1,13 +1,5 @@ .validation { - &-notice { - color: steelblue; - background-color: #b0e0e6; - border-radius: 5px; - padding: 15px; - margin-bottom: 10px; - } - &-rule-builder-wrapper { // TODO work-around so that the dropdowns can be shown, otherwise they get cut off. padding-bottom: 150px;