Skip to content

Commit fe55ccf

Browse files
committed
fix(ui): properly update namespace selector list when namespace is edited
1 parent 9282a35 commit fe55ccf

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

ui/admin/src/components/Namespace/NamespaceEdit.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@
6464
import { useField } from "vee-validate";
6565
import { computed, ref } from "vue";
6666
import * as yup from "yup";
67-
import useNamespacesStore from "@admin/store/modules/namespaces";
67+
import useAdminNamespacesStore from "@admin/store/modules/namespaces";
68+
import useNamespacesStore from "@/store/modules/namespaces";
6869
import useSnackbar from "@/helpers/snackbar";
6970
import { IAdminNamespace } from "../../interfaces/INamespace";
7071
import FormDialog from "@/components/Dialogs/FormDialog.vue";
@@ -73,6 +74,7 @@ const props = defineProps<{ namespace: IAdminNamespace }>();
7374
7475
const snackbar = useSnackbar();
7576
const namespacesStore = useNamespacesStore();
77+
const adminNamespacesStore = useAdminNamespacesStore();
7678
const showDialog = ref(false);
7779
7880
const {
@@ -119,13 +121,14 @@ const closeDialog = () => {
119121
const submitForm = async () => {
120122
if (hasErrors.value) return;
121123
try {
122-
await namespacesStore.updateNamespace({
124+
await adminNamespacesStore.updateNamespace({
123125
...props.namespace,
124126
name: name.value as string,
125127
max_devices: Number(maxDevices.value),
126128
settings: { session_record: sessionRecord.value },
127129
});
128-
await namespacesStore.fetchNamespaceList();
130+
await adminNamespacesStore.fetchNamespaceList();
131+
await namespacesStore.fetchNamespaceList({ perPage: 30 });
129132
snackbar.showSuccess("Namespace updated successfully.");
130133
showDialog.value = false;
131134
} catch {

ui/admin/tests/unit/components/Namespaces/NamespaceEdit/index.spec.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import MockAdapter from "axios-mock-adapter";
12
import { createVuetify } from "vuetify";
23
import { DOMWrapper, flushPromises, mount } from "@vue/test-utils";
34
import { describe, expect, it, vi } from "vitest";
@@ -6,6 +7,7 @@ import useNamespacesStore from "@admin/store/modules/namespaces";
67
import NamespaceEdit from "@admin/components/Namespace/NamespaceEdit.vue";
78
import { IAdminNamespace } from "@admin/interfaces/INamespace";
89
import { SnackbarInjectionKey } from "@/plugins/snackbar";
10+
import { namespacesApi } from "@/api/http";
911

1012
const namespace = {
1113
billing: {
@@ -45,6 +47,7 @@ const mockSnackbar = {
4547

4648
describe("Namespace Edit", () => {
4749
setActivePinia(createPinia());
50+
const mockNamespacesApi = new MockAdapter(namespacesApi.getAxios());
4851
const namespacesStore = useNamespacesStore();
4952
namespacesStore.updateNamespace = vi.fn();
5053
namespacesStore.fetchNamespaceList = vi.fn();
@@ -70,6 +73,7 @@ describe("Namespace Edit", () => {
7073
});
7174

7275
it("Calls namespace store and snackbar on form submission", async () => {
76+
mockNamespacesApi.onGet("http://localhost:3000/api/namespaces?page=1&per_page=30").reply(200, []);
7377
wrapper.vm.submitForm();
7478
await flushPromises();
7579
expect(namespacesStore.updateNamespace).toHaveBeenCalled();

ui/src/components/Namespace/Namespace.vue

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ const showAdminButton = computed(() => {
147147
});
148148
149149
const availableNamespaces = computed(() => {
150-
const namespaces = namespaceList.value.filter((ns) => ns.tenant_id !== currentNamespace.value.tenant_id);
151-
if (props.isAdminContext && currentNamespace.value.tenant_id) namespaces.push(currentNamespace.value);
152-
return namespaces;
150+
if (props.isAdminContext) return namespaceList.value;
151+
return namespaceList.value.filter((ns) => ns.tenant_id !== currentNamespace.value.tenant_id);
153152
});
154153
155154
const navigateToAdminPanel = () => { window.location.href = "/admin"; };

0 commit comments

Comments
 (0)