Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
More refactoring based on review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Eng committed Oct 15, 2015
1 parent 9cb00d6 commit 7bf615e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 33 deletions.
9 changes: 6 additions & 3 deletions frontend/src/main/web/lib/components/SystemGlossary.jsx
Expand Up @@ -15,6 +15,8 @@ import StringUtils from '../utils/StringUtils'
var SystemGlossary = React.createClass({
mixins: [PureRenderMixin],

filterTimeout: null,

_init: function() {
return GlossaryStore.init();
},
Expand Down Expand Up @@ -48,11 +50,12 @@ var SystemGlossary = React.createClass({

_handleFilterChange: function(event) {
this.setState({filter: event.target.value});
if(this.state.filterTimeout !== null) {
clearTimeout(this.state.filterTimeout);

if(this.filterTimeout !== null) {
clearTimeout(this.filterTimeout);
}
if(!StringUtils.isEmptyOrNull(event.target.value)) {
this.state.filterTimeout = setTimeout(() => {
this.filterTimeout = setTimeout(() => {
Actions.updateFilter(this.state.filter);
}, 500);
}
Expand Down
22 changes: 10 additions & 12 deletions frontend/src/main/web/lib/components/glossary/ActionCell.jsx
Expand Up @@ -55,16 +55,14 @@ var ActionCell = React.createClass({
},

render: function () {
var self = this;

if (self.props.contentHash === null || self.state.entry === null) {
if (this.props.contentHash === null || this.state.entry === null) {
return (<LoadingCell/>);
} else {
var isTransModified = self.state.entry.status.isTransModified;
var canUpdateComment = self.state.entry.status.canUpdateTransComment;
var isSaving = self.state.entry.status.isSaving;
var isTransModified = this.state.entry.status.isTransModified;
var canUpdateComment = this.state.entry.status.canUpdateTransComment;
var isSaving = this.state.entry.status.isSaving;

var infoTooltip = <Tooltip id="info">{self.props.info}</Tooltip>;
var infoTooltip = <Tooltip id="info">{this.props.info}</Tooltip>;
var info = (
<OverlayTrigger placement='top' rootClose overlay={infoTooltip}>
<Icon className="cpri" name="info"/>
Expand All @@ -75,9 +73,9 @@ var ActionCell = React.createClass({
comment = (
<Comment
className="ml1/4"
readOnly={!self.props.canUpdateEntry || !canUpdateComment || isSaving}
value={self.state.entry.transTerm.comment}
onUpdateCommentCallback={self._onUpdateComment}/>
readOnly={!this.props.canUpdateEntry || !canUpdateComment || isSaving}
value={this.state.entry.transTerm.comment}
onUpdateCommentCallback={this._onUpdateComment}/>
);

if(isSaving) {
Expand All @@ -91,12 +89,12 @@ var ActionCell = React.createClass({

if(isTransModified) {
updateButton = (
<Button kind='primary' className='ml1/4' onClick={self._handleUpdate}>
<Button kind='primary' className='ml1/4' onClick={this._handleUpdate}>
Update
</Button>
);
cancelButton = (
<Button className='ml1/4' link onClick={self._handleCancel}>
<Button className='ml1/4' link onClick={this._handleCancel}>
Cancel
</Button>
);
Expand Down
18 changes: 10 additions & 8 deletions frontend/src/main/web/lib/components/glossary/DataTable.jsx
Expand Up @@ -16,6 +16,8 @@ var DataTable = React.createClass({

CONTENT_HASH_INDEX: 0,

loadTimeout: null,

ENTRY: {
SRC: {
col: 1,
Expand Down Expand Up @@ -87,13 +89,15 @@ var DataTable = React.createClass({
},

/**
* if top is undefined, table height will be calculated based on DOM height.
*
* @param fixedTop - gets the height from the DOM if this is not specified
* @param top - Number value of top height
*/
_getHeight: function(fixedTop) {
_getHeight: function(top) {
var footer = window.document.getElementById("footer");
var footerHeight = footer ? footer.clientHeight : 91;
var top = _.isUndefined(fixedTop) ? React.findDOMNode(this).offsetTop: fixedTop;

top = _.isUndefined(top) ? React.findDOMNode(this).offsetTop: top;
var newHeight = window.innerHeight - footerHeight - top;

//minimum height 250px
Expand Down Expand Up @@ -438,14 +442,12 @@ var DataTable = React.createClass({
_rowGetter: function(rowIndex) {
var row = this.props.glossaryHash[rowIndex];
if(_.isUndefined(row) || row === null) {
if(this.state.timeout !== null) {
clearTimeout(this.state.timeout);
if(this.loadTimeout !== null) {
clearTimeout(this.loadTimeout);
}

this.state.timeout = setTimeout(() => {
this.loadTimeout = setTimeout(() => {
Actions.loadGlossary(rowIndex);
}, this.TIMEOUT);

return [null];
} else {
return row;
Expand Down
17 changes: 9 additions & 8 deletions frontend/src/main/web/lib/components/glossary/InputCell.jsx
Expand Up @@ -16,7 +16,9 @@ var InputCell = React.createClass({
onBlurCallback: React.PropTypes.func
},

TIMEOUT: 100,
TIMEOUT: 150,

updateTimeout: null,

getInitialState: function() {
return this._getState();
Expand All @@ -30,8 +32,7 @@ var InputCell = React.createClass({

return {
value: value,
isFocused : isFocused,
timeout: null
isFocused : isFocused
}
},

Expand All @@ -50,13 +51,13 @@ var InputCell = React.createClass({
},

_onValueChange : function(event) {
var self = this,
value = event.target.value;
var value = event.target.value;
this.setState({value: value});
if(this.state.timeout !== null) {
clearTimeout(this.state.timeout);
if(this.updateTimeout !== null) {
clearTimeout(this.updateTimeout);
}
this.state.timeout = setTimeout(() => {
this.updateTimeout = setTimeout(() => {
console.info('update');
Actions.updateEntryField(this.props.contentHash, this.props.field, value);
}, this.TIMEOUT);
},
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/main/web/lib/stores/GlossaryStore.js
Expand Up @@ -300,7 +300,7 @@ var GlossaryStore = assign({}, EventEmitter.prototype, {
break;
case GlossaryActionTypes.UPDATE_FILTER:
console.debug('Update filter', action.data);
if(_state.filter !== action.data) {
if(_state.filter !== action.data) {
_state.filter = action.data;
refreshGlossaryEntries();
}
Expand Down
Expand Up @@ -43,7 +43,7 @@
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' === document.location.protocol ? 'https' : 'http') +
wf.src = (document.location.protocol === 'https:' ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
Expand Down

0 comments on commit 7bf615e

Please sign in to comment.