Skip to content

Commit

Permalink
COMPASS-584 hide system.* collections from table + refactoring (#714)
Browse files Browse the repository at this point in the history
* COMPASS-584 add a clickable prop to enable or disable links in sortable table

* COMPASS-584 make table more generic, pass links as cells

* removed unused clickable

* removing system collections from collections table

* move system collection filtering to store + cleanup

* remove unnecessary null check for collection name.
  • Loading branch information
Satya committed Dec 28, 2016
1 parent af234ae commit b9595dc
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 54 deletions.
30 changes: 10 additions & 20 deletions src/internal-packages/app/lib/components/sortable-table.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const FontAwesome = require('react-fontawesome');
const Button = require('react-bootstrap').Button;
const _ = require('lodash');

// const debug = require('debug')('mongodb-compass:app:sortable-table');
/**
* The base for the classes.
*/
Expand All @@ -28,13 +29,6 @@ class SortableTable extends React.Component {
}
}

onNameClicked(idx, name, evt) {
evt.preventDefault();
if (this.props.onNameClicked) {
this.props.onNameClicked(idx, name);
}
}

/**
* compares either a column index (number) or a column name (string) with
* another column name and returns whether they are a match. This abstraction
Expand Down Expand Up @@ -93,30 +87,30 @@ class SortableTable extends React.Component {
row = row.slice(0, this.props.columns.length);
}
const cells = _.map(row, (cell, c) => {
const title = _.isString(cell) ? cell : _.get(cell, 'props.children', '');
return (
<td
className={`${BASE}-td`}
data-test-id={`${BASE}-column-${c}`}
title={cell}
title={title}
key={`td-${c}`}>
{c === 0 ?
<a className={`${BASE}-row-name`} onClick={this.onNameClicked.bind(this, r, cell)}>{cell}</a> : cell
}
{cell}
</td>
);
});
if (this.props.removable) {
// add a column with a delete button if the `removable` prop was set
const name = _.get(row, this.props.valueIndex, 0);
const valueCell = row[this.props.valueIndex];
const valueStr = _.isString(valueCell) ? valueCell : _.get(valueCell, 'props.children', '');
cells.push(
<td
className={`${BASE}-td`}
key="td-delete"
data-test-id={`${BASE}-delete`}
title={`Delete ${name}`}>
title={`Delete ${valueStr}`}>
<Button
className={`${BASE}-trash-button`}
onClick={this.onRowDeleteButtonClicked.bind(this, r, name)} >
onClick={this.onRowDeleteButtonClicked.bind(this, r, valueStr)} >
<FontAwesome className={`${BASE}-trash-icon`} name="trash-o" />
</Button>
</td>
Expand Down Expand Up @@ -198,11 +192,6 @@ SortableTable.propTypes = {
* @type {Function}
*/
onRowDeleteButtonClicked: React.PropTypes.func,
/**
* callback when user clicks on the name (first row element)
* @type {Function}
*/
onNameClicked: React.PropTypes.func,
/**
* The index in the columns to pass as a second value to the delete function.
* @type {Number}
Expand All @@ -216,7 +205,8 @@ SortableTable.defaultProps = {
sortable: true,
sortColumn: 0,
sortOrder: 'asc',
removable: false
removable: false,
valueIndex: 0
};

SortableTable.displayName = 'SortableTable';
Expand Down
4 changes: 0 additions & 4 deletions src/internal-packages/app/styles/sortable-table.less
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@
background-color: transparent;
}

.sortable-table-row-name {
text-decoration: none;
}

&-td {
border-bottom: 3px solid @gray8;
padding: 13px 0 13px 24px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const { TextButton } = require('hadron-react-buttons');
const numeral = require('numeral');
const ipc = require('hadron-ipc');

// const debug = require('debug')('mongodb-compass:database:collections-table');

const _ = require('lodash');

class CollectionsTable extends React.Component {
Expand All @@ -29,16 +31,27 @@ class CollectionsTable extends React.Component {
CollectionsActions.openCreateCollectionDialog();
}

onNameClicked(index, name) {
onNameClicked(name) {
// retrieve collection based on name
const collection = _.first(_.filter(this.props.collections, '_id', `${this.props.database}.${name}`));
this.CollectionStore.setCollection(collection);
ipc.call('window:show-collection-submenu');
}

renderLink(coll) {
const collName = coll['Collection Name'];
return (
<a className="collections-table-link" href="#" onClick={this.onNameClicked.bind(this, collName)}>{collName}</a>
);
}

render() {
const rows = _.map(this.props.renderedCollections, (coll) => {
const linkName = this.renderLink(coll);

// return formatted table row
return _.assign({}, coll, {
'Collection Name': linkName,
'Documents': numeral(coll.Documents).format('0,0'),
'Avg. Document Size': _.isNaN(coll['Avg. Document Size']) ?
'-' : numeral(coll['Avg. Document Size']).format('0.0 b'),
Expand Down Expand Up @@ -69,7 +82,6 @@ class CollectionsTable extends React.Component {
valueIndex={0}
removable={writable}
onColumnHeaderClicked={this.onColumnHeaderClicked.bind(this)}
onNameClicked={this.onNameClicked.bind(this)}
onRowDeleteButtonClicked={this.onRowDeleteButtonClicked.bind(this)}
/>
<CreateCollectionDialog />
Expand Down
30 changes: 19 additions & 11 deletions src/internal-packages/database/lib/stores/collections-store.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const Reflux = require('reflux');
const StateMixin = require('reflux-state-mixin');
const CollectionsActions = require('../actions/collections-actions');
const toNS = require('mongodb-ns');
const app = require('ampersand-app');
const _ = require('lodash');

Expand Down Expand Up @@ -78,17 +79,24 @@ const CollectionsStore = Reflux.createStore({
});
return;
}
const unsorted = _.map(res.collections, (coll) => {
return _.zipObject(COLL_COLUMNS, [
coll.name, // Collection Name
coll.document_count, // Num. Documents
coll.size / coll.document_count, // Avg. Document Size
coll.size, // Total Document Size
coll.index_count, // Num Indexes
coll.index_size // Total Index Size
]);
});

const unsorted = _(res.collections)
.filter((coll) => {
// skip system collections
const ns = toNS(coll.ns);
return !ns.system;
})
.map((coll) => {
// re-format for table view
return _.zipObject(COLL_COLUMNS, [
coll.name, // Collection Name
coll.document_count, // Num. Documents
coll.size / coll.document_count, // Avg. Document Size
coll.size, // Total Document Size
coll.index_count, // Num Indexes
coll.index_size // Total Index Size
]);
})
.value();
this.setState({
collections: database.collections,
renderedCollections: this._sort(unsorted),
Expand Down
17 changes: 17 additions & 0 deletions src/internal-packages/database/styles/collections-table.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.collections-table {
background-color: @gray8;
overflow-y: scroll;
padding: 0 20px 100px 20px;
position: absolute;
top: 78px;
right: 0;
bottom: 0;
left: 250px;

&-link, &-link:hover, &-link:active {
text-decoration: none;
}

&-create-button {
}
}
16 changes: 1 addition & 15 deletions src/internal-packages/database/styles/index.less
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
@import './drop-collection-dialog.less';
@import './collections-table.less';

.collections {

.tab-nav-bar-header {
top: 0;
}
}

.collections-table {
background-color: @gray8;
overflow-y: scroll;
padding: 0 20px 100px 20px;
position: absolute;
top: 78px;
right: 0;
bottom: 0;
left: 250px;

&-create-button {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class DatabasesTable extends React.Component {
shell.openExternal(AUTH_HELP_URL);
}

onNameClicked(index, name) {
onNameClicked(name) {
if (NamespaceStore.ns !== name) {
this.CollectionStore.setCollection({});
NamespaceStore.ns = name;
Expand Down Expand Up @@ -78,7 +78,9 @@ class DatabasesTable extends React.Component {
// convert storage size to human-readable units (MB, GB, ...)
// we do this here so that sorting is not affected in the store
const rows = _.map(this.props.databases, (db) => {
const dbName = db['Database Name'];
return _.assign({}, db, {
'Database Name': <a className="rtss-databases-link" href="#" onClick={this.onNameClicked.bind(this, dbName)}>{dbName}</a>,
'Storage Size': numeral(db['Storage Size']).format('0.0b')
});
});
Expand All @@ -105,7 +107,6 @@ class DatabasesTable extends React.Component {
valueIndex={0}
removable={writable}
onColumnHeaderClicked={this.onColumnHeaderClicked.bind(this)}
onNameClicked={this.onNameClicked.bind(this)}
onRowDeleteButtonClicked={this.onRowDeleteButtonClicked.bind(this)}
/>
{this.props.databases.length === 0 ?
Expand Down
4 changes: 4 additions & 0 deletions src/internal-packages/server-stats/styles/rtss-databases.less
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
bottom: 0;
left: 250px;

&-link, &-link:hover, &-link:active {
text-decoration: none;
}

&-create-button {
height: 32px;
background: @gray8;
Expand Down

0 comments on commit b9595dc

Please sign in to comment.