fix namespace page

This commit is contained in:
behrooz
2025-11-06 19:50:01 +03:30
parent c17b17c23a
commit 94f766d199

View File

@@ -7,6 +7,7 @@ interface Namespace {
}
export default function Namespaces() {
const [namespaces, setNamespace] = useState<Namespace[]>([])
const [clusterName, setClusterName] = useState<string>('')
// const namespaces = [
// { name: 'default', status: 'Active', age: '2d', labels: 'app=web' },
// { name: 'kube-system', status: 'Active', age: '2d', labels: 'system' },
@@ -14,34 +15,41 @@ export default function Namespaces() {
// { name: 'ingress-nginx', status: 'Active', age: '1d', labels: 'ingress' },
// ]
const fetchNamespaces = async () => {
try {
const response = await fetch('http://localhost:8082/cluster_namespaces?Name=test-cluster', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `${localStorage.getItem('auth:token') || ''}`
},
})
if (response.ok) {
const data = await response.json()
setNamespace(data || [])
} else {
const data = await response.json()
console.error(data.message || 'Failed to fetch clusters')
}
} catch (error) {
console.error('Failed to fetch clusters', error)
}
}
useEffect(() => {
fetchNamespaces()
}, [])
useEffect(() => {
const storedClusterName = localStorage.getItem('selectedCluster')
if (storedClusterName) {
setClusterName(storedClusterName)
}
fetchNamespaces()
}, [clusterName])
const fetchNamespaces = async () => {
if (!clusterName) return
try {
const response = await fetch(`http://localhost:8082/cluster_namespaces?Name=${encodeURIComponent(clusterName)}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
'Authorization': `${localStorage.getItem('auth:token') || ''}`
},
})
if (response.ok) {
const data = await response.json()
setNamespace(data || [])
} else {
const data = await response.json()
console.error(data.message || 'Failed to fetch clusters')
}
} catch (error) {
console.error('Failed to fetch clusters', error)
}
}
return (
<div className="space-y-6">