Skip to content

Commit

Permalink
fix: move link query update template to use new page context
Browse files Browse the repository at this point in the history
  • Loading branch information
vpicone committed Jul 17, 2019
1 parent 98ddefd commit 53a344c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 34 deletions.
55 changes: 34 additions & 21 deletions packages/gatsby-theme-carbon/src/components/EditLink/EditLink.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,51 @@
import React from 'react';
import PropTypes from 'prop-types';
import { graphql, useStaticQuery } from 'gatsby';

import { link, row } from './EditLink.module.scss';

export default class EditLink extends React.Component {
render() {
const {
repository: { baseUrl, subDirectory },
slug,
fileType,
} = this.props;
const href = `${baseUrl}/tree/master${subDirectory}/src/pages${slug}.${fileType}`;
const EditLink = ({ relativePagePath }) => {
const {
site: {
siteMetadata: { repository },
},
} = useStaticQuery(graphql`
query REPOSITORY_QUERY {
site {
siteMetadata {
repository {
baseUrl
subDirectory
}
}
}
}
`);

return baseUrl ? (
<div className={`bx--row ${row}`}>
<div className="bx--col">
<a className={link} href={href}>
Edit this page on GitHub
</a>
</div>
const { baseUrl, subDirectory } = repository;
const href = `${baseUrl}/tree/master${subDirectory}/src/pages${relativePagePath}`;

return baseUrl ? (
<div className={`bx--row ${row}`}>
<div className="bx--col">
<a className={link} href={href}>
Edit this page on GitHub
</a>
</div>
) : null;
}
}
</div>
) : null;
};

EditLink.propTypes = {
repository: PropTypes.shape({
baseUrl: PropTypes.string,
subDirectory: PropTypes.string,
}),
fileType: PropTypes.string,
slug: PropTypes.string.isRequired,
relativePagePath: PropTypes.string,
};

EditLink.defaultProps = {
fileType: 'mdx',
relativePagePath: '/index.mdx',
};

export default EditLink;
16 changes: 3 additions & 13 deletions packages/gatsby-theme-carbon/src/templates/Default.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,18 @@ import PageTabs from '../components/PageTabs';
import Main from '../components/Main';

const Default = ({ pageContext, children, location }) => {
const { frontmatter = {} } = pageContext;
const { frontmatter = {}, relativePagePath } = pageContext;
const { tabs, title } = frontmatter;
const scrollDirection = useScrollDirection();
const shouldHideHeader = !!tabs && scrollDirection === 'down';

// get the path prefix if it exists
const {
site: {
pathPrefix,
siteMetadata: { repository },
},
site: { pathPrefix },
} = useStaticQuery(graphql`
query PATH_PREFIX_QUERY {
site {
pathPrefix
siteMetadata {
repository {
baseUrl
subDirectory
}
}
}
}
`);
Expand Down Expand Up @@ -61,9 +52,8 @@ const Default = ({ pageContext, children, location }) => {
</PageHeader>
<Main padded>
{children}
<EditLink repository={repository} slug={slug} />
<EditLink relativePagePath={relativePagePath} />
</Main>

<NextPrevious
pageContext={pageContext}
location={location}
Expand Down

0 comments on commit 53a344c

Please sign in to comment.