-
Notifications
You must be signed in to change notification settings - Fork 55
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
Update demo to connect with MPI #267
Open
isaacguerreir
wants to merge
1
commit into
develop
Choose a base branch
from
feat/mpi-connector
base: develop
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.
+104
−1
Open
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ import { | |
Image, | ||
Input, | ||
Menu, | ||
Message, | ||
Sidebar, | ||
} from "semantic-ui-react"; | ||
import seqparse from "seqparse"; | ||
|
@@ -21,6 +22,7 @@ import { chooseRandomColor } from "../../src/colors"; | |
import { AnnotationProp, Primer, TranslationProp } from "../../src/elements"; | ||
import Header from "./Header"; | ||
import file from "./file"; | ||
import { useEffect, useState } from "react"; | ||
|
||
const viewerTypeOptions = [ | ||
{ key: "both", text: "Both", value: "both" }, | ||
|
@@ -29,6 +31,11 @@ const viewerTypeOptions = [ | |
{ key: "both_flip", text: "Both Flip", value: "both_flip" }, | ||
]; | ||
|
||
interface Message { | ||
positive: boolean | ||
visible: boolean | ||
} | ||
|
||
interface AppState { | ||
annotations: AnnotationProp[]; | ||
customChildren: boolean; | ||
|
@@ -45,6 +52,7 @@ interface AppState { | |
showSidebar: boolean; | ||
translations: TranslationProp[]; | ||
viewer: string; | ||
message: Message; | ||
zoom: number; | ||
} | ||
|
||
|
@@ -101,6 +109,10 @@ export default class App extends React.Component<any, AppState> { | |
{ end: 1147, name: "", start: 736 }, | ||
{ end: 1885, name: "ORF 2", start: 1165 }, | ||
], | ||
message: { | ||
positive: true, | ||
visible: false | ||
}, | ||
viewer: "both", | ||
zoom: 50, | ||
}; | ||
|
@@ -123,6 +135,34 @@ export default class App extends React.Component<any, AppState> { | |
this.setState({ showSelectionMeta: !showSelectionMeta }); | ||
}; | ||
|
||
sendToMPI = async () => { | ||
try { | ||
const { seq, name, annotations } = this.state; | ||
const response = await fetch(`https://mpi.f4hcvcnn7c36k.us-east-1.cs.amazonlightsail.com/sequences`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ seq, name, type: "dna", annotations }), | ||
}); | ||
const res = await response.json(); | ||
if (res.statusCode && res.statusCode != 201) { | ||
throw "Not possible to export sequence." | ||
} | ||
this.setState({ message: { positive: true, visible: true } }) | ||
} catch (e) { | ||
this.setState({ message: { positive: false, visible: true } }) | ||
} | ||
|
||
this.closeMessage() | ||
}; | ||
|
||
closeMessage = () => { | ||
setTimeout(() => { | ||
this.setState({ message: { positive: true, visible: false } }); | ||
}, 3000); | ||
}; | ||
|
||
handleHide = () => { | ||
this.setState({ showSidebar: false }); | ||
}; | ||
|
@@ -192,6 +232,7 @@ export default class App extends React.Component<any, AppState> { | |
|
||
return ( | ||
<div style={{ height: "100vh" }}> | ||
<Alert visible={this.state.message.visible} positive={this.state.message.positive} /> | ||
<Sidebar.Pushable className="sidebar-container"> | ||
<Sidebar | ||
animation="overlay" | ||
|
@@ -245,6 +286,7 @@ export default class App extends React.Component<any, AppState> { | |
showSelectionMeta={this.state.showSelectionMeta} | ||
toggleShowSelectionMeta={this.toggleShowSelectionMeta} | ||
toggleSidebar={this.toggleSidebar} | ||
sendToMPI={this.sendToMPI} | ||
/> | ||
<div id="seqviewer"> | ||
{this.state.seq && ( | ||
|
@@ -441,3 +483,25 @@ const SidebarFooter = () => ( | |
</p> | ||
</div> | ||
); | ||
|
||
const Alert = ({ visible, positive }) => { | ||
if (visible) { | ||
if (positive) { | ||
return ( | ||
<Message id="alert-message" positive> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: a version that uses less code could be something like:
|
||
<p> | ||
Sequence successfully exported to MPI. | ||
</p> | ||
</Message> | ||
); | ||
} | ||
return ( | ||
<Message id="alert-message" negative> | ||
<p> | ||
Error exporting sequence to MPI. Try again later. | ||
</p> | ||
</Message> | ||
); | ||
} | ||
}; | ||
|
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import * as React from "react"; | ||
import { Button, Icon, Image, Popup } from "semantic-ui-react"; | ||
|
||
const Header = ({ selection, showSelectionMeta, toggleShowSelectionMeta, toggleSidebar }) => ( | ||
const Header = ({ selection, showSelectionMeta, toggleShowSelectionMeta, toggleSidebar, sendToMPI }) => ( | ||
<div className="header" id="app-header"> | ||
<div id="header-primary"> | ||
<Popup | ||
|
@@ -17,6 +17,9 @@ const Header = ({ selection, showSelectionMeta, toggleShowSelectionMeta, toggleS | |
showSelectionMeta={showSelectionMeta} | ||
toggleShowSelectionMeta={toggleShowSelectionMeta} | ||
/> | ||
<ExportToMPI | ||
sendToMPI={sendToMPI} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: why passing this as a prop instead of just declaring the function here? |
||
/> | ||
<a href="https://github.com/Lattice-Automation/seqviz" id="github-link" rel="noopener noreferrer" target="_blank"> | ||
<Icon name="github" size="large" /> | ||
</a> | ||
|
@@ -40,6 +43,14 @@ const ToggleSelectionMetaButton = ({ showSelectionMeta, toggleShowSelectionMeta | |
</div> | ||
); | ||
|
||
const ExportToMPI = ({ sendToMPI }) => ( | ||
<div className="mpi-block"> | ||
<Button id="mpi-button" onClick={sendToMPI}> | ||
Export to MPI | ||
</Button> | ||
</div> | ||
); | ||
|
||
const SelectionMetaRow = ({ selection }) => { | ||
const { end, feature, length, start } = selection; | ||
const noneSelected = start === end; | ||
|
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
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.
If not visible doesn't return anything? If so, maybe we can remove the prop and do:
this.state.message.visible && <Alert positive={this.state.message.positive} />