From 09380d5b80151451edd740169d822cfb0e9d36f2 Mon Sep 17 00:00:00 2001 From: afonso Date: Tue, 23 Apr 2024 21:54:12 +0100 Subject: [PATCH] CELE-17 feat: Update global context properties --- .../frontend/src/components/LeftComponent.tsx | 43 ++++++----------- .../src/components/RightComponent.tsx | 19 ++++---- .../frontend/src/contexts/GlobalContext.tsx | 47 +++++++++++++++++-- .../src/helpers/initialWorkspacesHelper.ts | 7 ++- .../frontend/src/helpers/mappers.ts | 18 +++++++ .../frontend/src/helpers/workspacesHelper.ts | 24 ++++------ .../visualizer/frontend/src/models.ts | 6 +-- 7 files changed, 101 insertions(+), 63 deletions(-) create mode 100644 applications/visualizer/frontend/src/helpers/mappers.ts diff --git a/applications/visualizer/frontend/src/components/LeftComponent.tsx b/applications/visualizer/frontend/src/components/LeftComponent.tsx index b1962b11..f5c5d33b 100644 --- a/applications/visualizer/frontend/src/components/LeftComponent.tsx +++ b/applications/visualizer/frontend/src/components/LeftComponent.tsx @@ -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() - const [allDataset, setAllDataset] = useState() - const [currentPage, setCurrentPage] = useState<{page: number, loadedElements: number, totalElements: number}>({page: 0, loadedElements: 0, totalElements: 1}) - const [neurons, setNeurons] = useState([]) - - 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 ( Vite + React + Typescript - API state: {ready} - Dataset: {JSON.stringify(dataset)} All datasets names: { - allDataset?.map(x => {x.name}) + // Render each dataset name + datasetArray.map(dataset => ( + {dataset.name} + )) } Neurons: { - neurons?.map(x => {x.name}) + // Render each neuron name + neuronArray.map(neuron => ( + {neuron.name} + )) } - - ) + ); } \ No newline at end of file diff --git a/applications/visualizer/frontend/src/components/RightComponent.tsx b/applications/visualizer/frontend/src/components/RightComponent.tsx index 5f9ee21f..97d48f23 100644 --- a/applications/visualizer/frontend/src/components/RightComponent.tsx +++ b/applications/visualizer/frontend/src/components/RightComponent.tsx @@ -10,11 +10,8 @@ import { import {ViewerSynchronizationPair, ViewerType} from "../models.ts"; -const testNeuron = {id: 'neuron3', label: 'Neuron 3'}; -const testDataset = {id: 'dataset1', name: 'Dataset 1'}; - export default function RightComponent() { - const {workspaces, currentWorkspaceId, updateWorkspace} = useGlobalContext(); + const {workspaces, currentWorkspaceId, updateWorkspace, datasets, neurons} = useGlobalContext(); const workspace = workspaces[currentWorkspaceId]; function withWorkspaceUpdate(modifyWorkspace) { @@ -44,6 +41,8 @@ export default function RightComponent() { const currentVisibility = workspace.viewers[viewerToToggle]; const syncPair = ViewerSynchronizationPair.Graph_InstanceDetails; const currentSyncStatus = workspace.synchronizations[syncPair]; + const testNeuron = 'ADAL' + const testDataset = "white_1986_jse" return ( @@ -57,14 +56,14 @@ export default function RightComponent() { Activate Neuron