From ace7ae9855d0d7c799f843718e8e48476f832322 Mon Sep 17 00:00:00 2001 From: Antonio Anaya Date: Sun, 24 May 2026 16:50:53 -0600 Subject: [PATCH 1/2] ui_migration refactor(store) Remove lingering getters for origin and available at settings.js pinia store, fixed unit test and thresholds accordingly. --- webapp/src/stores/settings.js | 25 +++++++------------- webapp/src/tests/unit/LoggingContent.spec.js | 2 +- webapp/vitest.config.js | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/webapp/src/stores/settings.js b/webapp/src/stores/settings.js index 82e0ecc7..94779722 100644 --- a/webapp/src/stores/settings.js +++ b/webapp/src/stores/settings.js @@ -1,5 +1,5 @@ import { defineStore } from "pinia"; -import { ref, computed } from "vue"; +import { ref } from "vue"; function getOriginFromLocation() { // This will default to the same origin that's serving @@ -13,8 +13,8 @@ export const useSettingsStore = defineStore( "settings", () => { // State - const origin = ref(getOriginFromLocation()); - const available = ref(false); + const baseUri = ref(getOriginFromLocation()); + const ready = ref(false); const waiting = ref(false); const error = ref(""); const trackWindow = ref(true); @@ -43,14 +43,14 @@ export const useSettingsStore = defineStore( // Actions function resetState() { waiting.value = false; - available.value = false; + ready.value = false; // On resetState there is no connection. error.value = "Microscope is not connected."; } function setConnected() { waiting.value = false; - available.value = true; + ready.value = true; } function addStream(id) { @@ -59,15 +59,12 @@ export const useSettingsStore = defineStore( function removeStream(id) { activeStreams.value[id] = false; } - // Getters - const baseUri = computed(() => origin.value); - const ready = computed(() => available.value); // Export return { - //State - origin, - available, + // State + baseUri, + ready, waiting, error, trackWindow, @@ -79,11 +76,7 @@ export const useSettingsStore = defineStore( navigationStepSize, navigationInvert, - //Getters - baseUri, - ready, - - //Actions + // Actions resetState, setConnected, addStream, diff --git a/webapp/src/tests/unit/LoggingContent.spec.js b/webapp/src/tests/unit/LoggingContent.spec.js index 2153c29f..4f541750 100644 --- a/webapp/src/tests/unit/LoggingContent.spec.js +++ b/webapp/src/tests/unit/LoggingContent.spec.js @@ -53,7 +53,7 @@ describe("Test LoggingContent.vue", () => { createTestingPinia({ createSpy: vi.fn, initialState: { - settings: { origin: "http://microscope.local:5000/api/v3" }, + settings: { baseUri: "http://microscope.local:5000/api/v3" }, }, }), ], diff --git a/webapp/vitest.config.js b/webapp/vitest.config.js index b4b29cb2..dc9dbbf4 100644 --- a/webapp/vitest.config.js +++ b/webapp/vitest.config.js @@ -50,7 +50,7 @@ export default defineConfig({ thresholds: { lines: 4, statements: 3, - functions: 3, + functions: 2, branches: 1, }, }, From f8c4ffe62b4daed1f6cda72b8e671601c470136f Mon Sep 17 00:00:00 2001 From: Antonio Anaya Date: Sun, 24 May 2026 18:16:01 -0600 Subject: [PATCH 2/2] ui_migration refactor(store) Remove lingering getters at wot.js pinia store --- webapp/src/stores/wot.js | 83 ++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 42 deletions(-) diff --git a/webapp/src/stores/wot.js b/webapp/src/stores/wot.js index 2b4f9dce..a4aff9ed 100644 --- a/webapp/src/stores/wot.js +++ b/webapp/src/stores/wot.js @@ -9,6 +9,10 @@ export const useWotStore = defineStore( const thingDescriptions = ref({}); const servient = ref(null); const helpers = ref(null); + + // Getters + const thingList = computed(() => Object.keys(thingDescriptions.value)); + // Actions function addThingDescription(thingName, thingDescription) { thingDescriptions.value[thingName] = thingDescription; @@ -42,58 +46,53 @@ export const useWotStore = defineStore( } } - const thingList = computed(() => Object.keys(thingDescriptions.value)); - - const thingAvailable = computed(() => (thingName) => { + function thingAvailable(thingName) { return thingName in thingDescriptions.value; - }); + } - const thingAffordanceAvailable = computed(() => (thing, affordanceType, affordance) => { + function thingAffordanceAvailable(thing, affordanceType, affordance) { const td = thingDescriptions.value[thing]; if (!td || !td[affordanceType]) return false; return affordance in td[affordanceType]; - }); + } - const thingFormUrl = computed( - () => - (thing, affordanceType, affordance, op, allowUndefined = true) => { - // Find the URL for a particular operation - const td = thingDescriptions.value[thing]; - if (!td) { - if (allowUndefined) return undefined; - throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`; - } - const affordances = td[affordanceType]; - if (!affordances || !(affordance in affordances)) { - if (allowUndefined) return undefined; - throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`; - } - let href = findFormHref(affordances[affordance], op); - if (href === undefined) { - if (allowUndefined) return undefined; - throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`; - } - // If we've found an href, prepend the `base` URL if appropriate - if (href.startsWith("http")) return href; - if ("base" in td) { - let base = td.base; - if (href.startsWith("/")) href = href.slice(1); - if (!base.endsWith("/")) base += "/"; - return base + href; - } - return href; - }, - ); + function thingFormUrl(thing, affordanceType, affordance, op, allowUndefined = true) { + // Find the URL for a particular operation + const td = thingDescriptions.value[thing]; + if (!td) { + if (allowUndefined) return undefined; + throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`; + } + const affordances = td[affordanceType]; + if (!affordances || !(affordance in affordances)) { + if (allowUndefined) return undefined; + throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`; + } + let href = findFormHref(affordances[affordance], op); + if (href === undefined) { + if (allowUndefined) return undefined; + throw `Could not find form for ${affordanceType} ${thing}/${affordance} with op ${op}`; + } + // If we've found an href, prepend the `base` URL if appropriate + if (href.startsWith("http")) return href; + if ("base" in td) { + let base = td.base; + if (href.startsWith("/")) href = href.slice(1); + if (!base.endsWith("/")) base += "/"; + return base + href; + } + return href; + } - const thingPropertyUrl = computed(() => (thing, property, op, allowUndefined) => { + function thingPropertyUrl(thing, property, op, allowUndefined) { // Find the URL for a particular property - return thingFormUrl.value(thing, "properties", property, op, allowUndefined); - }); + return thingFormUrl(thing, "properties", property, op, allowUndefined); + } - const thingActionUrl = computed(() => (thing, action, op, allowUndefined) => { + function thingActionUrl(thing, action, op, allowUndefined) { // Find the URL for a particular action - return thingFormUrl.value(thing, "actions", action, op, allowUndefined); - }); + return thingFormUrl(thing, "actions", action, op, allowUndefined); + } return { thingDescriptions,