Skip to content

Commit

Permalink
add attribute listing demo
Browse files Browse the repository at this point in the history
  • Loading branch information
nsheff committed Aug 9, 2024
1 parent d0790b0 commit 3b26030
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 12 deletions.
23 changes: 21 additions & 2 deletions frontend/src/components/ObjectLists.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Link } from "react-router-dom"
import { useLoaderData } from "react-router-dom"


// Basic list of Sequence Collections
const CollectionList = ({collections}) => {
const seqColList = collections || useLoaderData()[0]
console.log("CollectionList", CollectionList)
console.log("seqColList", seqColList)

return (<>
<div>
Expand All @@ -18,6 +20,23 @@ const CollectionList = ({collections}) => {
)
}

const AttributeList = ({attributes}) => {
const attrList = attributes || useLoaderData()[0]
console.log("attrList", attrList)

return (<>
<div>
<ul>
{attrList.results.map((attr) => (
<li key={attr}>
Attribute: <Link to={`/attribute/sorted_name_length_pairs/${attr}`}>{attr}</Link>
</li>
))}
</ul>
</div></>
)
}


// Basic list of Pangenomes
const PangenomeList = ({pangenomes}) => {
Expand All @@ -39,5 +58,5 @@ const PangenomeList = ({pangenomes}) => {



export { CollectionList, PangenomeList }
export { AttributeList, CollectionList, PangenomeList }

20 changes: 11 additions & 9 deletions frontend/src/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ const fetchPangenomeLevels = async(digest, level="2", collated=true) => {
}

const fetchSeqColList = async() => {
const url = `${API_BASE}/list/collections?limit=10&offset=10`
const url2 = `${API_BASE}/list/pangenomes?limit=5`
const url = `${API_BASE}/list/collections?page_size=10&page=1`
const url2 = `${API_BASE}/list/pangenomes?page_size=5`
const url3 = `${API_BASE}/list/attributes/sorted_name_length_pairs?page_size=5`
let resps = [
fetch(url).then((response) => response.json()),
fetch(url2).then((response) => response.json())
fetch(url2).then((response) => response.json()),
fetch(url3).then((response) => response.json())
]
return Promise.all(resps)
}
Expand All @@ -79,8 +81,8 @@ const fecthComparison = async(digest1, digest2) => {
}

const fetchAttribute = async(attribute, digest) => {
const url = `${API_BASE}/attribute/${attribute}/${digest}/list`
const url2 = `${API_BASE}/attribute/${attribute}/${digest}`
const url = `${API_BASE}/list/collections/${attribute}/${digest}`
const url2 = `${API_BASE}/attribute/collection/${attribute}/${digest}`
let resps = [
fetch(url).then((response) => response.json()),
fetch(url2).then((response) => response.json())
Expand All @@ -93,9 +95,9 @@ const fetchAttribute = async(attribute, digest) => {
const Level1Collection = ({collection}) => {
return (
<div>
Names: <Link to={`/attribute/names/${collection.names}`}>{collection.names}</Link><br/>
Lengths: <Link to={`/attribute/lengths/${collection.lengths}`}>{collection.lengths}</Link><br/>
Sequences: <Link to={`/attribute/sequences/${collection.sequences}`}>{collection.sequences}</Link><br/>
Names: <Link to={`/attribute/collection/names/${collection.names}`}>{collection.names}</Link><br/>
Lengths: <Link to={`/attribute/collection/lengths/${collection.lengths}`}>{collection.lengths}</Link><br/>
Sequences: <Link to={`/attribute/collection/sequences/${collection.sequences}`}>{collection.sequences}</Link><br/>
</div>
)
}
Expand Down Expand Up @@ -185,7 +187,7 @@ const CollectionTable = ({collections}) => {
</tr>
</thead>
<tbody>
{seqColList["items"].map((collection) => (
{seqColList["results"].map((collection) => (
<tr key={collection}>
<td><LinkedCollectionDigest digest={collection.digest} clipboard={false}/></td>
<td className="tiny mx-2"><LinkedAttributeDigest attribute="names" digest={collection.names_digest} clipboard={false}/></td>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/AttributeView.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { CollectionList } from '../components/ObjectLists.jsx'
const AttributeView = () => {
const content = useLoaderData()
const { attribute, digest } = useParams()
const api_url = `${API_BASE}/attribute/${attribute}/${digest}`
const api_url = `${API_BASE}/attribute/collection/${attribute}/${digest}`
const api_url_list = `${API_BASE}/list/collections/${attribute}/${digest}`
let results = content[0]
let attribute_value = content[1]
Expand Down
11 changes: 11 additions & 0 deletions frontend/src/pages/HomePage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ import { PangenomeList } from '../components/ObjectLists.jsx'
import { CollectionList } from '../components/ObjectLists.jsx'
import { Link } from "react-router-dom";
import { useLoaderData } from "react-router-dom";
import { AttributeList } from '../components/ObjectLists';


const HomePage = () => {
const loaderData = useLoaderData()
console.log("HomePage loadData ", loaderData)
const collections = loaderData[0]
const pangenomes = loaderData[1]
const sorted_name_length_pairs = loaderData[2]

const PangenomeExamplesList = () => {
if (pangenomes.results[0]) {
Expand Down Expand Up @@ -54,6 +57,14 @@ const HomePage = () => {
</ul>
<PangenomeExamplesList/>

<h5 className="mt-4">4. List of sorted_name_length_pairs on this server:</h5>
<p className="text-muted fs-6">
The <span className="font-monospace text-success">/list/attributes</span> endpoint lets you retrieve
a list of all the values of a particular attribute hosted by this server.
</p>
<AttributeList attributes={sorted_name_length_pairs}/>


</div>
)
}
Expand Down

0 comments on commit 3b26030

Please sign in to comment.