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 @@ -171,7 +171,7 @@ export const createView = () => {
isReadonly: true,
sourceName: viewSource,
editViewName: null,
isSourceReadonly: state.isReadonly,
sourceReadonly: state.isReadonly,
sourceViewOn: state.sourceName,
sourcePipeline: viewPipeline
}
Expand Down
2 changes: 1 addition & 1 deletion packages/compass-aggregations/src/modules/update-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const updateView = () => {
isReadonly: true,
sourceName: state.namespace,
editViewName: null,
isSourceReadonly: state.isReadonly,
sourceReadonly: state.isReadonly,
sourceViewOn: state.sourceName,
sourcePipeline: viewPipeline
};
Expand Down
6 changes: 3 additions & 3 deletions packages/compass-collection/electron/renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ dataService.connect((error, ds) => {
isReadonly: false,
sourceName: null,
editViewName: null,
isSourceReadonly: false,
sourceReadonly: false,
sourceViewOn: null
}
);
Expand All @@ -113,7 +113,7 @@ dataService.connect((error, ds) => {
isReadonly: true,
sourceName: 'citibike.trips',
editViewName: null,
isSourceReadonly: false,
sourceReadonly: false,
sourceViewOn: null,
sourcePipeline: [{ '$match': { name: 'testing' }}]
}
Expand All @@ -125,7 +125,7 @@ dataService.connect((error, ds) => {
isReadonly: true,
sourceName: 'citibike.tripsOfShortDuration',
editViewName: null,
isSourceReadonly: true,
sourceReadonly: true,
sourceViewOn: 'citibike.trips',
sourcePipeline: [{ '$match': { gender: 0 }}]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class CollectionHeader extends Component {
globalAppRegistry: PropTypes.func.isRequired,
namespace: PropTypes.string.isRequired,
isReadonly: PropTypes.bool.isRequired,
isTimeSeries: PropTypes.bool.isRequired,
statsPlugin: PropTypes.func.isRequired,
selectOrCreateTab: PropTypes.func.isRequired,
statsStore: PropTypes.object.isRequired,
Expand All @@ -24,27 +25,29 @@ class CollectionHeader extends Component {
};

modifySource = () => {
this.props.selectOrCreateTab(
this.props.sourceName,
this.props.sourceReadonly,
this.props.sourceViewOn,
this.props.namespace,
false,
null,
this.props.pipeline
);
this.props.selectOrCreateTab({
namespace: this.props.sourceName,
isReadonly: this.props.sourceReadonly,
isTimeSeries: this.props.isTimeSeries,
sourceName: this.props.sourceViewOn,
editViewName: this.props.namespace,
sourceReadonly: false,
sourceViewOn: null,
sourcePipeline: this.props.pipeline
});
}

returnToView = () => {
this.props.selectOrCreateTab(
this.props.editViewName,
true,
this.props.namespace,
null,
this.props.isReadonly,
this.props.sourceName,
this.props.pipeline
);
this.props.selectOrCreateTab({
namespace: this.props.editViewName,
isReadonly: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitely easier to see what's up at a glance now 👍

isTimeSeries: this.props.isTimeSeries,
sourceName: this.props.namespace,
editViewName: null,
sourceReadonly: this.props.isReadonly,
sourceViewOn: this.props.sourceName,
sourcePipeline: this.props.pipeline
});
}

handleDBClick = (db) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Collection extends Component {

static propTypes = {
namespace: PropTypes.string.isRequired,
isTimeSeries: PropTypes.bool,
isReadonly: PropTypes.bool.isRequired,
tabs: PropTypes.array.isRequired,
views: PropTypes.array.isRequired,
Expand Down Expand Up @@ -69,6 +70,7 @@ class Collection extends Component {
globalAppRegistry={this.props.globalAppRegistry}
namespace={this.props.namespace}
isReadonly={this.props.isReadonly}
isTimeSeries={this.props.isTimeSeries}
statsPlugin={this.props.statsPlugin}
statsStore={this.props.statsStore}
editViewName={this.props.editViewName}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ describe('Collection [Component]', () => {
component = mount(
<Collection
isReadonly={false}
isTimeSeries={false}
tabs={[]}
views={[]}
queryHistoryIndexes={[]}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,20 @@ class CreateTab extends PureComponent {
static displayName = 'CreateTabComponent';

static propTypes = {
createNewTab: PropTypes.func.isRequired,
activeNamespace: PropTypes.string.isRequired,
activeIsReadonly: PropTypes.bool.isRequired,
activeSourceName: PropTypes.string
createNewTab: PropTypes.func.isRequired
};

/**
* Create a new tab with the same namespace as the last one.
*/
createTab = () => {
this.props.createNewTab(
this.props.activeNamespace,
this.props.activeIsReadonly,
this.props.activeSourceName
);
}

/**
* Render the Create Tab component.
*
* @returns {Component} The rendered component.
*/
render() {
return (
<div className={styles['create-tab']} onClick={this.createTab}>
<div
className={styles['create-tab']}
onClick={() => this.props.createNewTab()}
>
+
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ describe('CreateTab [Component]', () => {

component = mount(
<CreateTab
activeNamespace="db.coll"
activeIsReadonly={false}
activeSourceName=""
createNewTab={createNewTabSpy} />
createNewTab={createNewTabSpy}
/>
);
});

Expand All @@ -32,7 +30,7 @@ describe('CreateTab [Component]', () => {
context('when clicking the create button', () => {
it('calls the action', () => {
component.find(`.${styles['create-tab']}`).simulate('click');
expect(createNewTabSpy.calledWith('db.coll')).to.equal(true);
expect(createNewTabSpy.called).to.equal(true);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ const KEY_CLOSE_BRKT = 221;
*/
const KEY_OPEN_BRKT = 219;

const DEFAULT_NEW_TAB = {
namespace: '',
isReadonly: false,
sourceName: ''
};

/**
* The collection workspace contains tabs of multiple collections.
*/
Expand Down Expand Up @@ -88,14 +94,31 @@ class Workspace extends PureComponent {
this.props.moveTab(oldIndex, newIndex);
}

onCreateNewTab = () => {
const activeTab = this.activeTab();
const newTabProps = activeTab
? {
namespace: activeTab.namespace,
isReadonly: activeTab.isReadonly,
isTimeSeries: activeTab.isTimeSeries,
sourceName: activeTab.sourceName,
editViewName: activeTab.editViewName,
sourceReadonly: activeTab.sourceReadonly,
sourceViewOn: activeTab.sourceViewOn,
sourcePipeline: activeTab.pipeline
}
: DEFAULT_NEW_TAB;
this.props.createNewTab(newTabProps);
}

/**
* Handle key press. This listens for CTRL/CMD+T and CTRL/CMD+W to control
* natural opening and closing of collection tabs. CTRL/CMD+SHIFT+] and
* CTRL/CMD+SHIFT+[ to go forward and backwards through the tabs.
*
* @param {Event} evt - The event.
*/
handleKeypress(evt) {
handleKeypress = (evt) => {
if (evt.ctrlKey || evt.metaKey) {
if (evt.shiftKey) {
if (evt.keyCode === KEY_CLOSE_BRKT) {
Expand All @@ -109,7 +132,7 @@ class Workspace extends PureComponent {
evt.preventDefault();
}
} else if (evt.keyCode === KEY_T) {
this.props.createNewTab(this.activeNamespace());
this.onCreateNewTab();
}
}
}
Expand All @@ -118,26 +141,6 @@ class Workspace extends PureComponent {
return this.props.tabs.find(tab => tab.isActive);
}

/**
* Get the active namespace in the list.
*
* @returns {String} The active namespace in the list.
*/
activeNamespace() {
const activeTab = this.activeTab();
return activeTab ? activeTab.namespace : '';
}

activeIsReadonly() {
const activeTab = this.activeTab();
return activeTab ? activeTab.isReadonly : false;
}

activeSourceName() {
const activeTab = this.activeTab();
return activeTab ? activeTab.sourceName : undefined;
}

renderTab = (tab, i) => {
return (
<CollectionTab
Expand Down Expand Up @@ -201,6 +204,7 @@ class Workspace extends PureComponent {
id={tab.id}
namespace={tab.namespace}
isReadonly={tab.isReadonly}
isTimeSeries={tab.isTimeSeries}
sourceName={tab.sourceName}
editViewName={tab.editViewName}
sourceReadonly={tab.sourceReadonly}
Expand Down Expand Up @@ -236,10 +240,8 @@ class Workspace extends PureComponent {
<div className={styles['workspace-tabs-container']}>
{this.renderTabs()}
<CreateTab
createNewTab={this.props.createNewTab}
activeNamespace={this.activeNamespace()}
activeIsReadonly={this.activeIsReadonly()}
activeSourceName={this.activeSourceName()} />
createNewTab={this.onCreateNewTab}
/>
</div>
<div className={styles['workspace-tabs-right']}>
<div onClick={this.props.nextTab} className={styles['workspace-tabs-next']}>
Expand Down
Loading