Merge branch 'remove_store_getters' into 'v3'

ui_migration refactor(store) Remove lingering getters for origin and available...

Closes #762

See merge request openflexure/openflexure-microscope-server!597
This commit is contained in:
Julian Stirling 2026-05-26 09:21:12 +00:00
commit 08b6b274a8
4 changed files with 52 additions and 60 deletions

View file

@ -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,

View file

@ -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,

View file

@ -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" },
},
}),
],

View file

@ -50,7 +50,7 @@ export default defineConfig({
thresholds: {
lines: 4,
statements: 3,
functions: 3,
functions: 2,
branches: 1,
},
},