-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This shows the execution status, including the age of the execution and execution duration if available. It's also where we put the button to request a recomputation of an existing page. The component's data is populated by the TimesSquareHtmlEventsContext. We show how to mock the context in Storybook to design different states.
- Loading branch information
1 parent
66fe54a
commit 54da6c3
Showing
5 changed files
with
121 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
apps/squareone/src/components/TimesSquareGitHubPagePanel/ExecStats.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* ExecStats provides a summary of the execution status and timing of the | ||
* notebook execution. It also provides a button to request the recomputation | ||
* of the already-executed notebook. | ||
*/ | ||
|
||
import React from 'react'; | ||
import styled from 'styled-components'; | ||
import { parseISO, formatDistanceToNow } from 'date-fns'; | ||
|
||
import { TimesSquareHtmlEventsContext } from '../TimesSquareHtmlEventsProvider'; | ||
import { GhostButton } from '../Button'; | ||
|
||
export default function ExecStats({}) { | ||
const htmlEvent = React.useContext(TimesSquareHtmlEventsContext); | ||
|
||
if (htmlEvent.executionStatus == 'complete') { | ||
const dateFinished = parseISO(htmlEvent.dateFinished); | ||
return ( | ||
<StyledContainer> | ||
<p> | ||
Computed{' '} | ||
<time | ||
dateTime={htmlEvent.dateFinished} | ||
title={htmlEvent.dateFinished} | ||
> | ||
{formatDistanceToNow(dateFinished, { addSuffix: true })} | ||
</time>{' '} | ||
in {htmlEvent.executionDuration} seconds. | ||
</p> | ||
<GhostButton onClick={() => console.log('Recompute')}> | ||
Recompute | ||
</GhostButton> | ||
</StyledContainer> | ||
); | ||
} | ||
|
||
if (htmlEvent.executionStatus == 'in_progress') { | ||
return ( | ||
<StyledContainer> | ||
<p>Computing…</p> | ||
</StyledContainer> | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
const StyledContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
margin-top: 1rem; | ||
`; |
56 changes: 56 additions & 0 deletions
56
apps/squareone/src/components/TimesSquareGitHubPagePanel/ExecStats.stories.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React from 'react'; | ||
|
||
import { TimesSquareHtmlEventsContext } from '../TimesSquareHtmlEventsProvider'; | ||
import ExecStats from './ExecStats'; | ||
|
||
export default { | ||
component: ExecStats, | ||
title: 'Components/TimesSquare/ExecStats', | ||
parameters: { | ||
viewport: { | ||
viewports: { | ||
sidebar: { | ||
name: 'Sidebar', | ||
styles: { | ||
width: '280px', | ||
height: '900px', | ||
}, | ||
}, | ||
}, | ||
}, | ||
defaultViewport: 'sidebar', | ||
}, | ||
}; | ||
|
||
const Template = (args) => ( | ||
<TimesSquareHtmlEventsContext.Provider value={args}> | ||
<ExecStats /> | ||
</TimesSquareHtmlEventsContext.Provider> | ||
); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { | ||
dateSubmitted: '2021-09-01T12:00:00Z', | ||
dateStarted: '2021-09-01T12:00:01Z', | ||
dateFinished: '2021-09-01T12:00:10Z', | ||
executionStatus: 'complete', | ||
executionDuration: 10.12, | ||
}; | ||
|
||
export const InProgressNew = Template.bind({}); | ||
InProgressNew.args = { | ||
dateSubmitted: '2021-09-01T12:00:10Z', | ||
dateStarted: null, | ||
dateFinished: null, | ||
executionStatus: 'in_progress', | ||
executionDuration: null, | ||
}; | ||
|
||
export const InProgressExisting = Template.bind({}); | ||
InProgressExisting.args = { | ||
dateSubmitted: '2021-09-01T12:00:00Z', | ||
dateStarted: '2021-09-01T12:00:01Z', | ||
dateFinished: '2021-09-01T12:00:10Z', | ||
executionStatus: 'in_progress', | ||
executionDuration: 10.12, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.