-
Notifications
You must be signed in to change notification settings - Fork 0
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
Eda notebook #1283
Draft
dmfalke
wants to merge
4
commits into
main
Choose a base branch
from
eda-notebook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Eda notebook #1283
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
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
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,116 @@ | ||
.EdaNotebook { | ||
.Heading { | ||
display: flex; | ||
gap: 2em; | ||
align-items: baseline; | ||
} | ||
|
||
.Paper { | ||
/* A4 dimensions */ | ||
--paper-width: 2480px; | ||
--paper-height: 3508px; | ||
--paper-scale: 0.5; | ||
|
||
width: calc(var(--paper-width) * var(--paper-scale)); | ||
/* height: calc(var(--paper-height) * var(--paper-scale)); */ | ||
|
||
padding: 2em; | ||
margin: 1em auto; | ||
|
||
/* background-color: #f3f3f3; */ | ||
box-shadow: 0 0 2px #b5b5b5; | ||
|
||
> * + * { | ||
margin-block-start: 1rem; | ||
} | ||
|
||
.Heading { | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: space-between; | ||
gap: 0.5em; | ||
|
||
h1 { | ||
padding: 0; | ||
font-size: 1.75em; | ||
} | ||
|
||
h2 { | ||
font-size: 1em; | ||
font-weight: bold; | ||
padding: 0.25em 0.5em; | ||
color: var(--coreui-color-primary, black); | ||
border: 2px solid; | ||
border-radius: 0.25em; | ||
background-color: color-mix( | ||
in srgb, | ||
var(--coreui-color-primary) 5%, | ||
transparent | ||
); | ||
} | ||
} | ||
|
||
> details { | ||
border: 1px solid; | ||
border-color: color-mix( | ||
in srgb, | ||
var(--coreui-color-primary) 30%, | ||
transparent | ||
); | ||
border-top-left-radius: 0.5em; | ||
border-top-right-radius: 0.5em; | ||
border-bottom-left-radius: 0.5em; | ||
border-bottom-right-radius: 0.5em; | ||
|
||
> summary { | ||
padding: 0.75em; | ||
cursor: pointer; | ||
font-size: 1.2em; | ||
font-weight: 500; | ||
background-color: color-mix( | ||
in srgb, | ||
var(--coreui-color-primary) 10%, | ||
transparent | ||
); | ||
|
||
&:hover { | ||
background-color: color-mix( | ||
in srgb, | ||
var(--coreui-color-primary) 20%, | ||
transparent | ||
); | ||
} | ||
|
||
&:active { | ||
background-color: color-mix( | ||
in srgb, | ||
var(--coreui-color-primary) 15%, | ||
transparent | ||
); | ||
} | ||
|
||
transition: background-color 100ms ease-in; | ||
} | ||
|
||
&[open] > summary { | ||
border-bottom: 1px solid; | ||
border-color: color-mix( | ||
in srgb, | ||
var(--coreui-color-primary) 30%, | ||
transparent | ||
); | ||
} | ||
|
||
> div { | ||
padding: 1em; | ||
} | ||
} | ||
} | ||
|
||
.Title { | ||
fieldset { | ||
padding: 0; | ||
margin: 0; | ||
} | ||
} | ||
} |
97 changes: 97 additions & 0 deletions
97
packages/libs/eda/src/lib/notebook/EdaNotebookAnalysis.tsx
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,97 @@ | ||
// Notes | ||
// ===== | ||
// | ||
// - For now, we will only support "fixed" notebooks. If we want to allow "custom" notebooks, | ||
// we have to make some decisions. | ||
// - Do we want a top-down data flow? E.g., subsetting is global for an analysis. | ||
// - Do we want to separate compute config from visualization? If so, how do we | ||
// support that in the UI? | ||
// - Do we want text-based cells? | ||
// - Do we want download cells? It could have a preview. | ||
// | ||
|
||
import React, { useCallback, useMemo } from 'react'; | ||
import { useAnalysis, useStudyRecord } from '../core'; | ||
import { safeHtml } from '@veupathdb/wdk-client/lib/Utils/ComponentUtils'; | ||
import { SaveableTextEditor } from '@veupathdb/wdk-client/lib/Components'; | ||
import { ExpandablePanel } from '@veupathdb/coreui'; | ||
import { NotebookCell as NotebookCellType } from './Types'; | ||
import { NotebookCell } from './NotebookCell'; | ||
|
||
import './EdaNotebook.css'; | ||
|
||
interface NotebookSettings { | ||
/** Ordered array of notebook cells */ | ||
cells: NotebookCellType[]; | ||
} | ||
|
||
const NOTEBOOK_UI_SETTINGS_KEY = '@@NOTEBOOK@@'; | ||
|
||
interface Props { | ||
analysisId: string; | ||
} | ||
|
||
export function EdaNotebookAnalysis(props: Props) { | ||
const { analysisId } = props; | ||
const studyRecord = useStudyRecord(); | ||
const analysisState = useAnalysis( | ||
analysisId === 'new' ? undefined : analysisId | ||
); | ||
const { analysis } = analysisState; | ||
const notebookSettings = useMemo((): NotebookSettings => { | ||
const storedSettings = | ||
analysis?.descriptor.subset.uiSettings[NOTEBOOK_UI_SETTINGS_KEY]; | ||
if (storedSettings == null) | ||
return { | ||
cells: [ | ||
{ | ||
type: 'subset', | ||
title: 'Subset data', | ||
}, | ||
], | ||
}; | ||
return storedSettings as any as NotebookSettings; | ||
}, [analysis]); | ||
const updateCell = useCallback( | ||
(cell: Partial<Omit<NotebookCellType, 'type'>>, cellIndex: number) => { | ||
const oldCell = notebookSettings.cells[cellIndex]; | ||
const newCell = { ...oldCell, ...cell }; | ||
const nextCells = notebookSettings.cells.concat(); | ||
nextCells[cellIndex] = newCell; | ||
const nextSettings = { | ||
...notebookSettings, | ||
cells: nextCells, | ||
}; | ||
analysisState.setVariableUISettings({ | ||
[NOTEBOOK_UI_SETTINGS_KEY]: nextSettings, | ||
}); | ||
}, | ||
[analysisState, notebookSettings] | ||
); | ||
return ( | ||
<div className="EdaNotebook"> | ||
<div className="Paper"> | ||
<div className="Heading"> | ||
<h1> | ||
<SaveableTextEditor | ||
className="Title" | ||
value={analysisState.analysis?.displayName ?? ''} | ||
onSave={analysisState.setName} | ||
/> | ||
</h1> | ||
<h2>{safeHtml(studyRecord.displayName)}</h2> | ||
</div> | ||
{notebookSettings.cells.map((cell, index) => ( | ||
<details> | ||
<summary>{cell.title}</summary> | ||
<NotebookCell | ||
analysisState={analysisState} | ||
cell={cell} | ||
updateCell={(update) => updateCell(update, index)} | ||
/> | ||
</details> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} |
37 changes: 37 additions & 0 deletions
37
packages/libs/eda/src/lib/notebook/EdaNotebookLandingPage.tsx
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,37 @@ | ||
import React from 'react'; | ||
import { useWdkStudyRecords } from '../core/hooks/study'; | ||
import { useConfiguredSubsettingClient } from '../core/hooks/client'; | ||
import { Link, useRouteMatch } from 'react-router-dom'; | ||
import { safeHtml } from '@veupathdb/wdk-client/lib/Utils/ComponentUtils'; | ||
|
||
interface Props { | ||
edaServiceUrl: string; | ||
} | ||
|
||
export function EdaNotebookLandingPage(props: Props) { | ||
const subsettingClient = useConfiguredSubsettingClient(props.edaServiceUrl); | ||
const datasets = useWdkStudyRecords(subsettingClient); | ||
const { url } = useRouteMatch(); | ||
return ( | ||
<div> | ||
<h1>EDA Notebooks</h1> | ||
<div> | ||
<h2>Start a new notebook</h2> | ||
<ul> | ||
{datasets?.map((dataset) => ( | ||
<li> | ||
{safeHtml( | ||
dataset.displayName, | ||
{ to: `${url}/${dataset.attributes.dataset_id as string}/new` }, | ||
Link | ||
)} | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
<hr /> | ||
<div>MY NOTEBOOKS</div> | ||
<div>SHARED NOTEBOOKS</div> | ||
</div> | ||
); | ||
} |
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,28 @@ | ||
import { AnalysisState } from '../core'; | ||
import { NotebookCell as NotebookCellType } from './Types'; | ||
import { SubsettingNotebookCell } from './SubsettingNotebookCell'; | ||
|
||
interface Props { | ||
analysisState: AnalysisState; | ||
cell: NotebookCellType; | ||
updateCell: (cell: Partial<Omit<NotebookCellType, 'type'>>) => void; | ||
} | ||
|
||
/** | ||
* Top-level component that delegates to imeplementations of NotebookCell variants. | ||
*/ | ||
export function NotebookCell(props: Props) { | ||
const { cell, analysisState, updateCell } = props; | ||
switch (cell.type) { | ||
case 'subset': | ||
return ( | ||
<SubsettingNotebookCell | ||
cell={cell} | ||
analysisState={analysisState} | ||
updateCell={updateCell} | ||
/> | ||
); | ||
default: | ||
return null; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was breaking keyboard accessibility.