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
36 changes: 31 additions & 5 deletions src/internal-packages/app/lib/stores/collection-store.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const app = require('ampersand-app');
const Reflux = require('reflux');
const { NamespaceStore } = require('hadron-reflux-store');

Expand All @@ -10,8 +11,7 @@ const CollectionStore = Reflux.createStore({
* Initialize the store.
*/
init() {
this.ns = null;
this.readonly = null;
this.collection = {};
},

/**
Expand All @@ -20,11 +20,37 @@ const CollectionStore = Reflux.createStore({
* @param {Object} collection - The collection info.
*/
setCollection(collection) {
this.ns = collection._id;
this.readonly = collection.readonly;
this.collection = collection;
if (collection._id) {
NamespaceStore.ns = this.ns;
NamespaceStore.ns = collection._id;
}
},

/**
* Get the collection ns.
*
* @returns {String} The collection ns.
*/
ns() {
return this.collection._id;
},

/**
* Is the collection readonly?
*
* @returns {Boolean} If the collection is readonly.
*/
isReadonly() {
return this.collection.readonly;
},

/**
* Is the collection writable?
*
* @returns {Boolean} If the collection is writable.
*/
isWritable() {
return !this.isReadonly() && app.dataService.isWritable();
}
});

Expand Down
2 changes: 1 addition & 1 deletion src/internal-packages/collection-stats/lib/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CollectionStatsStore = Reflux.createStore({
*/
loadCollectionStats: function(ns) {
if (toNS(ns || '').collection) {
if (this.CollectionStore.readonly) {
if (this.CollectionStore.isReadonly()) {
this.trigger();
} else {
app.dataService.collection(ns, { readPreference: READ }, (err, result) => {
Expand Down
3 changes: 1 addition & 2 deletions src/internal-packages/crud/lib/component/document-list.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,10 @@ class DocumentList extends React.Component {
* @return {Array} The document list item components.
*/
renderDocuments(docs) {
const editable = app.dataService.isWritable() && !this.CollectionStore.readonly;
return _.map(docs, (doc) => {
return (
<li className="document-list-item" key={this._key(doc)}>
<Document doc={doc} key={this._key(doc)} editable={editable} />
<Document doc={doc} key={this._key(doc)} editable={this.CollectionStore.isWritable()} />
</li>
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ class CollectionsTable extends React.Component {
});
});

const writable = app.dataService.isWritable();

return (
<div className="collections-table">
<div className="collections-table-create-button">
<TextButton
text="Create Collection"
className="btn btn-default btn-sm"
clickHandler={this.onCreateCollectionButtonClicked.bind(this)} />
{writable ?
<TextButton
text="Create Collection"
className="btn btn-default btn-sm"
clickHandler={this.onCreateCollectionButtonClicked.bind(this)} /> : null}
</div>
<this.SortableTable
theme="light"
Expand All @@ -54,7 +57,7 @@ class CollectionsTable extends React.Component {
sortOrder={this.props.sortOrder}
sortColumn={this.props.sortColumn}
valueIndex={0}
removable
removable={writable}
onColumnHeaderClicked={this.onColumnHeaderClicked.bind(this)}
onRowDeleteButtonClicked={this.onRowDeleteButtonClicked.bind(this)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class CompassExplain extends React.Component {
return (
<div className="compass-explain header-margin">
<div className="flexbox-fix"></div>
{this.CollectionStore.readonly ? this.renderReadonly() : this.renderComponent()}
{this.CollectionStore.isReadonly() ? this.renderReadonly() : this.renderComponent()}
</div>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/internal-packages/explain/lib/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const CompassExplainStore = Reflux.createStore({
if (!ns.database || !ns.collection) {
return;
}
if (this.CollectionStore.readonly) {
if (this.CollectionStore.isReadonly()) {
this.setState(this.getInitialState());
} else {
app.dataService.explain(ns.ns, filter, options, (err, explain) => {
Expand Down
3 changes: 2 additions & 1 deletion src/internal-packages/indexes/lib/component/index-header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class IndexHeader extends React.Component {
constructor(props) {
super(props);
this.state = { sortOrder: ASC };
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
}

/**
Expand Down Expand Up @@ -59,7 +60,7 @@ class IndexHeader extends React.Component {
<IndexHeaderColumn hook="th-size" name="Size" sortOrder={this.state.sortOrder} />
<IndexHeaderColumn hook="th-usage" name="Usage" sortOrder={this.state.sortOrder} />
<IndexHeaderColumn hook="th-properties" name="Properties" sortOrder={this.state.sortOrder} />
{app.dataService.isWritable() ?
{this.CollectionStore.isWritable() ?
<IndexHeaderColumn hook="th-drop" name="Drop" sortOrder={this.state.sortOrder}/>
: null}
</tr>
Expand Down
7 changes: 6 additions & 1 deletion src/internal-packages/indexes/lib/component/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ const app = require('ampersand-app');
*/
class Index extends React.Component {

constructor(props) {
super(props);
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
}

/**
* Render the index.
*
Expand All @@ -27,7 +32,7 @@ class Index extends React.Component {
relativeSize={this.props.index.relativeSize} />
<UsageColumn usage={this.props.index.usageCount} since={this.props.index.usageSince} />
<PropertyColumn index={this.props.index} />
{app.dataService.isWritable() ?
{this.CollectionStore.isWritable() ?
<DropColumn indexName={this.props.index.name} />
: null}
</tr>
Expand Down
6 changes: 4 additions & 2 deletions src/internal-packages/indexes/lib/component/indexes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ class Indexes extends React.Component {
}

determineState() {
const writable = app.dataService.isWritable() && !this.CollectionStore.readonly;
return { writable: writable, readonly: this.CollectionStore.readonly };
return {
writable: this.CollectionStore.isWritable(),
readonly: this.CollectionStore.isReadonly()
};
}

handleLoad() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const LoadIndexesStore = Reflux.createStore({
*/
loadIndexes: function() {
if (NamespaceStore.ns) {
if (this.CollectionStore.readonly) {
if (this.CollectionStore.isReadonly()) {
this.trigger([]);
} else {
app.dataService.indexes(NamespaceStore.ns, { readPreference: READ }, (err, indexes) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class SamplingMessage extends React.Component {
<div className="sampling-message">
Query returned&nbsp;<b>{this.state.count}</b>&nbsp;{noun}.&nbsp;
{this._loadedMessage()}
{!this.CollectionStore.readonly ?
{this.CollectionStore.isWritable() ?
<TextButton
clickHandler={this.props.insertHandler}
className="btn btn-primary btn-xs open-insert"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ class DatabasesTable extends React.Component {
});
});

const writable = app.dataService.isWritable();

return (
<div className="rtss-databases">
<div className="rtss-databases-create-button">
<TextButton
text="Create Database"
className="btn btn-default btn-sm"
clickHandler={this.onCreateDatabaseButtonClicked.bind(this)} />
{writable ?
<TextButton
text="Create Database"
className="btn btn-default btn-sm"
clickHandler={this.onCreateDatabaseButtonClicked.bind(this)} /> : null}
</div>
<this.SortableTable
theme="dark"
Expand All @@ -54,7 +57,7 @@ class DatabasesTable extends React.Component {
sortOrder={this.props.sortOrder}
sortColumn={this.props.sortColumn}
valueIndex={0}
removable
removable={writable}
onColumnHeaderClicked={this.onColumnHeaderClicked.bind(this)}
onRowDeleteButtonClicked={this.onRowDeleteButtonClicked.bind(this)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class Validation extends React.Component {
render() {
return (
<div className="validation header-margin">
{this.CollectionStore.readonly ? this.renderReadonly() : this.renderComponent()}
{this.CollectionStore.isReadonly() ? this.renderReadonly() : this.renderComponent()}
</div>
);
}
Expand Down
26 changes: 24 additions & 2 deletions src/internal-packages/validation/lib/stores/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const ValidationStore = Reflux.createStore({
*/
init() {
this.lastFetchedValidatorDoc = {};
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
NamespaceStore.listen((ns) => {
if (ns && toNS(ns).collection) {
ValidationActions.fetchValidationRules();
Expand Down Expand Up @@ -238,8 +237,31 @@ const ValidationStore = Reflux.createStore({
});
},

/**
* Determine if the collection is readonly.
*
* @note Durran: The wacky logic here is because the ampersand app is not
* loaded in the unit test environment and the validation tests fail since
* not app registry is found. Once we get rid of the ampersand app we can
* put the store set back into the init once we've sorted out the proper
* test strategy.
*
* @returns {Boolean} If the collection is readonly.
*/
_isCollectionReadonly() {
if (this.CollectionStore) {
return this.CollectionStore.isReadonly();
}
const registry = app.appRegistry;
if (registry) {
this.CollectionStore = registry.getStore('App.CollectionStore');
return this.CollectionStore.isReadonly();
}
return false;
},

fetchValidationRules() {
if (this.CollectionStore.readonly) {
if (this._isCollectionReadonly()) {
this.setState(this.getInitialState());
} else {
this.setState({
Expand Down