Skip to content

Commit e2bc31b

Browse files
pzrqdurran
authored andcommitted
COMPASS-989: Backport COMPASS 904 per plugin tooltip (#904) (#907)
* Remove unused this.Tooltip It attempts to get an 'App.Tooltip' component from the AppRegistry that was not registered, and so ends up as undefined. * Remove unused CREATE_DATABASE_ICON It was decided a while back not to proceed with it as we already have the CREATE_DATABASE_BUTTON. * Consolidate sidebar tooltips into top-level component Anecdotally improves performance of the sidebar, might bring out the timeline when clicking the Sidebar Refresh button to be sure. * abstract react-tooltip to HadronToolTip * enable tooltip for databases-table * enable toolltip for collections-table * enable tooltip for crud * enable tooltip for indexes * enable tooltip for validation * remove global tooltip from home * add test for the collections table component * add test for databases table component * add test for indexes component * add test for sampling message * add test for rule builder component * 👕
1 parent ab11932 commit e2bc31b

File tree

19 files changed

+147
-33
lines changed

19 files changed

+147
-33
lines changed

src/internal-packages/app/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
const app = require('hadron-app');
2+
3+
const HadronTooltip = require('./lib/components/hadron-tooltip');
24
const StoreConnector = require('./lib/components/store-connector');
35
const SortableTable = require('./lib/components/sortable-table');
46
const TabNavBar = require('./lib/components/tab-nav-bar');
@@ -12,6 +14,7 @@ const ModalStatusMessage = require('./lib/components/modal-status-message');
1214
* Activate all the components in the Compass Sidebar package.
1315
*/
1416
function activate() {
17+
app.appRegistry.registerComponent('App.HadronTooltip', HadronTooltip);
1518
app.appRegistry.registerComponent('App.StoreConnector', StoreConnector);
1619
app.appRegistry.registerComponent('App.SortableTable', SortableTable);
1720
app.appRegistry.registerComponent('App.ModalStatusMessage', ModalStatusMessage);
@@ -26,6 +29,7 @@ function activate() {
2629
* Deactivate all the components in the Compass Sidebar package.
2730
*/
2831
function deactivate() {
32+
app.appRegistry.deregisterComponent('App.HadronTooltip');
2933
app.appRegistry.deregisterComponent('App.StoreConnector');
3034
app.appRegistry.deregisterComponent('App.SortableTable');
3135
app.appRegistry.deregisterComponent('App.ModalStatusMessage');
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const React = require('react');
2+
const ReactTooltip = require('react-tooltip');
3+
4+
class HadronTooltip extends React.Component {
5+
6+
/**
7+
* Render the tooltip component.
8+
*
9+
* @returns {React.Component} The component.
10+
*/
11+
render() {
12+
return (
13+
<ReactTooltip {...this.props} />
14+
);
15+
}
16+
}
17+
18+
HadronTooltip.propTypes = {
19+
id: React.PropTypes.string.isRequired,
20+
effect: React.PropTypes.string,
21+
className: React.PropTypes.string,
22+
place: React.PropTypes.string,
23+
delayShow: React.PropTypes.number
24+
};
25+
26+
HadronTooltip.defaultProps = {
27+
place: 'right',
28+
effect: 'solid',
29+
className: 'hadron-tooltip',
30+
delayShow: 200
31+
};
32+
33+
HadronTooltip.displayName = 'HadronTooltip';
34+
35+
module.exports = HadronTooltip;

src/internal-packages/app/styles/not-writable-tooltip.less renamed to src/internal-packages/app/styles/hadron-tooltip.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.is-not-writable-tooltip {
1+
.hadron-tooltip {
22
height: 24px;
33
font-size: 11px;
44
padding: 3px 6px !important;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
@import './hadron-tooltip.less';
12
@import './sortable-table.less';
23
@import './modal-status-message.less';
34
@import './tab-nav-bar.less';
45
@import './status-row.less';
5-
@import './not-writable-tooltip.less';

src/internal-packages/database-ddl/lib/component/databases-table.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class DatabasesTable extends React.Component {
2020
this.DatabaseDDLAction = app.appRegistry.getAction('DatabaseDDL.Actions');
2121
this.SortableTable = app.appRegistry.getComponent('App.SortableTable');
2222
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
23-
this.Tooltip = app.appRegistry.getComponent('App.Tooltip');
23+
this.HadronTooltip = app.appRegistry.getComponent('App.HadronTooltip');
2424
}
2525

2626
onColumnHeaderClicked(column, order) {
@@ -83,12 +83,18 @@ class DatabasesTable extends React.Component {
8383
});
8484

8585
const isWritable = app.dataService.isWritable();
86+
const tooltipId = 'database-ddl-is-not-writable';
87+
const isNotWritableTooltip = isWritable ? null : (
88+
<this.HadronTooltip
89+
id={tooltipId}
90+
/>
91+
);
8692
const tooltipText = 'This action is not available on a secondary node';
8793

8894
return (
8995
<div className="rtss-databases" data-test-id="databases-table">
9096
<div className="rtss-databases-create-button action-bar controls-container">
91-
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for="is-not-writable">
97+
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for={tooltipId}>
9298
<button
9399
className="btn btn-primary btn-xs"
94100
type="button"
@@ -117,6 +123,7 @@ class DatabasesTable extends React.Component {
117123
</div>
118124
{this.props.databases.length === 0 ?
119125
this.renderNoCollections(isWritable) : null}
126+
{isNotWritableTooltip}
120127
</div>
121128
);
122129
}

src/internal-packages/database/lib/components/collections-table.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class CollectionsTable extends React.Component {
1313
super(props);
1414
this.SortableTable = app.appRegistry.getComponent('App.SortableTable');
1515
this.CollectionStore = app.appRegistry.getStore('App.CollectionStore');
16+
this.HadronTooltip = app.appRegistry.getComponent('App.HadronTooltip');
1617
}
1718

1819
onColumnHeaderClicked(column, order) {
@@ -61,12 +62,18 @@ class CollectionsTable extends React.Component {
6162
});
6263

6364
const isWritable = app.dataService.isWritable();
64-
const tooltipText = 'This action is not available on a secondary node.';
65+
const tooltipId = 'database-is-not-writable';
66+
const isNotWritableTooltip = isWritable ? null : (
67+
<this.HadronTooltip
68+
id={tooltipId}
69+
/>
70+
);
71+
const tooltipText = 'This action is not available on a secondary node';
6572

6673
return (
6774
<div className="collections-table" data-test-id="collections-table">
6875
<div className="collections-table-create-button action-bar controls-container">
69-
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for="is-not-writable">
76+
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for={tooltipId}>
7077
<button
7178
className="btn btn-primary btn-xs"
7279
type="button"
@@ -93,6 +100,7 @@ class CollectionsTable extends React.Component {
93100
/>
94101
</div>
95102
</div>
103+
{isNotWritableTooltip}
96104
</div>
97105
);
98106
}

src/internal-packages/home/lib/component/home.jsx

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const React = require('react');
22
const app = require('hadron-app');
3-
const ReactTooltip = require('react-tooltip');
43

54
class Home extends React.Component {
65
constructor(props) {
@@ -46,17 +45,6 @@ class Home extends React.Component {
4645
}
4746

4847
render() {
49-
// if server is not writable, include global tooltip component for diabled buttons
50-
const isNotWritableTooltip = app.dataService.isWritable() ? null : (
51-
<ReactTooltip
52-
id="is-not-writable"
53-
effect="solid"
54-
class="is-not-writable-tooltip"
55-
place="right"
56-
delayShow={200}
57-
/>
58-
);
59-
6048
return (
6149
<div className="page-container">
6250
<this.InstanceHeader sidebarCollapsed={this.state.collapsed}/>
@@ -65,7 +53,6 @@ class Home extends React.Component {
6553
{this.renderContent()}
6654
</div>
6755
<this.sideBar onCollapse={this.collapseSidebar.bind(this)}/>
68-
{isNotWritableTooltip}
6956
<this.CreateDatabaseDialog />
7057
<this.DropDatabaseDialog />
7158
<this.CreateCollectionDialog />

src/internal-packages/indexes/lib/component/create-index-button.jsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const React = require('react');
2+
const app = require('hadron-app');
23
const CreateIndexModal = require('./create-index-modal');
34

45
/**
@@ -16,6 +17,7 @@ class CreateIndexButton extends React.Component {
1617
this.state = {
1718
showModal: false
1819
};
20+
this.HadronTooltip = app.appRegistry.getComponent('App.HadronTooltip');
1921
}
2022

2123
/**
@@ -42,11 +44,17 @@ class CreateIndexButton extends React.Component {
4244
* @returns {React.Component} The create index button.
4345
*/
4446
render() {
45-
const tooltipText = 'This action is not available on a secondary node.';
47+
const tooltipId = 'index-is-not-writable';
48+
const isNotWritableTooltip = this.props.isWritable ? null : (
49+
<this.HadronTooltip
50+
id={tooltipId}
51+
/>
52+
);
53+
const tooltipText = 'This action is not available on a secondary node';
4654

4755
return (
4856
<div className="create-index-btn action-bar">
49-
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for="is-not-writable">
57+
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for={tooltipId}>
5058
<button
5159
className="btn btn-primary btn-xs"
5260
type="button"
@@ -56,6 +64,7 @@ class CreateIndexButton extends React.Component {
5664
Create Index
5765
</button>
5866
</div>
67+
{isNotWritableTooltip}
5968
<CreateIndexModal
6069
open={this.state.showModal}
6170
close={this.close.bind(this)} />

src/internal-packages/query/lib/component/sampling-message.jsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class SamplingMessage extends React.Component {
2323
this.documentRemovedAction = crudActions.documentRemoved;
2424
this.refreshDocumentsAction = crudActions.refreshDocuments;
2525
this.loadMoreDocumentsStore = app.appRegistry.getStore('CRUD.LoadMoreDocumentsStore');
26+
this.HadronTooltip = app.appRegistry.getComponent('App.HadronTooltip');
2627
}
2728

2829
/**
@@ -135,7 +136,15 @@ class SamplingMessage extends React.Component {
135136
*/
136137
renderQueryMessage() {
137138
const noun = pluralize('document', this.state.count);
138-
const tooltipText = 'This action is not available on a secondary node.';
139+
140+
const isWritable = app.dataService.isWritable();
141+
const tooltipId = 'document-is-not-writable';
142+
const isNotWritableTooltip = isWritable ? null : (
143+
<this.HadronTooltip
144+
id={tooltipId}
145+
/>
146+
);
147+
const tooltipText = 'This action is not available on a secondary node';
139148

140149
return (
141150
<div>
@@ -152,7 +161,7 @@ class SamplingMessage extends React.Component {
152161
text="&nbsp;Refresh" />
153162
</div>
154163
<div className="action-bar">
155-
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for="is-not-writable">
164+
<div className="tooltip-button-wrapper" data-tip={tooltipText} data-for={tooltipId}>
156165
<button
157166
className="btn btn-primary btn-xs open-insert"
158167
type="button"
@@ -162,6 +171,7 @@ class SamplingMessage extends React.Component {
162171
Insert Document
163172
</button>
164173
</div>
174+
{isNotWritableTooltip}
165175
</div>
166176
</div>
167177
);

src/internal-packages/sidebar/lib/components/constants.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const TOOLTIP_IDS = Object.freeze({
22
CREATE_COLLECTION: 'create-collection',
33
CREATE_DATABASE_BUTTON: 'create-database-button',
4-
CREATE_DATABASE_ICON: 'create-database-icon',
54
DROP_COLLECTION: 'drop-collection',
65
DROP_DATABASE: 'drop-database'
76
});

0 commit comments

Comments
 (0)