make section H1s linkable
This commit is contained in:
parent
ab9dc8aa9c
commit
6fbb6f653c
@ -25,6 +25,7 @@
|
|||||||
"inherits": "^2.0.3",
|
"inherits": "^2.0.3",
|
||||||
"locale": "^0.1.0",
|
"locale": "^0.1.0",
|
||||||
"lodash.find": "^4.6.0",
|
"lodash.find": "^4.6.0",
|
||||||
|
"lodash.flatten": "^4.4.0",
|
||||||
"lodash.get": "^4.4.2",
|
"lodash.get": "^4.4.2",
|
||||||
"lodash.isempty": "^4.4.0",
|
"lodash.isempty": "^4.4.0",
|
||||||
"lodash.template": "^4.4.0",
|
"lodash.template": "^4.4.0",
|
||||||
|
@ -70,6 +70,11 @@ const arrowPosition = {
|
|||||||
right: '10%'
|
right: '10%'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const EmptyButton = styled.button`
|
||||||
|
background: none
|
||||||
|
border: none
|
||||||
|
`;
|
||||||
|
|
||||||
const Header = ({
|
const Header = ({
|
||||||
account = {},
|
account = {},
|
||||||
tooltip = false,
|
tooltip = false,
|
||||||
@ -114,7 +119,7 @@ const Header = ({
|
|||||||
>
|
>
|
||||||
<StyledProfileWrapper>
|
<StyledProfileWrapper>
|
||||||
<StyledAvatarWrapper toggled={tooltip}>
|
<StyledAvatarWrapper toggled={tooltip}>
|
||||||
<a onClick={handleToggleClick}>
|
<EmptyButton onClick={handleToggleClick}>
|
||||||
<StyledName>{account.name}</StyledName>
|
<StyledName>{account.name}</StyledName>
|
||||||
<Avatar
|
<Avatar
|
||||||
alt={account.name}
|
alt={account.name}
|
||||||
@ -124,7 +129,7 @@ const Header = ({
|
|||||||
marginLeft: '12px'
|
marginLeft: '12px'
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</a>
|
</EmptyButton>
|
||||||
</StyledAvatarWrapper>
|
</StyledAvatarWrapper>
|
||||||
{tooltipComponent}
|
{tooltipComponent}
|
||||||
</StyledProfileWrapper>
|
</StyledProfileWrapper>
|
||||||
@ -137,8 +142,8 @@ const Header = ({
|
|||||||
|
|
||||||
Header.propTypes = {
|
Header.propTypes = {
|
||||||
account: PropTypes.account,
|
account: PropTypes.account,
|
||||||
tooltip: React.PropTypes.boolean,
|
handleToggle: React.PropTypes.func,
|
||||||
handleToggle: React.PropTypes.func
|
tooltip: React.PropTypes.bool
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Header;
|
module.exports = Header;
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
|
const flatten = require('lodash.flatten');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const ReactIntl = require('react-intl');
|
const ReactIntl = require('react-intl');
|
||||||
const ReactRouter = require('react-router');
|
const ReactRouter = require('react-router');
|
||||||
|
|
||||||
const H1 = require('@ui/components/h1');
|
const H1 = require('@ui/components/h1');
|
||||||
const Li = require('@ui/components/horizontal-list/li');
|
const Li = require('@ui/components/horizontal-list/li');
|
||||||
|
const PropTypes = require('@root/prop-types');
|
||||||
const Ul = require('@ui/components/horizontal-list/ul');
|
const Ul = require('@ui/components/horizontal-list/ul');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -17,7 +19,7 @@ const {
|
|||||||
const Section = ({
|
const Section = ({
|
||||||
children,
|
children,
|
||||||
links = [],
|
links = [],
|
||||||
name = ''
|
name = []
|
||||||
}) => {
|
}) => {
|
||||||
const navLinks = links.map((link) => (
|
const navLinks = links.map((link) => (
|
||||||
<Li key={link.name}>
|
<Li key={link.name}>
|
||||||
@ -27,9 +29,28 @@ const Section = ({
|
|||||||
</Li>
|
</Li>
|
||||||
));
|
));
|
||||||
|
|
||||||
|
const nameLinks = flatten(name.map((part, i) => {
|
||||||
|
const link = (
|
||||||
|
<Link key={part.pathname} to={part.pathname}>
|
||||||
|
{part.name}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
|
||||||
|
const slash = (
|
||||||
|
<span key={`${part.pathname}${i}`}> / </span>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (i === 0) ? link : [
|
||||||
|
slash,
|
||||||
|
link
|
||||||
|
];
|
||||||
|
}));
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<H1>{name}</H1>
|
<H1>
|
||||||
|
{nameLinks}
|
||||||
|
</H1>
|
||||||
<Ul>
|
<Ul>
|
||||||
{navLinks}
|
{navLinks}
|
||||||
</Ul>
|
</Ul>
|
||||||
@ -40,13 +61,8 @@ const Section = ({
|
|||||||
|
|
||||||
Section.propTypes = {
|
Section.propTypes = {
|
||||||
children: React.PropTypes.node,
|
children: React.PropTypes.node,
|
||||||
links: React.PropTypes.arrayOf(
|
links: React.PropTypes.arrayOf(PropTypes.link),
|
||||||
React.PropTypes.shape({
|
name: React.PropTypes.arrayOf(PropTypes.link)
|
||||||
name: React.PropTypes.string,
|
|
||||||
pathname: React.PropTypes.string
|
|
||||||
})
|
|
||||||
),
|
|
||||||
name: React.PropTypes.string
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Section;
|
module.exports = Section;
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
const React = require('react');
|
|
||||||
const ReactRedux = require('react-redux');
|
const ReactRedux = require('react-redux');
|
||||||
|
|
||||||
const selectors = require('@state/selectors');
|
const selectors = require('@state/selectors');
|
||||||
const actions = require('@state/actions');
|
const actions = require('@state/actions');
|
||||||
const Header = require('@components/header');
|
const Header = require('@components/header');
|
||||||
const PropTypes = require('@root/prop-types');
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
connect
|
connect
|
||||||
@ -19,24 +17,6 @@ const {
|
|||||||
toggleHeaderTooltip
|
toggleHeaderTooltip
|
||||||
} = actions;
|
} = actions;
|
||||||
|
|
||||||
const Component = ({
|
|
||||||
account = {},
|
|
||||||
tooltip = false,
|
|
||||||
handleToggle
|
|
||||||
}) => (
|
|
||||||
<Header
|
|
||||||
account={account}
|
|
||||||
tooltip={tooltip}
|
|
||||||
handleToggle={handleToggle}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
|
|
||||||
Component.propTypes = {
|
|
||||||
account: PropTypes.account,
|
|
||||||
tooltip: React.PropTypes.bool,
|
|
||||||
handleToggle: React.PropTypes.func
|
|
||||||
};
|
|
||||||
|
|
||||||
const mapStateToProps = (state, ownProps) => ({
|
const mapStateToProps = (state, ownProps) => ({
|
||||||
account: accountSelector(state),
|
account: accountSelector(state),
|
||||||
...accountUISelector(state)
|
...accountUISelector(state)
|
||||||
|
@ -19,13 +19,18 @@ const OrgSection = ({
|
|||||||
org = {},
|
org = {},
|
||||||
sections = []
|
sections = []
|
||||||
}) => {
|
}) => {
|
||||||
const links = sections.map((name) => ({
|
const navLinks = sections.map((name) => ({
|
||||||
pathname: `/${org.id}/${name}`,
|
pathname: `/${org.id}/${name}`,
|
||||||
name
|
name
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const nameLinks = [{
|
||||||
|
pathname: `/${org.id}`,
|
||||||
|
name: org.name
|
||||||
|
}];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section links={links} name={org.name}>
|
<Section links={navLinks} name={nameLinks}>
|
||||||
{children}
|
{children}
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
@ -21,13 +21,11 @@ const OrgSection = ({
|
|||||||
project = {},
|
project = {},
|
||||||
sections = []
|
sections = []
|
||||||
}) => {
|
}) => {
|
||||||
const name = `${org.name} / ${project.name}`;
|
|
||||||
|
|
||||||
const pathname = (props) => (
|
const pathname = (props) => (
|
||||||
`/${props.org}/projects/${props.project}/${props.section}`
|
`/${props.org}/projects/${props.project}/${props.section}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const links = sections.map((name) => ({
|
const navLinks = sections.map((name) => ({
|
||||||
pathname: pathname({
|
pathname: pathname({
|
||||||
org: org.id,
|
org: org.id,
|
||||||
project: project.id,
|
project: project.id,
|
||||||
@ -36,8 +34,16 @@ const OrgSection = ({
|
|||||||
name
|
name
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const nameLinks = [{
|
||||||
|
pathname: `/${org.id}`,
|
||||||
|
name: org.name
|
||||||
|
}, {
|
||||||
|
pathname: `/${org.id}/projects/${project.id}`,
|
||||||
|
name: project.name
|
||||||
|
}];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section links={links} name={name}>
|
<Section links={navLinks} name={nameLinks}>
|
||||||
{children}
|
{children}
|
||||||
</Section>
|
</Section>
|
||||||
);
|
);
|
||||||
|
@ -40,8 +40,6 @@ const Service = ({
|
|||||||
sections = [],
|
sections = [],
|
||||||
service = {}
|
service = {}
|
||||||
}) => {
|
}) => {
|
||||||
const name = `${org.name} / ${project.name} / ${service.name}`;
|
|
||||||
|
|
||||||
const pathname = ({
|
const pathname = ({
|
||||||
org,
|
org,
|
||||||
project,
|
project,
|
||||||
@ -51,7 +49,14 @@ const Service = ({
|
|||||||
`/${org}/projects/${project}/services/${service}/${section}`
|
`/${org}/projects/${project}/services/${service}/${section}`
|
||||||
);
|
);
|
||||||
|
|
||||||
const links = sections.map((name) => ({
|
const redirectHref = pathname({
|
||||||
|
org: org.id,
|
||||||
|
project: project.id,
|
||||||
|
service: service.id,
|
||||||
|
section: 'summary'
|
||||||
|
});
|
||||||
|
|
||||||
|
const navLinks = sections.map((name) => ({
|
||||||
pathname: pathname({
|
pathname: pathname({
|
||||||
org: org.id,
|
org: org.id,
|
||||||
project: project.id,
|
project: project.id,
|
||||||
@ -61,6 +66,17 @@ const Service = ({
|
|||||||
name
|
name
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const nameLinks = [{
|
||||||
|
pathname: `/${org.id}`,
|
||||||
|
name: org.name
|
||||||
|
}, {
|
||||||
|
pathname: `/${org.id}/projects/${project.id}`,
|
||||||
|
name: project.name
|
||||||
|
}, {
|
||||||
|
pathname: redirectHref,
|
||||||
|
name: service.name
|
||||||
|
}];
|
||||||
|
|
||||||
const navMatches = sections.map((name) => (
|
const navMatches = sections.map((name) => (
|
||||||
<Match
|
<Match
|
||||||
component={SectionComponents[name]}
|
component={SectionComponents[name]}
|
||||||
@ -69,19 +85,13 @@ const Service = ({
|
|||||||
/>
|
/>
|
||||||
));
|
));
|
||||||
|
|
||||||
const redirectHref = pathname({
|
|
||||||
org: org.id,
|
|
||||||
project: project.id,
|
|
||||||
service: service.id,
|
|
||||||
section: 'summary'
|
|
||||||
});
|
|
||||||
|
|
||||||
const missMatch = !sections.length ? null : (
|
const missMatch = !sections.length ? null : (
|
||||||
<Miss component={Redirect(redirectHref)} />
|
<Miss component={Redirect(redirectHref)} />
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Section links={links} name={name}>
|
<Section links={navLinks} name={nameLinks}>
|
||||||
{navMatches}
|
{navMatches}
|
||||||
{missMatch}
|
{missMatch}
|
||||||
</Section>
|
</Section>
|
||||||
|
@ -10,6 +10,11 @@ const Account = React.PropTypes.shape({
|
|||||||
...BaseObject
|
...BaseObject
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const Link = React.PropTypes.shape({
|
||||||
|
name: React.PropTypes.string,
|
||||||
|
pathname: React.PropTypes.string
|
||||||
|
});
|
||||||
|
|
||||||
const Org = React.PropTypes.shape({
|
const Org = React.PropTypes.shape({
|
||||||
...BaseObject,
|
...BaseObject,
|
||||||
owner: React.PropTypes.string
|
owner: React.PropTypes.string
|
||||||
@ -29,6 +34,7 @@ const Sections = React.PropTypes.arrayOf(
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
account: Account,
|
account: Account,
|
||||||
|
link: Link,
|
||||||
org: Org,
|
org: Org,
|
||||||
project: Project,
|
project: Project,
|
||||||
sections: Sections,
|
sections: Sections,
|
||||||
|
@ -3529,7 +3529,7 @@ lodash.find@^4.6.0:
|
|||||||
version "4.6.0"
|
version "4.6.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1"
|
resolved "https://registry.yarnpkg.com/lodash.find/-/lodash.find-4.6.0.tgz#cb0704d47ab71789ffa0de8b97dd926fb88b13b1"
|
||||||
|
|
||||||
lodash.flatten@^4.2.0:
|
lodash.flatten, lodash.flatten@^4.2.0:
|
||||||
version "4.4.0"
|
version "4.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
|
resolved "https://registry.yarnpkg.com/lodash.flatten/-/lodash.flatten-4.4.0.tgz#f31c22225a9632d2bbf8e4addbef240aa765a61f"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user