Skip to content

Commit

Permalink
Add GitHubEditLink component
Browse files Browse the repository at this point in the history
This component links to the notebook in GitHub. Currently it assumes
we're referencing the "main" branch; to fix that we'd have to store the
default branch in Times Square to serve from its API.
  • Loading branch information
jonathansick committed Apr 11, 2024
1 parent 9e169a6 commit 570c660
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/smart-pandas-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'squareone': minor
---

Times Square notebook pages show a link to the source notebook on GitHub.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import styled from 'styled-components';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

export default function GitHubEditLink({ owner, repository, sourcePath }) {
if (!owner || !repository || !sourcePath) {
return null;
}

const editUrl = `https://github.com/${owner}/${repository}/blob/main/${sourcePath}`;

return (
<p>
Edit in{' '}
<a href={editUrl}>
<StyledFontAwesomeIcon icon="fa-brands fa-github" />
{owner}/{repository}
</a>
</p>
);
}

const StyledFontAwesomeIcon = styled(FontAwesomeIcon)`
margin-right: 0.2em;
font-size: 1em;
color: ${(props) => props.color || 'inherit'};
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React from 'react';

import GitHubEditLink from './GitHubEditLink';

export default {
component: GitHubEditLink,
title: 'Components/TimesSquare/GitHubEditLink',
parameters: {
viewport: {
viewports: {
sidebar: {
name: 'Sidebar',
styles: {
width: '280px',
height: '900px',
},
},
},
},
defaultViewport: 'sidebar',
},
};

const Template = (args) => <GitHubEditLink {...args} />;

export const Default = Template.bind({});
Default.args = {
owner: 'lsst-sqre',
repository: 'times-square-demo',
sourcePath: 'demo.ipynb',
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Error from 'next/error';
import useTimesSquarePage from '../../hooks/useTimesSquarePage';
import TimesSquareParameters from '../TimesSquareParameters';
import ExecStats from './ExecStats';
import GitHubEditLink from './GitHubEditLink';

export default function TimesSquareGitHubPagePanel({}) {
const { publicRuntimeConfig } = getConfig();
Expand All @@ -37,6 +38,12 @@ export default function TimesSquareGitHubPagePanel({}) {
{description && (
<div dangerouslySetInnerHTML={{ __html: description.html }}></div>
)}
<GitHubEditLink
owner={pageData.github.owner}
repo={pageData.github.repository}
sourcePath={pageData.github.sourcePath}
/>

<TimesSquareParameters />

<ExecStats />
Expand Down

0 comments on commit 570c660

Please sign in to comment.