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

Tooltips with react-intl #4549

Merged
merged 4 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
68 changes: 48 additions & 20 deletions js/src/ui/Tooltips/Tooltip/tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import { FlatButton } from 'material-ui';
import ActionDoneAll from 'material-ui/svg-icons/action/done-all';
import ContentClear from 'material-ui/svg-icons/content/clear';
import NavigationArrowForward from 'material-ui/svg-icons/navigation/arrow-forward';

import { CancelIcon, DoneIcon, NextIcon } from '~/ui/Icons';
import { nodeOrStringProptype } from '~/util/proptypes';

import { newTooltip, nextTooltip, closeTooltips } from '../actions';

Expand All @@ -30,15 +31,15 @@ let tooltipId = 0;

class Tooltip extends Component {
static propTypes = {
title: PropTypes.string,
text: PropTypes.string,
right: PropTypes.bool,
className: PropTypes.string,
currentId: PropTypes.number,
maxId: PropTypes.number,
className: PropTypes.string,
right: PropTypes.bool,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@jacogr jacogr Feb 15, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funnily enough, I played with that some weeks ago - it does some nice stuff, e.g. required first, then normal, then handlers (onSomething) - obviously all ordered. (Or you can just order without caring about the type)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So shouldn't we use it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should, the only reason I have not pulled it in as part of one of my eslint updates (yet) is that we are basically wrong in 70% of the cases. So lot of small little niggly updates, just didn't have the time to fiddle.

Medium-term, I would love to.

onNewTooltip: PropTypes.func,
onNextTooltip: PropTypes.func,
onCloseTooltips: PropTypes.func
onCloseTooltips: PropTypes.func,
text: nodeOrStringProptype(),
title: nodeOrStringProptype()
}

state = {
Expand All @@ -54,8 +55,7 @@ class Tooltip extends Component {

render () {
const { id } = this.state;
const { className, currentId, maxId, right, onCloseTooltips, onNextTooltip } = this.props;
const classes = `${styles.box} ${right ? styles.arrowRight : styles.arrowLeft} ${className}`;
const { className, currentId, maxId, right, onCloseTooltips, onNextTooltip, text, title } = this.props;

if (id !== currentId) {
return null;
Expand All @@ -64,32 +64,57 @@ class Tooltip extends Component {
const buttons = id !== maxId
? [
<FlatButton
icon={ <CancelIcon /> }
key='skipButton'
icon={ <ContentClear /> }
label='Skip'
label={
<FormattedMessage
id='ui.tooltips.button.skip'
defaultMessage='Skip'
/>
}
onTouchTap={ onCloseTooltips }
/>,
<FlatButton
icon={ <NextIcon /> }
key='nextButton'
icon={ <NavigationArrowForward /> }
label='Next'
label={
<FormattedMessage
id='ui.tooltips.button.next'
defaultMessage='Next'
/>
}
onTouchTap={ onNextTooltip }
/>
] : (
<FlatButton
icon={ <ActionDoneAll /> }
label='Done'
icon={ <DoneIcon /> }
label={
<FormattedMessage
id='ui.tooltips.button.done'
defaultMessage='Done'
/>
}
onTouchTap={ onCloseTooltips }
/>
);

return (
<div className={ classes }>
<div
className={
[
styles.box,
right
? styles.arrowRight
: styles.arrowLeft,
className
].join(' ')
}
>
<div className={ styles.title }>
{ this.props.title }
{ title }
</div>
<div className={ styles.text }>
{ this.props.text }
{ text }
</div>
<div className={ styles.buttons }>
{ buttons }
Expand All @@ -102,7 +127,10 @@ class Tooltip extends Component {
function mapStateToProps (state) {
const { currentId, maxId } = state.tooltip;

return { currentId, maxId };
return {
currentId,
maxId
};
}

function mapDispatchToProps (dispatch) {
Expand Down
68 changes: 68 additions & 0 deletions js/src/ui/Tooltips/Tooltip/tooltip.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React from 'react';
import { shallow } from 'enzyme';
import sinon from 'sinon';

import Tooltip from './';

let component;
let store;

function createRedux (currentId = 0) {
store = {
dispatch: sinon.stub(),
subscribe: sinon.stub(),
getState: () => {
return {
tooltip: {
currentId,
maxId: 2
}
};
}
};

return store;
}

function render () {
component = shallow(
<Tooltip />,
{
context: {
store: createRedux()
}
}
).find('Tooltip').shallow();

return component;
}

describe('ui/Tooltips/Tooltip', () => {
beforeEach(() => {
render();
});

it('renders defaults', () => {
expect(component.get(0)).to.be.ok;
});

it('renders null when id !== currentId', () => {
expect(render(1).get(0)).to.be.null;
});
});
7 changes: 3 additions & 4 deletions js/src/ui/Tooltips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import Tooltip from './Tooltip';
import tooltipReducer from './reducers';

export default from './tooltips';
export { Tooltip, tooltipReducer };

export Tooltip from './Tooltip';
export tooltipReducer from './reducers';
5 changes: 3 additions & 2 deletions js/src/ui/Tooltips/tooltips.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Tooltips extends Component {

static propTypes = {
currentId: PropTypes.number,
closed: PropTypes.bool,
onNextTooltip: PropTypes.func
}

Expand Down Expand Up @@ -72,7 +71,9 @@ class Tooltips extends Component {
function mapStateToProps (state) {
const { currentId } = state.tooltip;

return { currentId };
return {
currentId
};
}

function mapDispatchToProps (dispatch) {
Expand Down
76 changes: 76 additions & 0 deletions js/src/ui/Tooltips/tooltips.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2015-2017 Parity Technologies (UK) Ltd.
// This file is part of Parity.

// Parity is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.

// Parity is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import { shallow } from 'enzyme';
import React from 'react';
import sinon from 'sinon';

import Tooltips from './';

let component;
let router;
let store;

function createRedux () {
store = {
dispatch: sinon.stub(),
subscribe: sinon.stub(),
getState: () => {
return {
tooltip: {
currentId: 1
}
};
}
};

return store;
}

function createRouter () {
router = {
push: sinon.stub()
};

return router;
}

function render () {
component = shallow(
<Tooltips />,
{
context: {
store: createRedux()
}
}
).find('Tooltips').shallow({
context: {
router: createRouter()
}
});

return component;
}

describe('ui/Tooltips', () => {
beforeEach(() => {
render();
});

it('renders defaults', () => {
expect(component.get(0)).to.be.ok;
});
});
15 changes: 13 additions & 2 deletions js/src/views/Accounts/accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

import React, { Component, PropTypes } from 'react';
import { FormattedMessage } from 'react-intl';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import ContentAdd from 'material-ui/svg-icons/content/add';
Expand Down Expand Up @@ -88,7 +89,12 @@ class Accounts extends Component {
<Page>
<Tooltip
className={ styles.accountTooltip }
text='your accounts are visible for easy access, allowing you to edit the meta information, make transfers, view transactions and fund the account'
text={
<FormattedMessage
id='accounts.tooltip.overview'
defaultMessage='your accounts are visible for easy access, allowing you to edit the meta information, make transfers, view transactions and fund the account'
/>
}
/>

{ this.renderWallets() }
Expand Down Expand Up @@ -228,7 +234,12 @@ class Accounts extends Component {
<Tooltip
className={ styles.toolbarTooltip }
right
text='actions relating to the current view are available on the toolbar for quick access, be it for performing actions or creating a new item'
text={
<FormattedMessage
id='accounts.tooltip.actions'
defaultMessage='actions relating to the current view are available on the toolbar for quick access, be it for performing actions or creating a new item'
/>
}
/>
</Actionbar>
);
Expand Down
7 changes: 2 additions & 5 deletions js/src/views/Application/TabBar/Tab/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ const SIGNER_ID = 'signer';

export default class Tab extends Component {
static propTypes = {
children: PropTypes.node,
pendings: PropTypes.number,
view: PropTypes.object.isRequired
};

render () {
const { view, children } = this.props;
const { view } = this.props;

return (
<MUITab
Expand All @@ -42,9 +41,7 @@ export default class Tab extends Component {
? this.renderSignerLabel()
: this.renderLabel(view.id)
}
>
{ children }
</MUITab>
/>
);
}

Expand Down
1 change: 0 additions & 1 deletion js/src/views/Application/TabBar/Tab/tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ let instance;
function render (id = 'signer') {
component = shallow(
<Tab
children={ <div>testChildren</div> }
pending={ 5 }
view={ { id } }
/>
Expand Down
4 changes: 2 additions & 2 deletions js/src/views/Application/TabBar/tabBar.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
}

.tabbarTooltip {
left: 3.3em;
top: 0.5em;
left: 3em;
top: 4em;
}

.label {
Expand Down
Loading