From b8ee3471ae22e00df45797d217dc9cffa55ab7a8 Mon Sep 17 00:00:00 2001 From: Sebastian Eicke Date: Thu, 9 Jan 2025 13:18:45 +0100 Subject: [PATCH] Cleanup AASStore (#227) * Preserve query parameter for switching between AAS Viewer/Editor, Submodel Viewer, About page, ... Fixes #166 * Using anchor tag `to` for declarative navigation * Undo changes in AppNavigation/MainMenu * Adds state for url query * Adds route guard to preserver query parameter * Implements fetchSme() and fetchAndDispatchSme() in SMRepositoryClient * Usage of fetchAndDispathSme() in App.vue * Usage of fetchAndDispatchSme() in route guard * Adds env variable EDITOR_ID_PREFIX * Fix type of for GlobalAssetId * Extends generateIri() * Adds tests for generateIri() * Strip idShortPath of path URL query in case of switching to SubmodelViewer * Updates router guard * Updates IDUtils tests for generateIri() * Udpates jsdoc of generateCustomId() * Adds tests for generateCustomId() * Get idPrefix from EnvStore --> pinia error * Transfers IDUtils to composable * Fixes usage of IDUtils composable in AAS.vue * Avoids AASStore actions within Clients * Removes updatedNode from AASStore * Fix VTreeview --- aas-web-ui/src/components/AASTreeview.vue | 8 ++++---- aas-web-ui/src/components/SubmodelList.vue | 4 ++-- aas-web-ui/src/components/UIComponents/VTreeview.vue | 3 ++- aas-web-ui/src/composables/SMEHandling.ts | 2 +- aas-web-ui/src/composables/SMHandling.ts | 2 +- aas-web-ui/src/mixins/SubmodelElementHandling.ts | 4 ++-- aas-web-ui/src/store/AASDataStore.ts | 10 ---------- 7 files changed, 12 insertions(+), 21 deletions(-) diff --git a/aas-web-ui/src/components/AASTreeview.vue b/aas-web-ui/src/components/AASTreeview.vue index a3a15e75..fd713a51 100644 --- a/aas-web-ui/src/components/AASTreeview.vue +++ b/aas-web-ui/src/components/AASTreeview.vue @@ -85,7 +85,7 @@ const loading = computed(() => aasStore.getLoadingState); // gets loading State from Store const aasRegistryServerURL = computed(() => navigationStore.getAASRegistryURL); // get AAS Registry URL from Store const submodelRegistryURL = computed(() => navigationStore.getSubmodelRegistryURL); // get Submodel Registry URL from Store - const updatedNode = computed(() => aasStore.getUpdatedNode); // get the updated Treeview Node from Store + const selectedNode = computed(() => aasStore.getSelectedNode); // get the updated Treeview Node from Store const initTree = computed(() => aasStore.getInitTreeByReferenceElement); // get the init treeview flag from Store // Watchers @@ -108,8 +108,8 @@ }); // change the submodelData Object when the updated Node changes - watch(updatedNode, () => { - updateNode(updatedNode.value); + watch(selectedNode, () => { + updateNode(selectedNode.value); }); // initialize Treeview when the initTree flag changes @@ -324,7 +324,7 @@ if (!foundNode) { foundNode = true; element.isActive = true; - aasStore.dispatchNode(element); + aasStore.dispatchSelectedNode(element); aasStore.dispatchRealTimeObject(element); } // if prop showChildren exists, set it to true diff --git a/aas-web-ui/src/components/SubmodelList.vue b/aas-web-ui/src/components/SubmodelList.vue index 49e1d3d9..cb457727 100644 --- a/aas-web-ui/src/components/SubmodelList.vue +++ b/aas-web-ui/src/components/SubmodelList.vue @@ -151,7 +151,7 @@ fetchedSubmodelData.forEach((submodel: any) => { if (submodel.path === initialNode.value.path) { submodel.isActive = true; - aasStore.dispatchNode(submodel); + aasStore.dispatchSelectedNode(submodel); aasStore.dispatchRealTimeObject(submodel); } }); @@ -269,7 +269,7 @@ router.push({ query: query }); } // dispatch the selected Node to the store - aasStore.dispatchNode(localSubmodel); + aasStore.dispatchSelectedNode(localSubmodel); // add Submodel to the store (as RealTimeDataObject) aasStore.dispatchRealTimeObject(localSubmodel); } diff --git a/aas-web-ui/src/components/UIComponents/VTreeview.vue b/aas-web-ui/src/components/UIComponents/VTreeview.vue index b74dfd90..f4caadfc 100644 --- a/aas-web-ui/src/components/UIComponents/VTreeview.vue +++ b/aas-web-ui/src/components/UIComponents/VTreeview.vue @@ -179,14 +179,15 @@ }, }); } + this.aasStore.dispatchSelectedNode(localItem); } else { // remove the path query from the Route entirely let query = { ...this.route.query }; delete query.path; this.router.push({ query: query }); + this.aasStore.dispatchSelectedNode({}); } // dispatch the selected Node to the store - this.aasStore.dispatchNode(localItem); }, // Function to copy the path of the current Node to the Clipboard diff --git a/aas-web-ui/src/composables/SMEHandling.ts b/aas-web-ui/src/composables/SMEHandling.ts index 015b35f7..6fe89d9c 100644 --- a/aas-web-ui/src/composables/SMEHandling.ts +++ b/aas-web-ui/src/composables/SMEHandling.ts @@ -20,7 +20,7 @@ export function useSMEHandling(): any { sme.path = submodelElementPath; sme.isActive = true; - aasStore.dispatchNode(sme); + aasStore.dispatchSelectedNode(sme); } return { fetchAndDispatchSme }; diff --git a/aas-web-ui/src/composables/SMHandling.ts b/aas-web-ui/src/composables/SMHandling.ts index 7268d5e4..f44fc6bd 100644 --- a/aas-web-ui/src/composables/SMHandling.ts +++ b/aas-web-ui/src/composables/SMHandling.ts @@ -20,7 +20,7 @@ export function useSMHandling(): any { sm.path = smEndpoint; sm.isActive = true; - aasStore.dispatchNode(sm); + aasStore.dispatchSelectedNode(sm); } return { fetchAndDispatchSm }; diff --git a/aas-web-ui/src/mixins/SubmodelElementHandling.ts b/aas-web-ui/src/mixins/SubmodelElementHandling.ts index 75e0c502..998c27b0 100644 --- a/aas-web-ui/src/mixins/SubmodelElementHandling.ts +++ b/aas-web-ui/src/mixins/SubmodelElementHandling.ts @@ -811,7 +811,7 @@ export default defineComponent({ node.timestamp = this.formatDate(new Date()); // add timestamp to the SubmodelElement Data node.path = smRepoUrl; // add the path to the SubmodelElement Data node.isActive = true; // add the isActive Property to the SubmodelElement Data - this.aasStore.dispatchNode(node); // set the updatedNode in the AASStore + this.aasStore.dispatchSelectedNode(node); // set the updatedNode in the AASStore this.aasStore.dispatchInitTreeByReferenceElement(true); // set the initTreeByReferenceElement in the AASStore to true to init + expand the Treeview on the referenced Element } else { // execute if the Request failed @@ -826,7 +826,7 @@ export default defineComponent({ }); // Show Error Snackbar return; } - this.aasStore.dispatchNode({}); + this.aasStore.dispatchSelectedNode({}); } }); }) diff --git a/aas-web-ui/src/store/AASDataStore.ts b/aas-web-ui/src/store/AASDataStore.ts index c341dede..18399839 100644 --- a/aas-web-ui/src/store/AASDataStore.ts +++ b/aas-web-ui/src/store/AASDataStore.ts @@ -5,7 +5,6 @@ export const useAASStore = defineStore({ state: () => ({ aasObject: {} as any, // holds the AAS object for the currently selected AAS loadingState: false, // loading state of the AAS Treeview Component - updatedNode: {} as any, // holds the most recently updated Node in the AAS Treeview Component selectedNode: {} as any, // holds the currently selected Node in the AAS Treeview Component realTimeObject: {} as any, // holds the newest synced SubmodelElement (for the ComponentViasualization) initTreeByReferenceElement: false, // holds the state if the AAS Treeview Component should be initialized because the Jump-Button was clicked on a ReferenceElement @@ -13,7 +12,6 @@ export const useAASStore = defineStore({ getters: { getSelectedAAS: (state) => state.aasObject, getLoadingState: (state) => state.loadingState, - getUpdatedNode: (state) => state.updatedNode, getSelectedNode: (state) => state.selectedNode, getRealTimeObject: (state) => state.realTimeObject, getInitTreeByReferenceElement: (state) => state.initTreeByReferenceElement, @@ -26,14 +24,6 @@ export const useAASStore = defineStore({ dispatchLoadingState(loadingState: boolean) { this.loadingState = loadingState; }, - dispatchNode(node: any) { - this.updatedNode = node; - if (!node.isActive) { - this.selectedNode = {}; - } else { - this.selectedNode = node; - } - }, dispatchSelectedNode(node: any) { this.selectedNode = node; },