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
@@ -0,0 +1,48 @@

import React from 'react';
import PropTypes from 'prop-types';
import Icon from '@leafygreen-ui/icon';

import { TIME_SERIES_COLLECTION_TYPE } from '../../modules/collection';

import styles from './collection-type-icon.less';

const VIEW_COLLECTION_TYPE = 'view';

function CollectionTypeIcon({
collectionType
}) {
if (collectionType === TIME_SERIES_COLLECTION_TYPE) {
return (
<Icon
className={styles['compass-sidebar-collection-type-icon']}
glyph="TimeSeries"
title="Time-Series Collection"
/>
);
}

if (collectionType === VIEW_COLLECTION_TYPE) {
return (
<Icon
className={styles['compass-sidebar-collection-type-icon']}
glyph="Visibility"
title="Read-only View"
/>
);
}

return (
<Icon
className={styles['compass-sidebar-collection-type-icon']}
glyph="Folder"
title="Collection"
/>
);
}

CollectionTypeIcon.propTypes = {
collectionType: PropTypes.string.isRequired
};

export default CollectionTypeIcon;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.compass-sidebar-collection-type-icon {
vertical-align: sub;
margin-right: 8px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import { mount } from 'enzyme';
import Icon from '@leafygreen-ui/icon';

import CollectionTypeIcon from '../collection-type-icon';

describe('CollectionTypeIcon [Component]', () => {
let component;

describe('default collection type', () => {
beforeEach(() => {
component = mount(<CollectionTypeIcon
collectionType="collection"
/>);
});

it('has a collection type icon folder', () => {
expect(component.find(Icon).props().glyph).to.equal('Folder');
});
});

describe('time-series collection type', () => {
beforeEach(() => {
component = mount(<CollectionTypeIcon
collectionType="timeseries"
/>);
});

it('has a time series icon', () => {
expect(component.find(Icon).props().glyph).to.equal('TimeSeries');
});
});

describe('view collection type', () => {
beforeEach(() => {
component = mount(<CollectionTypeIcon
collectionType="view"
/>);
});

it('has a view icon', () => {
expect(component.find(Icon).props().glyph).to.equal('Visibility');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import ColletionTypeIcon from './collection-type-icon';
export default ColletionTypeIcon;
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import classnames from 'classnames';
import PropTypes from 'prop-types';
import { DropdownButton, MenuItem } from 'react-bootstrap';
import toNS from 'mongodb-ns';
import Icon from '@leafygreen-ui/icon';

import { collectionMetadata, getSource, TIME_SERIES_COLLECTION_TYPE } from '../../modules/collection';
import { collectionMetadata, getSource } from '../../modules/collection';
import CollectionTypeIcon from '../collection-type-icon';

import styles from './sidebar-collection.less';

const DEFAULT_COLLECTION_TYPE = 'collection';

class SidebarCollection extends PureComponent {
static displayName = 'SidebarCollection';
static propTypes = {
Expand Down Expand Up @@ -138,41 +136,6 @@ class SidebarCollection extends PureComponent {
}
}

renderCollectionIcon() {
return (
<Icon
className={styles['compass-sidebar-collection-type-icon']}
glyph="Folder"
title="Collection"
/>
);
}

/**
* Render the readonly icon.
*
* @returns {Component} The component.
*/
renderViewIcon() {
return (
<Icon
className={styles['compass-sidebar-collection-type-icon']}
glyph="Visibility"
title="Read-only View"
/>
);
}

renderTimeSeriesIcon() {
return (
<Icon
className={styles['compass-sidebar-collection-type-icon']}
glyph="TimeSeries"
title="Time-Series Collection"
/>
);
}

/**
* Render the view contextual menu.
*
Expand Down Expand Up @@ -241,9 +204,9 @@ class SidebarCollection extends PureComponent {
data-test-id="sidebar-collection"
title={this.props._id}
>
{this.props.type === DEFAULT_COLLECTION_TYPE && this.renderCollectionIcon()}
{this.props.readonly && this.renderViewIcon()}
{this.props.type === TIME_SERIES_COLLECTION_TYPE && this.renderTimeSeriesIcon()}
<CollectionTypeIcon
collectionType={this.props.type}
/>
{collectionName}
</div>
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@
}
}

.compass-sidebar-collection-type-icon {
vertical-align: sub;
margin-right: 8px;
}

.compass-sidebar-item {
display: flex;
flex-wrap: nowrap;
Expand Down