Skip to content

Commit 7fbc590

Browse files
authored
COMPASS-2346: Don't show index actions in readonly mode (#1336)
1 parent 2813979 commit 7fbc590

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

src/internal-plugins/indexes/lib/component/drop-column.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class DropColumn extends React.Component {
4545
render() {
4646
return (
4747
<td className="drop-column">
48-
{this.props.indexName !== '_id_' ?
48+
{this.props.indexName !== '_id_' && !this.props.isReadonly ?
4949
<button
5050
className="drop-btn btn btn-default btn-sm"
5151
type="button"
@@ -65,7 +65,8 @@ class DropColumn extends React.Component {
6565
DropColumn.displayName = 'DropColumn';
6666

6767
DropColumn.propTypes = {
68-
indexName: PropTypes.string.isRequired
68+
indexName: PropTypes.string.isRequired,
69+
isReadonly: PropTypes.bool.isRequired
6970
};
7071

7172
module.exports = DropColumn;

src/internal-plugins/indexes/lib/component/index-list.jsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const _ = require('lodash');
22
const React = require('react');
3+
const PropTypes = require('prop-types');
34
const Index = require('./index');
45
const SortIndexesStore = require('../store/sort-indexes-store');
56
const UpdateIndexesStore = require('../store/update-indexes-store');
@@ -52,7 +53,7 @@ class IndexList extends React.Component {
5253
*/
5354
render() {
5455
const indexes = _.map(this.state.indexes, (model) => {
55-
return (<Index key={model.name} index={model} />);
56+
return (<Index key={model.name} index={model} isReadonly={this.props.isReadonly} />);
5657
});
5758
return (
5859
<tbody className="table">
@@ -64,4 +65,8 @@ class IndexList extends React.Component {
6465

6566
IndexList.displayName = 'IndexList';
6667

68+
IndexList.propTypes = {
69+
isReadonly: PropTypes.bool.isRequired
70+
};
71+
6772
module.exports = IndexList;

src/internal-plugins/indexes/lib/component/index.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ class Index extends React.Component {
3737
this.setState(state);
3838
}
3939

40+
isWritable() {
41+
return !this.CollectionStore.isReadonly() &&
42+
this.state.isWritable &&
43+
!this.props.isReadonly;
44+
}
45+
4046
/**
4147
* Render the index.
4248
*
@@ -52,9 +58,7 @@ class Index extends React.Component {
5258
relativeSize={this.props.index.relativeSize} />
5359
<UsageColumn usage={this.props.index.usageCount} since={this.props.index.usageSince} />
5460
<PropertyColumn index={this.props.index} />
55-
{(!this.CollectionStore.isReadonly() && this.state.isWritable) ?
56-
<DropColumn indexName={this.props.index.name} />
57-
: null}
61+
<DropColumn indexName={this.props.index.name} isReadonly={!this.isWritable()} />
5862
</tr>
5963
);
6064
}
@@ -63,7 +67,8 @@ class Index extends React.Component {
6367
Index.displayName = 'Index';
6468

6569
Index.propTypes = {
66-
index: PropTypes.object.isRequired
70+
index: PropTypes.object.isRequired,
71+
isReadonly: PropTypes.bool.isRequired
6772
};
6873

6974
module.exports = Index;

src/internal-plugins/indexes/lib/component/indexes.jsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class Indexes extends React.Component {
6161
this.setState(this.determineState(error));
6262
}
6363

64+
isReadonlyDistro() {
65+
return process.env.HADRON_READONLY === 'true';
66+
}
67+
6468
shouldComponentupdate(nextProps, nextState) {
6569
return nextState.isWritable !== this.state.isWritable ||
6670
nextState.isReadonly !== this.state.isReadonly;
@@ -72,7 +76,7 @@ class Indexes extends React.Component {
7276
<div className="column main">
7377
<table data-test-id="indexes-table">
7478
<IndexHeader />
75-
<IndexList />
79+
<IndexList isReadonly={this.isReadonlyDistro()} />
7680
</table>
7781
</div>
7882
</div>
@@ -94,6 +98,17 @@ class Indexes extends React.Component {
9498
);
9599
}
96100

101+
renderCreateIndexButton() {
102+
if (!this.isReadonlyDistro()) {
103+
return (
104+
<CreateIndexButton isWritable={this.state.isWritable} description={this.state.description} />
105+
);
106+
}
107+
return (
108+
<div className="create-index-btn action-bar"></div>
109+
);
110+
}
111+
97112
/**
98113
* Render the indexes.
99114
*
@@ -102,9 +117,8 @@ class Indexes extends React.Component {
102117
render() {
103118
return (
104119
<div className="index-container">
105-
{/* NOT SURE if we need to wrap the controls-container in a readonly conditional as well. */}
106120
<div className="controls-container">
107-
<CreateIndexButton isWritable={this.state.isWritable} description={this.state.description} />
121+
{this.renderCreateIndexButton()}
108122
</div>
109123
{(this.state.isReadonly || this.state.error) ? this.renderBanner() : this.renderComponent()}
110124
</div>

0 commit comments

Comments
 (0)