-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathsite-link.js
68 lines (55 loc) · 1.44 KB
/
site-link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/** @format */
/**
* External dependencies
*/
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
/**
* Internal dependencies
*/
import contextTypes from '../context-types';
import { getSelectedSiteId } from 'state/ui/selectors';
import { getSiteSlug } from 'state/sites/selectors';
import Button from 'components/button';
class SiteLink extends Component {
static propTypes = {
href: PropTypes.string,
isButton: PropTypes.bool,
};
static defaultProps = {
isButton: false,
};
static contextTypes = contextTypes;
onClick = event => {
this.props.onClick && this.props.onClick( event );
const { quit, tour, tourVersion, step, isLastStep } = this.context;
quit( { tour, tourVersion, step, isLastStep } );
};
render() {
const { children, href, siteSlug, isButton } = this.props;
const siteHref = href.replace( ':site', siteSlug );
if ( isButton ) {
return (
<Button primary onClick={ this.onClick } href={ siteHref }>
{ children }
</Button>
);
}
return (
<a onClick={ this.onClick } href={ siteHref } className="config-elements__text-link">
{ children }
</a>
);
}
}
const mapStateToProps = state => {
const siteId = getSelectedSiteId( state );
const siteSlug = getSiteSlug( state, siteId );
return { siteId, siteSlug };
};
const mapDispatchToProps = null;
export default connect(
mapStateToProps,
mapDispatchToProps
)( SiteLink );