-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CELE-17 feat: Update global context properties
- Loading branch information
1 parent
71b5aff
commit 09380d5
Showing
7 changed files
with
101 additions
and
63 deletions.
There are no files selected for viewing
43 changes: 15 additions & 28 deletions
43
applications/visualizer/frontend/src/components/LeftComponent.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 |
---|---|---|
@@ -1,46 +1,33 @@ | ||
import {Box, Button, Typography} from "@mui/material"; | ||
import { useEffect, useState } from "react"; | ||
import { Dataset, DatasetsService, HeathcheckService, Neuron, NeuronsService } from "../rest"; | ||
import {Box, Typography} from "@mui/material"; | ||
|
||
export default function LeftComponent() { | ||
const [ready, setReady] = useState("Not ready") | ||
const [dataset, setDataset] = useState<Dataset>() | ||
const [allDataset, setAllDataset] = useState<Dataset[]>() | ||
const [currentPage, setCurrentPage] = useState<{page: number, loadedElements: number, totalElements: number}>({page: 0, loadedElements: 0, totalElements: 1}) | ||
const [neurons, setNeurons] = useState<Neuron[]>([]) | ||
|
||
useEffect(() => { | ||
HeathcheckService.ready().then(answer => setReady(answer)) | ||
DatasetsService.getDataset({dataset: 'white_1986_whole'}).then(answer => setDataset(answer)) | ||
DatasetsService.getAllDatasets().then(answer => setAllDataset(answer)) | ||
loadMoreNeurons() | ||
}, []) | ||
import {useGlobalContext} from "../contexts/GlobalContext.tsx"; | ||
|
||
const loadMoreNeurons = async () => { | ||
const page = currentPage.page + 1 | ||
const neuronPage = await NeuronsService.getAllCells({page: page}) | ||
setNeurons([...neurons, ...neuronPage.items]) | ||
setCurrentPage({page: page, loadedElements: neurons.length, totalElements: neuronPage.count}) | ||
} | ||
export default function LeftComponent() { | ||
const {datasets, neurons} = useGlobalContext(); | ||
|
||
const datasetArray = datasets ? Object.values(datasets) : []; | ||
const neuronArray = neurons ? Object.values(neurons) : []; | ||
return ( | ||
<Box> | ||
<Typography variant="h1">Vite + React + Typescript</Typography> | ||
<Typography variant="h3">API state: {ready}</Typography> | ||
<Typography variant="h3">Dataset: {JSON.stringify(dataset)}</Typography> | ||
<Typography variant="h3">All datasets names:</Typography> | ||
<Box> | ||
{ | ||
allDataset?.map(x => <Typography key={x.name} variant="body1">{x.name}</Typography>) | ||
// Render each dataset name | ||
datasetArray.map(dataset => ( | ||
<Typography key={dataset.id} variant="body1">{dataset.name}</Typography> | ||
)) | ||
} | ||
</Box> | ||
<Typography variant="h3">Neurons:</Typography> | ||
<Box> | ||
{ | ||
neurons?.map(x => <Typography key={x.name} variant="body1">{x.name}</Typography>) | ||
// Render each neuron name | ||
neuronArray.map(neuron => ( | ||
<Typography key={neuron.id} variant="body1">{neuron.name}</Typography> | ||
)) | ||
} | ||
<Button disabled={currentPage.loadedElements >= currentPage.totalElements} onClick={loadMoreNeurons}>Load more</Button> | ||
</Box> | ||
</Box> | ||
) | ||
); | ||
} |
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,18 @@ | ||
import {Dataset as DatasetApi, Neuron as NeuronApi} from "../rest"; | ||
import {Dataset, Neuron} from "../models.ts"; | ||
|
||
// Function to map Neuron from the request to the context format | ||
export function mapNeuronFromRequestToContext(neuron: NeuronApi): Neuron { | ||
return { | ||
id: neuron.name || neuron.nclass, | ||
name: `${neuron.name}` | ||
}; | ||
} | ||
|
||
export function mapDatasetFromRequestToContext(dataset: DatasetApi): Dataset { | ||
return { | ||
id: dataset.id || dataset.name, | ||
name: dataset.name, | ||
neurons: new Set<Neuron>() // TODO: Need to understand how to populate this | ||
}; | ||
} |
24 changes: 9 additions & 15 deletions
24
applications/visualizer/frontend/src/helpers/workspacesHelper.ts
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