Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-43859: Include link to notebook on GitHub #164

Merged
merged 4 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .changeset/calm-items-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'squareone': minor
---

Users can now download the Jupyter Notebook (ipynb) file that they are viewing, with the current parameters filled in. This enables further interactive exploration.
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.
1 change: 1 addition & 0 deletions apps/squareone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"dependencies": {
"@fontsource/source-sans-pro": "^4.5.11",
"@fortawesome/fontawesome-svg-core": "^6.3.0",
"@fortawesome/free-brands-svg-icons": "^6.5.2",
"@fortawesome/free-solid-svg-icons": "^6.3.0",
"@fortawesome/react-fontawesome": "^0.2.0",
"@lsst-sqre/global-css": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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>
<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
@@ -0,0 +1,25 @@
import styled from 'styled-components';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';

export default function IpynbDownloadLink({ url, sourcePath }) {
// get the filename from the sourcePath
const filename = sourcePath.split('/').pop();

return (
<StyledP>
<a href={url} title={filename} download={filename}>
<StyledFontAwesomeIcon icon="download" /> Download notebook
</a>
</StyledP>
);
}

const StyledP = styled.p`
margin-top: 2rem;
`;

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
Expand Up @@ -11,11 +11,15 @@ import Head from 'next/head';
import Error from 'next/error';

import useTimesSquarePage from '../../hooks/useTimesSquarePage';
import { TimesSquareUrlParametersContext } from '../TimesSquareUrlParametersProvider';
import TimesSquareParameters from '../TimesSquareParameters';
import ExecStats from './ExecStats';
import GitHubEditLink from './GitHubEditLink';
import IpynbDownloadLink from './IpynbDownloadLink';

export default function TimesSquareGitHubPagePanel({}) {
const { publicRuntimeConfig } = getConfig();
const { urlQueryString } = React.useContext(TimesSquareUrlParametersContext);
const pageData = useTimesSquarePage();

if (pageData.loading) {
Expand All @@ -27,6 +31,8 @@ export default function TimesSquareGitHubPagePanel({}) {

const { title, description } = pageData;

const ipynbDownloadUrl = `${pageData.renderedIpynbUrl}?${urlQueryString}`;

return (
<PagePanelContainer>
<Head>
Expand All @@ -37,8 +43,19 @@ export default function TimesSquareGitHubPagePanel({}) {
{description && (
<div dangerouslySetInnerHTML={{ __html: description.html }}></div>
)}
<GitHubEditLink
owner={pageData.github.owner}
repository={pageData.github.repository}
sourcePath={pageData.github.sourcePath}
/>

<TimesSquareParameters />

<IpynbDownloadLink
url={ipynbDownloadUrl}
sourcePath={pageData.github.sourcePath}
/>

<ExecStats />
</div>
</PagePanelContainer>
Expand Down
11 changes: 11 additions & 0 deletions apps/squareone/src/hooks/useTimesSquarePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ function useTimesSquarePage() {
const { tsPageUrl } = React.useContext(TimesSquareUrlParametersContext);
const { data, error } = useSWR(tsPageUrl, fetcher);

const githubInfo = data
? {
owner: data.github.owner ? data.github.owner : null,
repository: data.github.repository ? data.github.repository : null,
sourcePath: data.github.source_path ? data.github.source_path : null,
sidecarPath: data.github.sidecar_path ? data.github.sidecar_path : null,
}
: { owner: null, repository: null, sourcePath: null, sidecarPath: null };

return {
error: error,
loading: !error && !data,
Expand All @@ -18,6 +27,8 @@ function useTimesSquarePage() {
htmlUrl: data ? data.html_url : null,
htmlStatusUrl: data ? data.html_status_url : null,
htmlEventsUrl: data ? data.html_events_url : null,
renderedIpynbUrl: data ? data.rendered_url : null,
github: githubInfo,
};
}

Expand Down
4 changes: 4 additions & 0 deletions apps/squareone/src/styles/icons.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import {
faCircleCheck,
faCircleMinus,
faCodeCommit,
faDownload,
} from '@fortawesome/free-solid-svg-icons';
import { faGithub } from '@fortawesome/free-brands-svg-icons';

// Add icons to the global Font Awesome library
library.add(faAngleDown);
Expand All @@ -24,3 +26,5 @@ library.add(faCircleXmark);
library.add(faCircleCheck);
library.add(faCircleMinus);
library.add(faCodeCommit);
library.add(faDownload);
library.add(faGithub);
17 changes: 17 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading