Skip to content

Commit 4609de4

Browse files
committed
INT-1160: Refactoring buttons (#427)
* INT-1160: Refactoring buttons * Incorporate button changes from Marc * Fix bug with length on null fields * Check namespace in should component update * Bring back treasure hunt (cherry picked from commit 3718cbf)
1 parent bf863aa commit 4609de4

19 files changed

+171
-441
lines changed

src/internal-packages/crud/lib/component/cancel-edit-button.jsx

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/internal-packages/crud/lib/component/cancel-insert-button.jsx

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/internal-packages/crud/lib/component/clone-document-button.jsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/internal-packages/crud/lib/component/delete-document-button.jsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/internal-packages/crud/lib/component/document-actions.jsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
const React = require('react');
44
const app = require('ampersand-app');
5-
const EditDocumentButton = require('./edit-document-button');
6-
const DeleteDocumentButton = require('./delete-document-button');
7-
const CloneDocumentButton = require('./clone-document-button');
5+
const IconButton = require('./icon-button');
86

97
/**
108
* The feature flag.
@@ -34,9 +32,18 @@ class DocumentActions extends React.Component {
3432
if (app.isFeatureEnabled(FEATURE)) {
3533
return (
3634
<div className='document-actions'>
37-
<EditDocumentButton handler={this.props.edit} />
38-
<DeleteDocumentButton handler={this.props.remove} />
39-
<CloneDocumentButton handler={this.props.clone} />
35+
<IconButton
36+
title='Edit Document'
37+
iconClassName='fa fa-pencil'
38+
clickHandler={this.props.edit} />
39+
<IconButton
40+
title='Delete Document'
41+
iconClassName='fa fa-trash-o'
42+
clickHandler={this.props.remove} />
43+
<IconButton
44+
title='Clone Document'
45+
iconClassName='fa fa-clone'
46+
clickHandler={this.props.clone} />
4047
</div>
4148
);
4249
}

src/internal-packages/crud/lib/component/document-footer.jsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
const _ = require('lodash');
44
const React = require('react');
55
const Element = require('hadron-document').Element;
6-
const CancelEditButton = require('./cancel-edit-button');
7-
const UpdateButton = require('./update-button');
6+
const TextButton = require('./text-button');
87

98
/**
109
* The progress mode.
@@ -169,8 +168,14 @@ class DocumentFooter extends React.Component {
169168
{this.state.message}
170169
</div>
171170
<div className='document-footer-actions'>
172-
<CancelEditButton handler={this.handleCancel.bind(this)} />
173-
<UpdateButton handler={this.handleUpdate.bind(this)} />
171+
<TextButton
172+
className='btn btn-link btn-xs cancel'
173+
text='Cancel'
174+
clickHandler={this.handleCancel.bind(this)} />
175+
<TextButton
176+
className='btn btn-default btn-xs update'
177+
text='Update'
178+
clickHandler={this.handleUpdate.bind(this)} />
174179
</div>
175180
</div>
176181
);

src/internal-packages/crud/lib/component/document-list.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const app = require('ampersand-app');
77
const Action = require('hadron-action');
88
const ObjectID = require('bson').ObjectID;
99
const Document = require('./document');
10+
const NamespaceStore = require('hadron-reflux-store').NamespaceStore;
1011
const ResetDocumentListStore = require('../store/reset-document-list-store');
1112
const LoadMoreDocumentsStore = require('../store/load-more-documents-store');
1213
const RemoveDocumentStore = require('../store/remove-document-store');
@@ -68,7 +69,7 @@ class DocumentList extends React.Component {
6869
*/
6970
constructor(props) {
7071
super(props);
71-
this.state = { docs: [], nextSkip: 0 };
72+
this.state = { docs: [], nextSkip: 0, namespace: NamespaceStore.ns };
7273
}
7374

7475
/**
@@ -101,7 +102,8 @@ class DocumentList extends React.Component {
101102
docs: this.renderDocuments(documents),
102103
nextSkip: documents.length,
103104
count: count,
104-
loadedCount: documents.length
105+
loadedCount: documents.length,
106+
namespace: NamespaceStore.ns
105107
});
106108
}
107109

@@ -212,7 +214,8 @@ class DocumentList extends React.Component {
212214
shouldComponentUpdate(nextProps, nextState) {
213215
return (nextState.docs.length !== this.state.docs.length) ||
214216
(nextState.nextSkip !== this.state.nextSkip) ||
215-
(nextState.loadedCount !== this.state.loadedCount);
217+
(nextState.loadedCount !== this.state.loadedCount) ||
218+
(nextState.namespace !== this.state.namespace);
216219
}
217220

218221
/**

src/internal-packages/crud/lib/component/edit-document-button.jsx

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/internal-packages/crud/lib/component/editable-value.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class EditableValue extends React.Component {
4141
<input
4242
ref={(c) => this._node = c}
4343
type='text'
44-
size={this.element.currentValue.length}
44+
size={this.element.currentValue ? this.element.currentValue.length : 5}
4545
className={this.style()}
4646
onBlur={this.handleBlur.bind(this)}
4747
onFocus={this.handleFocus.bind(this)}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
3+
const React = require('react');
4+
5+
/**
6+
* The button constant.
7+
*/
8+
const BUTTON = 'button';
9+
10+
/**
11+
* Component for a button with an icon.
12+
*/
13+
class IconButton extends React.Component {
14+
15+
/**
16+
* The component constructor.
17+
*
18+
* @param {Object} props - The properties.
19+
*/
20+
constructor(props) {
21+
super(props);
22+
}
23+
24+
/**
25+
* Render the button.
26+
*
27+
* @returns {Component} The button component.
28+
*/
29+
render() {
30+
return (
31+
<button
32+
type={BUTTON}
33+
title={this.props.title}
34+
className='btn btn-default btn-xs'
35+
onClick={this.props.clickHandler}>
36+
<i className={this.props.iconClassName} aria-hidden='true'></i>
37+
</button>
38+
);
39+
}
40+
41+
/**
42+
* By default should not need to to re-render itself.
43+
*
44+
* @returns {Boolean} Always false.
45+
*/
46+
shouldComponentUpdate() {
47+
return false;
48+
}
49+
}
50+
51+
IconButton.displayName = 'IconButton';
52+
53+
module.exports = IconButton;

0 commit comments

Comments
 (0)