Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -8,7 +8,10 @@ import { SortableTable } from 'hadron-react-components';
import dropCollectionStore from '../../../stores/drop-collection';
import styles from './collections-table.less';
import CollectionProperties from './collection-properties';

import {
TIME_SERIES_COLLECTION_TYPE,
VIEW_COLLECTION_TYPE
} from '../../../modules/collections/collections';

/**
* The name constant.
Expand Down Expand Up @@ -56,7 +59,6 @@ class CollectionsTable extends PureComponent {
columns: PropTypes.array.isRequired,
collections: PropTypes.array.isRequired,
isWritable: PropTypes.bool.isRequired,
isReadonly: PropTypes.bool.isRequired,
openLink: PropTypes.func.isRequired,
open: PropTypes.func.isRequired,
databaseName: PropTypes.string,
Expand Down Expand Up @@ -132,7 +134,11 @@ class CollectionsTable extends PureComponent {
const linkName = this.renderLink(coll);
return assign({}, coll, {
[NAME]: linkName,
[DOCUMENTS]: isNaN(coll.Documents) ? DASH : numeral(coll.Documents).format('0,0'),
[DOCUMENTS]: (
coll.type === TIME_SERIES_COLLECTION_TYPE ||
coll.type === VIEW_COLLECTION_TYPE ||
isNaN(coll.Documents)
) ? DASH : numeral(coll.Documents).format('0,0'),
[AVG_DOC_SIZE]: isNaN(coll[AVG_DOC_SIZE]) ?
DASH : numeral(coll[AVG_DOC_SIZE]).format('0.0 b'),
[TOT_DOC_SIZE]: isNaN(coll[TOT_DOC_SIZE]) ?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { mount } from 'enzyme';
import { SortableTable } from 'hadron-react-components';

import { INITIAL_STATE as COLUMNS } from '../../../modules/collections/columns';
import CollectionsTable from '../collections-table';
Expand All @@ -14,16 +15,15 @@ describe('CollectionsTable [Component]', () => {
let openLinkSpy;
let remount;

const basicCollection = {
_id: 'data-service.myView',
readonly: false,
type: 'collection',
Documents: 5
};

beforeEach(() => {
collections = [
{
_id: 'data-service.myView',
readonly: true,
type: 'view',
view_on: 'test',
pipeline: [{$project: {a: 1}}]
}
];
collections = [basicCollection];

openSpy = sinon.spy();
sortCollectionsSpy = sinon.spy();
Expand Down Expand Up @@ -64,17 +64,50 @@ describe('CollectionsTable [Component]', () => {
expect(component.find('.main')).to.be.present();
});

it('passes the document count', () => {
expect(component.find(SortableTable).props().rows[0].Documents).to.equal('5');
});

it('does not render the viewOn', () => {
for (const coll of collections) {
coll.view_on = undefined;
}
remount();
expect(component.find(`.${styles['collections-table-view-on']}`)).to.not.be.present();
});

describe('Views', () => {
beforeEach(() => {
collections = [{
...basicCollection,
readonly: true,
type: 'view',
view_on: 'test',
pipeline: [{$project: {a: 1}}]
}];
remount();
});

it('renders the viewOn', () => {
expect(component.find(`.${styles['collections-table-view-on']}`)).to.be.present();
});

it('does not render the viewOn when not a view', () => {
for (const coll of collections) {
coll.view_on = undefined;
}
it('passes the document count -', () => {
expect(component.find(SortableTable).props().rows[0].Documents).to.equal('-');
});
});

describe('time-series collections', () => {
beforeEach(() => {
collections = [{
...basicCollection,
type: 'timeseries'
}];
remount();
expect(component.find(`.${styles['collections-table-view-on']}`)).to.not.be.present();
});

it('passes the document count -', () => {
expect(component.find(SortableTable).props().rows[0].Documents).to.equal('-');
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { isEmpty } from 'lodash';
import { INITIAL_STATE as COLUMNS } from './columns';
import { UPDATE_SORT } from '../sort';

export const TIME_SERIES_COLLECTION_TYPE = 'timeseries';
export const VIEW_COLLECTION_TYPE = 'view';

/**
* Need extra columns to map.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import find from 'lodash.find';
import toNS from 'mongodb-ns';

import { TIME_SERIES_COLLECTION_TYPE } from '../../../compass-sidebar/src/modules/collection';
import { TIME_SERIES_COLLECTION_TYPE } from './collections/collections';
import { appRegistryEmit } from './app-registry';

/**
Expand Down