diff --git a/src/app/home/collection-list-item.js b/src/app/home/collection-list-item.js deleted file mode 100644 index 67f554d3f92..00000000000 --- a/src/app/home/collection-list-item.js +++ /dev/null @@ -1,39 +0,0 @@ -var ListItemView = require('../sidebar/list').ListItemView; -var toNS = require('mongodb-ns'); -var _ = require('lodash'); -// var debug = require('debug')('mongodb-compass:sidebar:collection-list-item'); - -var CollectionListItemView = ListItemView.extend({ - props: { - displayProp: ['string', true, 'name'] - }, - bindings: _.extend({}, ListItemView.prototype.bindings, { - is_special: { - type: 'booleanClass', - name: 'special' - } - }), - derived: { - is_special: { - deps: ['model._id'], - fn: function() { - if (!this.model._id) { - return false; - } - return toNS(this.model._id).specialish; - } - }, - title: { - deps: ['model._id', 'is_special'], - fn: function() { - var title = this.model._id; - if (this.is_special) { - title += ' (internal collection)'; - } - return title; - } - } - } -}); - -module.exports = CollectionListItemView; diff --git a/src/app/home/collection.jade b/src/app/home/collection.jade deleted file mode 100644 index 230964426cc..00000000000 --- a/src/app/home/collection.jade +++ /dev/null @@ -1,27 +0,0 @@ -.collection-view.clearfix - header - .row - .col-md-6 - h1(data-hook='collection-name') - .col-md-6 - div(data-hook='stats-subview') - .row - ul.nav.nav-tabs(role='tablist') - li(role='presentation', data-hook='schema-tab', id='schema-tab') - a Schema - li(role='presentation', data-hook='document-tab', id='document-tab') - a Documents - li(role='presentation', data-hook='explain-tab', id='explain-tab') - a Explain Plan - li(role='presentation', data-hook='index-tab', id='index-tab') - a Indexes - li(role='presentation', data-hook='validation-tab', id='validation-tab') - a Validation - .row - div(data-hook='refine-bar-subview') - - div(data-hook='document-subview') - div(data-hook='schema-subview') - div(data-hook='explain-subview') - div(data-hook='index-subview' class='index-container') - div(data-hook='validation-subview') diff --git a/src/app/home/collection.js b/src/app/home/collection.js deleted file mode 100644 index 66c1b0be153..00000000000 --- a/src/app/home/collection.js +++ /dev/null @@ -1,233 +0,0 @@ -var View = require('ampersand-view'); -var Action = require('hadron-action'); -var MongoDBCollection = require('../models/mongodb-collection'); -var React = require('react'); -var ReactDOM = require('react-dom'); -var NamespaceStore = require('hadron-reflux-store').NamespaceStore; -var toNS = require('mongodb-ns'); -var _ = require('lodash'); - -var app = require('ampersand-app'); -var metrics = require('mongodb-js-metrics')(); -var debug = require('debug')('mongodb-compass:home:collection'); - -var collectionTemplate = require('./collection.jade'); - -// map tab label to correct view and switch views -var tabToViewMap = { - 'DOCUMENTS': 'documentView', - 'SCHEMA': 'schemaView', - 'EXPLAIN PLAN': 'explainView', - 'INDEXES': 'indexView', - 'VALIDATION': 'validationView' -}; - -/** - * Ampersand view wrapper around a React component tab view - */ -var TabView = View.extend({ - template: '
', - props: { - componentKey: 'string', - visible: { - type: 'boolean', - required: true, - default: false - } - }, - bindings: { - visible: { - type: 'booleanClass', - no: 'hidden' - } - }, - render: function() { - this.renderWithTemplate(); - var tabComponent = app.appRegistry.getComponent(this.componentKey); - ReactDOM.render(React.createElement(tabComponent), this.query()); - } -}); - - -var MongoDBCollectionView = View.extend({ - // modelType: 'Collection', - template: collectionTemplate, - props: { - visible: { - type: 'boolean', - default: false - }, - viewSwitcher: 'object', - activeView: { - type: 'string', - required: true, - default: 'schemaView', - values: ['documentView', 'schemaView', 'explainView', 'indexView', 'validationView'] - }, - ns: 'string' - }, - events: { - 'click ul.nav li a': 'onTabClicked' - }, - bindings: { - visible: { - type: 'booleanClass', - no: 'hidden' - }, - 'model._id': { - hook: 'collection-name' - }, - activeView: { - type: 'switchClass', - 'name': 'active', - cases: { - 'documentView': '[data-hook=document-tab]', - 'schemaView': '[data-hook=schema-tab]', - 'explainView': '[data-hook=explain-tab]', - 'indexView': '[data-hook=index-tab]', - 'validationView': '[data-hook=validation-tab]' - } - } - }, - subviews: { - statsView: { - hook: 'stats-subview', - waitFor: 'ns', - prepareView: function(el) { - return new TabView({ - el: el, - parent: this, - visible: true, - componentKey: 'CollectionStats.CollectionStats' - }); - } - }, - documentView: { - hook: 'document-subview', - waitFor: 'ns', - prepareView: function(el) { - return new TabView({ - el: el, - parent: this, - componentKey: 'CRUD.DocumentList' - }); - } - }, - schemaView: { - hook: 'schema-subview', - waitFor: 'ns', - prepareView: function(el) { - return new TabView({ - el: el, - parent: this, - componentKey: 'Schema.Schema' - }); - } - }, - indexView: { - hook: 'index-subview', - waitFor: 'ns', - prepareView: function(el) { - return new TabView({ - el: el, - parent: this, - componentKey: 'Indexes.Indexes' - }); - } - }, - explainView: { - hook: 'explain-subview', - waitFor: 'ns', - prepareView: function(el) { - return new TabView({ - el: el, - parent: this, - componentKey: 'Explain.ExplainPlan' - }); - } - }, - validationView: { - hook: 'validation-subview', - waitFor: 'ns', - prepareView: function(el) { - return new TabView({ - el: el, - parent: this, - componentKey: 'Validation.Validation' - }); - } - } - }, - initialize: function() { - this.model = new MongoDBCollection(); - NamespaceStore.listen(this.onCollectionChanged.bind(this)); - this.loadIndexesAction = app.appRegistry.getAction('Indexes.LoadIndexes'); - this.fetchExplainPlanAction = app.appRegistry.getAction('Explain.Actions').fetchExplainPlan; - this.schemaActions = app.appRegistry.getAction('Schema.Actions'); - this.validationActions = app.appRegistry.getAction('Validation.Actions'); - // this.listenToAndRun(this.parent, 'change:ns', this.onCollectionChanged.bind(this)); - }, - render: function() { - this.renderWithTemplate(this); - // render query bar here for now - var queryBarComponent = app.appRegistry.getComponent('Query.QueryBar'); - ReactDOM.render(React.createElement(queryBarComponent), this.queryByHook('refine-bar-subview')); - }, - onTabClicked: function(e) { - e.preventDefault(); - e.stopPropagation(); - this.switchView(tabToViewMap[e.target.innerText]); - }, - switchView: function(viewStr) { - debug('switching to', viewStr); - // disable all views but the active one - this.activeView = viewStr; - _.each(_.values(tabToViewMap), function(subview) { - if (!this[subview]) return; - if (subview === viewStr) { - this[viewStr].el.classList.remove('hidden'); - } else { - this[subview].el.classList.add('hidden'); - } - }.bind(this)); - // Temporary hack to generate a resize when the schema is clicked. - if (viewStr === 'schemaView') { - this.schemaActions.resizeMiniCharts(); - } - }, - onCollectionChanged: function(ns) { - if (ns === this.ns) { - return; - } - this.ns = ns; - if (!ns || !toNS(ns || '').collection) { - this.visible = false; - debug('No active collection namespace so no schema has been requested yet.'); - return; - } - this.visible = true; - this.model._id = this.ns; - // this.model.once('sync', this.onCollectionFetched.bind(this)); - // this.model.fetch(); - Action.filterChanged.listen(() => { - this.loadIndexesAction(); - this.fetchExplainPlanAction(); - }); - Action.filterChanged(app.queryOptions.query); - this.switchView(this.activeView); - }, - onCollectionFetched: function(model) { - // track collection information - // @todo: Durran: We need to move these metrics into the namespace store - // or the collection store as this is no longer called. - var metadata = _.omit(model.serialize(), ['_id', 'database', - 'index_details', 'wired_tiger']); - metadata.specialish = model.specialish; - metadata['database name length'] = model.database.length; - metadata['collection name length'] = model.getId().length - - model.database.length - 1; - metrics.track('Collection', 'fetched', metadata); - } -}); - -module.exports = MongoDBCollectionView; diff --git a/src/app/home/index.jade b/src/app/home/index.jade index 21c5bad5f7e..ef967cef2a4 100644 --- a/src/app/home/index.jade +++ b/src/app/home/index.jade @@ -1,6 +1,6 @@ .page .content.with-sidebar - div(data-hook='collection-subview') + div(data-hook='collection-view') div.report-zero-state(data-hook='report-zero-state') div.state-arrow img(src='images/zero-state-arrow-collections.png', width="110") diff --git a/src/app/home/index.js b/src/app/home/index.js index b5a9abc8c2d..2bda70de1ae 100644 --- a/src/app/home/index.js +++ b/src/app/home/index.js @@ -1,7 +1,6 @@ var View = require('ampersand-view'); // var format = require('util').format; // var IdentifyView = require('../identify'); -var CollectionView = require('./collection'); var { NamespaceStore } = require('hadron-reflux-store'); var TourView = require('../tour'); var NetworkOptInView = require('../network-optin'); @@ -16,6 +15,32 @@ var ReactDOM = require('react-dom'); var indexTemplate = require('./index.jade'); +/** + * Ampersand view wrapper around a React component tab view + */ +var WrapperView = View.extend({ + template: '', + props: { + componentKey: 'string', + visible: { + type: 'boolean', + required: true, + default: false + } + }, + bindings: { + visible: { + type: 'booleanClass', + no: 'hidden' + } + }, + render: function() { + this.renderWithTemplate(); + var component = app.appRegistry.getComponent(this.componentKey); + ReactDOM.render(React.createElement(component), this.query()); + } +}); + var HomeView = View.extend({ screenName: 'Schema', props: { @@ -184,27 +209,6 @@ var HomeView = View.extend({ return database.collections.get(ns.ns); }, - // onNamespaceChange: function(ns) { - // const model = this._getCollection(); - // - // // if (!model) { - // // app.navigate('/'); - // // return; - // // } - // - // const collection = app.instance.collections; - // if (!collection.select(model)) { - // return debug('already selected %s', model); - // } - // - // this.updateTitle(model); - // this.showNoCollectionsZeroState = false; - // this.showDefaultZeroState = false; - // - // // app.navigate(format('schema/%s', model.getId()), { - // // silent: true - // // }); - // }, onClickShowConnectWindow: function() { // code to close current connection window and open connect dialog ipc.call('app:show-connect-window'); @@ -212,12 +216,14 @@ var HomeView = View.extend({ }, template: indexTemplate, subviews: { - _collection: { - hook: 'collection-subview', + collectionView: { + hook: 'collection-view', prepareView: function(el) { - return new CollectionView({ + return new WrapperView({ el: el, - parent: this + parent: this, + visible: true, + componentKey: 'Collection.Collection' }); } } diff --git a/src/app/home/index.less b/src/app/home/index.less index b4533cda38f..5a8bfcf6ba5 100644 --- a/src/app/home/index.less +++ b/src/app/home/index.less @@ -63,6 +63,7 @@ position: fixed; z-index: 4; background: @pw; + width: ~"calc(100% - 250px)"; .row { margin-left: 0; margin-right: 0; @@ -93,7 +94,7 @@ } .header-margin { - margin-top: 154px; // size of header + margin-top: 60px; // size of header } .column { diff --git a/src/internal-packages/app/lib/components/tab-nav-bar.jsx b/src/internal-packages/app/lib/components/tab-nav-bar.jsx index 4f0047d0d9d..3cb7205c347 100644 --- a/src/internal-packages/app/lib/components/tab-nav-bar.jsx +++ b/src/internal-packages/app/lib/components/tab-nav-bar.jsx @@ -8,7 +8,7 @@ class NavBarComponent extends React.Component { super(props); this.state = { paused: false, - activeTabIndex: 0 + activeTabIndex: props.activeTabIndex || 0 }; } @@ -30,7 +30,11 @@ class NavBarComponent extends React.Component { renderTabs() { const listItems = _.map(this.props.tabs, (tab, idx) => ( -