Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
50bb314
Sidebar: Remove DB icon
pzrq Jan 13, 2017
d1237e2
Sidebar: Move clickable arrow to left side
pzrq Jan 13, 2017
4961dc8
Add most new sidebar + and trash icons
pzrq Jan 14, 2017
c1b8b08
Add create/drop tooltips
pzrq Jan 16, 2017
94bf01b
Implement handleCreateDatabaseClick
pzrq Jan 16, 2017
88f5b84
Resolve import vs run time issue by using beforeEach
pzrq Jan 24, 2017
3b3dd3c
Fix failing enzyme tests by mocking the AppRegistry
pzrq Jan 24, 2017
de759b4
Implement handleCreateCollectionClick
pzrq Jan 16, 2017
e4a2fa5
Implement handleDropDBClick
pzrq Jan 16, 2017
fa4f415
Implement handleDropCollectionClick
pzrq Jan 16, 2017
8dc748b
Add CSS hacks to handle collapsible sidebar
pzrq Jan 23, 2017
2738322
Sidebar: Add Create Database button
pzrq Jan 23, 2017
3a8e9f5
switching home content on create database
Jan 24, 2017
17fa485
CreateDB: Reuse the NamespaceStore over HomeActions
pzrq Jan 24, 2017
39b3233
CreateCollection: Change to Collections list onCreateCollectionButton…
pzrq Jan 24, 2017
d015b3e
DropCollection: Change to Collections list onDropCollectionButtonClicked
pzrq Jan 24, 2017
259805a
DropDatabase: Change to Databases list onDropDatabaseButtonClicked
pzrq Jan 24, 2017
b20e12b
Update SidebarInstance tests to detect dataservice not writable
pzrq Jan 24, 2017
41c610e
Handle SidebarInstance isWritable
pzrq Jan 24, 2017
1d9a4c0
CreateDBButton: Add tooltip and handle secondaries/arbiters + tests
pzrq Jan 24, 2017
b71989d
DropCollectionIcon: Handle secondaries/arbiters + tests
pzrq Jan 24, 2017
5da030e
AddCollectionIcon & DropDatabaseIcon: Handle secondaries/arbiters + t…
pzrq Jan 24, 2017
2325d8d
Remove db/collection names from tooltips
pzrq Jan 25, 2017
5588c88
Only show Create Database Button tooltip when connected to a secondary
pzrq Jan 25, 2017
0c25d47
Add compass-sidebar-icon-is-disabled CSS classes for secondary tooltips
pzrq Jan 25, 2017
a6d0223
Add compass-sidebar-button-is-disabled CSS classes for secondary tool…
pzrq Jan 25, 2017
d1c0502
:shirt:
pzrq Jan 25, 2017
30cdf9b
Remove unnecessary tooltip CSS class
pzrq Jan 25, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const Modal = require('react-bootstrap').Modal;
const { TextButton } = require('hadron-react-buttons');
const Actions = require('../action');
const CreateDatabaseStore = require('../store/create-database-store');
const { NamespaceStore } = require('hadron-reflux-store');

/**
* The more information url.
Expand Down Expand Up @@ -88,6 +89,7 @@ class CreateDatabaseDialog extends React.Component {
this.state.capped,
this.state.maxSize
);
NamespaceStore.ns = '';
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const app = require('ampersand-app');
const React = require('react');
const Modal = require('react-bootstrap').Modal;
const { NamespaceStore } = require('hadron-reflux-store');
const { TextButton } = require('hadron-react-buttons');
const Actions = require('../action');
const DropDatabaseStore = require('../store/drop-database-store');
Expand Down Expand Up @@ -62,11 +63,13 @@ class DropDatabaseDialog extends React.Component {
evt.stopPropagation();

// prevent drop database if names don't match
if (this.state.confirmName !== this.state.name) {
const databaseName = this.state.name;
if (this.state.confirmName !== databaseName) {
return;
}
this.setState({ inProgress: true, error: false, errorMessage: '' });
Actions.dropDatabase(this.state.name);
Actions.dropDatabase(databaseName);
NamespaceStore.ns = '';
}

/**
Expand Down
3 changes: 3 additions & 0 deletions src/internal-packages/database/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const app = require('ampersand-app');
const CollectionsAction = require('./lib/actions/collections-actions');
const CollectionsTable = require('./lib/components');
const CreateCollectionCheckbox = require('./lib/components/create-collection-checkbox');
const CreateCollectionInput = require('./lib/components/create-collection-input');
Expand All @@ -10,6 +11,7 @@ const DropCollectionDialog = require('./lib/components/drop-collection-dialog');
* Activate all the components in the Schema package.
*/
function activate() {
app.appRegistry.registerAction('Database.CollectionsActions', CollectionsAction);
app.appRegistry.registerComponent('Database.CollectionsTable', CollectionsTable);
app.appRegistry.registerComponent('Database.CreateCollectionCheckbox', CreateCollectionCheckbox);
app.appRegistry.registerComponent('Database.CreateCollectionInput', CreateCollectionInput);
Expand All @@ -22,6 +24,7 @@ function activate() {
* Deactivate all the components in the Schema package.
*/
function deactivate() {
app.appRegistry.deregisterAction('Database.CollectionsActions');
app.appRegistry.deregisterComponent('Database.CollectionsTable');
app.appRegistry.deregisterComponent('Database.CreateCollectionCheckbox');
app.appRegistry.deregisterComponent('Database.CreateCollectionInput');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const app = require('ampersand-app');
const shell = require('electron').shell;
const React = require('react');
const Modal = require('react-bootstrap').Modal;
const { NamespaceStore } = require('hadron-reflux-store');
const { TextButton } = require('hadron-react-buttons');
const Actions = require('../actions/collections-actions');
const CreateCollectionStore = require('../stores/create-collection-store');
Expand Down Expand Up @@ -80,12 +81,14 @@ class CreateCollectionDialog extends React.Component {
evt.stopPropagation();

this.setState({ inProgress: true, error: false, errorMessage: '' });
const databaseName = this.state.databaseName;
Actions.createCollection(
this.state.databaseName,
databaseName,
this.state.collectionName,
this.state.capped,
this.state.maxSize
);
NamespaceStore.ns = databaseName;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const app = require('ampersand-app');
const React = require('react');
const Modal = require('react-bootstrap').Modal;
const { NamespaceStore } = require('hadron-reflux-store');
const { TextButton } = require('hadron-react-buttons');
const Actions = require('../actions/collections-actions');
const DropCollectionStore = require('../stores/drop-collection-store');
Expand Down Expand Up @@ -74,6 +75,7 @@ class DropCollectionDialog extends React.Component {

this.setState({ inProgress: true, error: false, errorMessage: '' });
Actions.dropCollection(this.state.databaseName, this.state.collectionName);
NamespaceStore.ns = this.state.databaseName;
}

/**
Expand Down
11 changes: 11 additions & 0 deletions src/internal-packages/sidebar/lib/components/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const TOOLTIP_IDS = Object.freeze({
CREATE_COLLECTION: 'create-collection',
CREATE_DATABASE_BUTTON: 'create-database-button',
CREATE_DATABASE_ICON: 'create-database-icon',
DROP_COLLECTION: 'drop-collection',
DROP_DATABASE: 'drop-database'
});

module.exports = {
TOOLTIP_IDS
};
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const app = require('ampersand-app');
const React = require('react');
const ReactTooltip = require('react-tooltip');
const ipc = require('hadron-ipc');

const { NamespaceStore } = require('hadron-reflux-store');

const { TOOLTIP_IDS } = require('./constants');

class SidebarCollection extends React.Component {
constructor() {
super();
this.state = {
active: false
};
this.handleClick = this.handleClick.bind(this);
this.CollectionsActions = app.appRegistry.getAction('Database.CollectionsActions');
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
}

Expand All @@ -28,6 +32,14 @@ class SidebarCollection extends React.Component {
}
}

handleDropCollectionClick(isWritable) {
if (isWritable) {
const databaseName = this.props.database;
const collectionName = this.getCollectionName();
this.CollectionsActions.openDropCollectionDialog(databaseName, collectionName);
}
}

renderReadonly() {
if (this.props.readonly) {
return (
Expand All @@ -38,15 +50,35 @@ class SidebarCollection extends React.Component {

render() {
const collectionName = this.getCollectionName();
let className = 'compass-sidebar-title compass-sidebar-title-is-actionable';
const isWritable = app.dataService.isWritable();
const tooltipText = isWritable ?
'Drop collection' :
'Drop collection is not available on a secondary node'; // TODO: Arbiter/recovering/etc
const tooltipOptions = {
'data-for': TOOLTIP_IDS.DROP_COLLECTION,
'data-effect': 'solid',
'data-offset': "{'bottom': 18, 'left': 3}",
'data-tip': tooltipText
};
let titleClassName = 'compass-sidebar-title compass-sidebar-title-is-actionable';
if (this.props.activeNamespace === this.props._id) {
className += ' compass-sidebar-title-is-active';
titleClassName += ' compass-sidebar-title-is-active';
}
let dropClassName = 'compass-sidebar-icon compass-sidebar-icon-drop-collection fa fa-trash-o';
if (!isWritable) {
dropClassName += ' compass-sidebar-icon-is-disabled';
}
return (
<div className="compass-sidebar-item">
<i
className={dropClassName}
onClick={this.handleDropCollectionClick.bind(this, isWritable)}
{...tooltipOptions}
/>
<ReactTooltip id={TOOLTIP_IDS.DROP_COLLECTION} />
<div
onClick={this.handleClick}
className={className}
className={titleClassName}
data-test-id="sidebar-collection"
title={this.props._id}>
{collectionName}&nbsp;
Expand Down
69 changes: 63 additions & 6 deletions src/internal-packages/sidebar/lib/components/sidebar-database.jsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const app = require('ampersand-app');
const ipc = require('hadron-ipc');
const React = require('react');
const SidebarCollection = require('./sidebar-collection');
const ReactTooltip = require('react-tooltip');
const { NamespaceStore } = require('hadron-reflux-store');
const toNS = require('mongodb-ns');

const { TOOLTIP_IDS } = require('./constants');
const SidebarCollection = require('./sidebar-collection');

class SidebarDatabase extends React.Component {
constructor(props) {
super(props);
this.state = { expanded: props.expanded };
this.CollectionsActions = app.appRegistry.getAction('Database.CollectionsActions');
this.DatabaseDDLActions = app.appRegistry.getAction('DatabaseDDL.Actions');
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
}

Expand Down Expand Up @@ -54,16 +59,68 @@ class SidebarDatabase extends React.Component {
this.setState({ expanded: !this.state.expanded });
}

handleCreateCollectionClick(isWritable) {
if (isWritable) {
const databaseName = this.props._id;
this.CollectionsActions.openCreateCollectionDialog(databaseName);
}
}

handleDropDBClick(isWritable) {
if (isWritable) {
const databaseName = this.props._id;
this.DatabaseDDLActions.openDropDatabaseDialog(databaseName);
}
}

render() {
let className = 'compass-sidebar-item-header compass-sidebar-item-header-is-expandable compass-sidebar-item-header-is-actionable';
const isWritable = app.dataService.isWritable();
const createTooltipText = isWritable ?
'Create collection' :
'Create collection is not available on a secondary node'; // TODO: Arbiter/recovering/etc
const createTooltipOptions = {
'data-for': TOOLTIP_IDS.CREATE_COLLECTION,
'data-effect': 'solid',
'data-offset': "{'bottom': 18, 'left': 3}",
'data-tip': createTooltipText
};
const dropTooltipText = isWritable ?
'Drop database' :
'Drop database is not available on a secondary node'; // TODO: Arbiter/recovering/etc
const dropTooltipOptions = {
'data-for': TOOLTIP_IDS.DROP_DATABASE,
'data-effect': 'solid',
'data-offset': "{'bottom': 18, 'left': 3}",
'data-tip': dropTooltipText
};
let headerClassName = 'compass-sidebar-item-header compass-sidebar-item-header-is-expandable compass-sidebar-item-header-is-actionable';
if (this.props.activeNamespace === this.props._id) {
className += ' compass-sidebar-item-header-is-active';
headerClassName += ' compass-sidebar-item-header-is-active';
}
let createClassName = 'compass-sidebar-icon compass-sidebar-icon-create-collection fa fa-plus-circle';
if (!isWritable) {
createClassName += ' compass-sidebar-icon-is-disabled';
}
let dropClassName = 'compass-sidebar-icon compass-sidebar-icon-drop-database fa fa-trash-o';
if (!isWritable) {
dropClassName += ' compass-sidebar-icon-is-disabled';
}
return (
<div className="compass-sidebar-item compass-sidebar-item-is-top-level">
<div className={className}>
<i onClick={this.handleDBClick.bind(this, this.props._id)} className="compass-sidebar-database-icon mms-icon-database"></i>
<i onClick={this.handleArrowClick.bind(this)} className={this.getArrowIconClasses()}></i>
<div className={headerClassName}>
<i onClick={this.handleArrowClick.bind(this)} className={this.getArrowIconClasses()} />
<i
className={createClassName}
onClick={this.handleCreateCollectionClick.bind(this, isWritable)}
{...createTooltipOptions}
/>
<ReactTooltip id={TOOLTIP_IDS.CREATE_COLLECTION} />
<i
className={dropClassName}
onClick={this.handleDropDBClick.bind(this, isWritable)}
{...dropTooltipOptions}
/>
<ReactTooltip id={TOOLTIP_IDS.DROP_DATABASE} />
<div
onClick={this.handleDBClick.bind(this, this.props._id)}
className="compass-sidebar-title" title={this.props._id}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
const React = require('react');
const ReactTooltip = require('react-tooltip');
const app = require('ampersand-app');
const ipc = require('hadron-ipc');
const { NamespaceStore } = require('hadron-reflux-store');
const { TOOLTIP_IDS } = require('./constants');

class SidebarInstanceProperties extends React.Component {
constructor(props) {
super(props);
this.DatabaseDDLActions = app.appRegistry.getAction('DatabaseDDL.Actions');
}

getHostnameAndPort() {
const connection = this.props.connection;
if (!connection.hostname) {
Expand Down Expand Up @@ -53,22 +60,49 @@ class SidebarInstanceProperties extends React.Component {
ipc.call('window:hide-collection-submenu');
}

handleCreateDatabaseClick(isWritable) {
if (isWritable) {
this.DatabaseDDLActions.openCreateDatabaseDialog();
}
}

render() {
const instance = this.props.instance;
const isWritable = app.dataService.isWritable();
const numDbs = instance.databases.length;
const numCollections = instance.collections.length;
const hostnameAndPort = this.getHostnameAndPort();
const sshTunnelViaPort = this.getSshTunnelViaPort();
const versionName = this.getVersionName();
let className = 'compass-sidebar-instance';
const tooltipText = isWritable ?
'Create database' :
'Create database is not available on a secondary node'; // TODO: Arbiter/recovering/etc
const tooltipOptions = {
'data-for': TOOLTIP_IDS.CREATE_DATABASE_ICON,
'data-effect': 'solid',
'data-place': 'right',
'data-offset': "{'top': 1, 'left': 18}",
'data-tip': tooltipText
};
let instanceClassName = 'compass-sidebar-instance';
// empty string for active namespace means instance level
if (this.props.activeNamespace === '') {
className += ' compass-sidebar-instance-is-active';
instanceClassName += ' compass-sidebar-instance-is-active';
}
let createClassName = 'compass-sidebar-icon compass-sidebar-icon-create-database fa fa-plus-circle';
if (!isWritable) {
createClassName += ' compass-sidebar-icon-is-disabled';
}
return (
<div className="compass-sidebar-properties">
<div className={className} onClick={this.handleClickHostname}>
<i className="fa fa-home compass-sidebar-instance-icon"></i>
<div className={instanceClassName} onClick={this.handleClickHostname}>
<i className="fa fa-home compass-sidebar-instance-icon" />
<i
className={createClassName}
onClick={this.handleCreateDatabaseClick.bind(this, isWritable)}
{...tooltipOptions}
/>
<ReactTooltip id={TOOLTIP_IDS.CREATE_DATABASE_ICON} />
<div
data-test-id="sidebar-instance-details"
className="compass-sidebar-instance-hostname">
Expand Down
Loading