Skip to content

Commit ccad4d1

Browse files
committed
feat(namespace): implement namespace loading and filtering in NamespaceTabs and Nodes components
1 parent 261c766 commit ccad4d1

File tree

4 files changed

+92
-51
lines changed

4 files changed

+92
-51
lines changed

app/src/components/NamespaceTabs/NamespaceTabs.vue

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,48 @@
11
<script setup lang="ts">
22
import type { Namespace } from '@/api/namespace'
33
import { message } from 'ant-design-vue'
4+
import namespaceApi from '@/api/namespace'
45
import nodeApi from '@/api/node'
56
import { useNodeAvailabilityStore } from '@/pinia/moudule/nodeAvailability'
67
7-
const props = defineProps<{
8-
namespaces: Namespace[]
8+
defineProps<{
9+
hideNodeInfo?: boolean
910
}>()
1011
1112
const modelValue = defineModel<string | number>('activeKey')
1213
const nodeStore = useNodeAvailabilityStore()
14+
const namespaces = ref<Namespace[]>([])
15+
16+
// Load all namespaces on mount (handle pagination)
17+
async function loadAllNamespaces() {
18+
const allNamespaces: Namespace[] = []
19+
let currentPage = 1
20+
let hasMore = true
21+
22+
while (hasMore) {
23+
try {
24+
const response = await namespaceApi.getList({ page: currentPage })
25+
allNamespaces.push(...response.data)
26+
27+
if (response.pagination && response.pagination.current_page < response.pagination.total_pages) {
28+
currentPage++
29+
}
30+
else {
31+
hasMore = false
32+
}
33+
}
34+
catch (error) {
35+
console.error('Failed to load namespaces:', error)
36+
hasMore = false
37+
}
38+
}
39+
40+
namespaces.value = allNamespaces
41+
}
42+
43+
onMounted(() => {
44+
loadAllNamespaces()
45+
})
1346
1447
const loading = ref({
1548
reload: false,
@@ -20,7 +53,7 @@ const loading = ref({
2053
const currentNamespace = computed(() => {
2154
if (!modelValue.value || modelValue.value === 0)
2255
return null
23-
return props.namespaces.find(g => g.id === Number(modelValue.value))
56+
return namespaces.value.find(g => g.id === Number(modelValue.value))
2457
})
2558
2659
// Get the list of nodes in the current group
@@ -86,7 +119,7 @@ async function handleRestartNginx() {
86119

87120
<!-- Display node information -->
88121
<ACard
89-
v-if="modelValue && modelValue !== 0 && syncNodes.length > 0"
122+
v-if="!hideNodeInfo && modelValue && modelValue !== 0 && syncNodes.length > 0"
90123
:title="$gettext('Sync Nodes')"
91124
size="small"
92125
class="mb-4"

app/src/views/dashboard/Nodes.vue

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<script setup lang="ts">
22
import type { Ref } from 'vue'
3+
import type { Namespace } from '@/api/namespace'
34
import type { Node } from '@/api/node'
45
import Icon, { LinkOutlined, ThunderboltOutlined } from '@ant-design/icons-vue'
56
import analytic from '@/api/analytic'
7+
import namespaceApi from '@/api/namespace'
68
import nodeApi from '@/api/node'
79
import logo from '@/assets/img/logo.png'
810
import pulse from '@/assets/svg/pulse.svg?component'
11+
import NamespaceTabs from '@/components/NamespaceTabs'
912
import { formatDateTime } from '@/lib/helper'
1013
import { useSettingsStore } from '@/pinia'
1114
import { useNodeAvailabilityStore } from '@/pinia/moudule/nodeAvailability'
@@ -14,6 +17,7 @@ import NodeAnalyticItem from './components/NodeAnalyticItem.vue'
1417
1518
const nodeStore = useNodeAvailabilityStore()
1619
const data = ref([]) as Ref<Node[]>
20+
const activeNamespaceKey = ref<string | number>(0)
1721
1822
const nodeMap = computed(() => {
1923
const o = {} as Record<number, Node>
@@ -25,10 +29,56 @@ const nodeMap = computed(() => {
2529
return o
2630
})
2731
32+
// Get namespaces to filter nodes
33+
const namespaces = ref([]) as Ref<Namespace[]>
34+
35+
// Filtered nodes based on active namespace
36+
const filteredNodes = computed(() => {
37+
if (activeNamespaceKey.value === 0) {
38+
return data.value
39+
}
40+
41+
const currentNamespace = namespaces.value.find(ns => ns.id === Number(activeNamespaceKey.value))
42+
if (!currentNamespace || !currentNamespace.sync_node_ids) {
43+
return []
44+
}
45+
46+
return data.value.filter(node => currentNamespace.sync_node_ids.includes(node.id))
47+
})
48+
49+
// Load all namespaces (handle pagination)
50+
async function loadAllNamespaces() {
51+
const allNamespaces: Namespace[] = []
52+
let currentPage = 1
53+
let hasMore = true
54+
55+
while (hasMore) {
56+
try {
57+
const response = await namespaceApi.getList({ page: currentPage })
58+
allNamespaces.push(...response.data)
59+
60+
if (response.pagination && response.pagination.current_page < response.pagination.total_pages) {
61+
currentPage++
62+
}
63+
else {
64+
hasMore = false
65+
}
66+
}
67+
catch (error) {
68+
console.error('Failed to load namespaces:', error)
69+
hasMore = false
70+
}
71+
}
72+
73+
namespaces.value = allNamespaces
74+
}
75+
2876
onMounted(() => {
2977
nodeApi.getList({ enabled: true }).then(r => {
3078
data.value.push(...r.data)
3179
})
80+
81+
loadAllNamespaces()
3282
})
3383
3484
onMounted(() => {
@@ -80,9 +130,11 @@ const visible = computed(() => {
80130
:title="$gettext('Nodes')"
81131
:bordered="false"
82132
>
133+
<NamespaceTabs v-model:active-key="activeNamespaceKey" class="mb-4" hide-node-info />
134+
83135
<AList
84136
item-layout="horizontal"
85-
:data-source="data"
137+
:data-source="filteredNodes"
86138
class="env-list"
87139
>
88140
<template #renderItem="{ item }">

app/src/views/site/site_list/SiteList.vue

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<script setup lang="tsx">
2-
import type { Namespace } from '@/api/namespace'
32
import { StdCurd } from '@uozi-admin/curd'
43
import { message } from 'ant-design-vue'
5-
import namespace from '@/api/namespace'
64
import site from '@/api/site'
75
import NamespaceTabs from '@/components/NamespaceTabs'
86
import { ConfigStatus } from '@/constants'
@@ -17,31 +15,11 @@ const curd = ref()
1715
const inspectConfig = ref()
1816
1917
const namespaceId = ref(Number.parseInt(route.query.namespace_id as string) || 0)
20-
const namespaces = ref<Namespace[]>([])
2118
2219
watch(route, () => {
2320
inspectConfig.value?.test()
2421
})
2522
26-
onMounted(async () => {
27-
let page = 1
28-
while (true) {
29-
try {
30-
const { data, pagination } = await namespace.getList({ page })
31-
if (!data || !pagination)
32-
return
33-
namespaces.value.push(...data)
34-
if (data.length < pagination?.per_page) {
35-
return
36-
}
37-
page++
38-
}
39-
catch {
40-
return
41-
}
42-
}
43-
})
44-
4523
function destroy(site_name: string) {
4624
site.deleteItem(site_name).then(() => {
4725
curd.value.refresh()
@@ -97,7 +75,7 @@ function handle_click_duplicate(name: string) {
9775
</template>
9876
<template #beforeCardBody>
9977
<InspectConfig ref="inspectConfig" />
100-
<NamespaceTabs v-model:active-key="namespaceId" :namespaces="namespaces" />
78+
<NamespaceTabs v-model:active-key="namespaceId" />
10179
</template>
10280
<template #afterActions="{ record }">
10381
<AButton

app/src/views/stream/StreamList.vue

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<script setup lang="tsx">
2-
import type { Namespace } from '@/api/namespace'
32
import { StdCurd } from '@uozi-admin/curd'
43
import { message } from 'ant-design-vue'
5-
import namespace from '@/api/namespace'
64
import stream from '@/api/stream'
75
import NamespaceTabs from '@/components/NamespaceTabs'
86
import InspectConfig from '@/views/config/InspectConfig.vue'
@@ -16,26 +14,6 @@ const curd = ref()
1614
const inspect_config = ref()
1715
1816
const namespaceId = ref(Number.parseInt(route.query.namespace_id as string) || 0)
19-
const namespaces = ref<Namespace[]>([])
20-
21-
onMounted(async () => {
22-
let page = 1
23-
while (true) {
24-
try {
25-
const { data, pagination } = await namespace.getList({ page })
26-
if (!data || !pagination)
27-
return
28-
namespaces.value.push(...data)
29-
if (data.length < pagination?.per_page) {
30-
return
31-
}
32-
page++
33-
}
34-
catch {
35-
return
36-
}
37-
}
38-
})
3917
4018
watch(route, () => {
4119
inspect_config.value?.test()
@@ -106,7 +84,7 @@ function handleAddStream() {
10684

10785
<template #beforeCardBody>
10886
<InspectConfig ref="inspect_config" />
109-
<NamespaceTabs v-model:active-key="namespaceId" :namespaces="namespaces" />
87+
<NamespaceTabs v-model:active-key="namespaceId" />
11088
</template>
11189

11290
<template #afterActions="{ record }">

0 commit comments

Comments
 (0)