From 7afef9be6ecca1db97135dddca7fa3bf223770e2 Mon Sep 17 00:00:00 2001 From: Anne Haley Date: Mon, 16 Sep 2024 22:36:31 +0000 Subject: [PATCH] refactor: populate store vars when fetching for Project contents --- web/src/components/ProjectContents.vue | 39 +++++++++++++++++++++---- web/src/storeFunctions.ts | 40 +------------------------- 2 files changed, 34 insertions(+), 45 deletions(-) diff --git a/web/src/components/ProjectContents.vue b/web/src/components/ProjectContents.vue index 732420fa..7bc2b046 100644 --- a/web/src/components/ProjectContents.vue +++ b/web/src/components/ProjectContents.vue @@ -14,7 +14,15 @@ import { getProjectSimulationTypes, } from "@/api/rest"; import DatasetList from "./DatasetList.vue"; -import { currentChart, currentSimulationType } from "@/store"; +import { + availableCharts, + availableDatasets, + availableDerivedRegions, + availableSimulationTypes, + currentChart, + currentSimulationType, +} from "@/store"; +import { getDatasetLayerForDataObject, toggleDatasetLayer } from "@/layers"; export default { components: { DatasetList }, @@ -27,10 +35,26 @@ export default { // eslint-disable-next-line @typescript-eslint/no-explicit-any setup(props: any) { const panels = [ - { label: "Datasets", loadFunction: getProjectDatasets }, - { label: "Regions", loadFunction: getProjectDerivedRegions }, - { label: "Charts", loadFunction: getProjectCharts }, - { label: "Simulations", loadFunction: getProjectSimulationTypes }, + { + label: "Datasets", + loadFunction: getProjectDatasets, + storeVar: availableDatasets, + }, + { + label: "Regions", + loadFunction: getProjectDerivedRegions, + storeVar: availableDerivedRegions, + }, + { + label: "Charts", + loadFunction: getProjectCharts, + storeVar: availableCharts, + }, + { + label: "Simulations", + loadFunction: getProjectSimulationTypes, + storeVar: availableSimulationTypes, + }, ]; const openPanels: Ref = ref([]); @@ -43,7 +67,9 @@ export default { item: Dataset | DerivedRegion | Chart | SimulationType ) { if (panelLabel == "Regions") { - // TODO: select region + getDatasetLayerForDataObject(item as DerivedRegion).then((layer) => { + toggleDatasetLayer(layer); + }); } else if (panelLabel == "Charts") { currentChart.value = item as Chart; } else if (panelLabel == "Simulations") { @@ -57,6 +83,7 @@ export default { if (openPanels.value.includes(panel.label)) { panel.loadFunction(props.project.id).then((data) => { projectContents.value[panel.label] = data; + panel.storeVar.value = data; }); } }); diff --git a/web/src/storeFunctions.ts b/web/src/storeFunctions.ts index 460d0775..e64f9803 100644 --- a/web/src/storeFunctions.ts +++ b/web/src/storeFunctions.ts @@ -31,15 +31,7 @@ import { tooltipOverlay, clickedFeatureCandidates, } from "./store"; -import { Dataset } from "./types"; -import { - getProjectDatasets, - getProjects, - getDataset, - getProjectCharts, - getProjectSimulationTypes, - getProjectDerivedRegions, -} from "@/api/rest"; +import { getProjects, getDataset, getProjectDerivedRegions } from "@/api/rest"; import { datasetLayerFromMapLayerID, styleNetworkVectorTileLayer, @@ -115,32 +107,6 @@ export function getCurrentMapPosition() { return { center, zoom }; } -export function loadDatasets() { - if (!currentProject.value) return; - availableDatasets.value = undefined; - getProjectDatasets(currentProject.value.id).then((data: Dataset[]) => { - availableDatasets.value = data; - }); -} - -export function loadCharts() { - if (!currentProject.value) return; - availableCharts.value = undefined; - currentChart.value = undefined; - getProjectCharts(currentProject.value.id).then((charts) => { - availableCharts.value = charts; - }); -} - -export function loadSimulationTypes() { - if (!currentProject.value) return; - availableSimulationTypes.value = undefined; - currentSimulationType.value = undefined; - getProjectSimulationTypes(currentProject.value.id).then((sims) => { - availableSimulationTypes.value = sims; - }); -} - export async function loadDerivedRegions() { if (!currentProject.value) { return; @@ -199,10 +165,6 @@ export function clearCurrentNetwork() { watch(currentProject, () => { clearState(); setMapCenter(); - loadDatasets(); - loadCharts(); - loadSimulationTypes(); - loadDerivedRegions(); }); watch(currentDataset, () => { rasterTooltipEnabled.value = false;