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() { export default function Namespaces() {
const [namespaces, setNamespace] = useState<Namespace[]>([]) const [namespaces, setNamespace] = useState<Namespace[]>([])
const [clusterName, setClusterName] = useState<string>('')
// const namespaces = [ // const namespaces = [
// { name: 'default', status: 'Active', age: '2d', labels: 'app=web' }, // { name: 'default', status: 'Active', age: '2d', labels: 'app=web' },
// { name: 'kube-system', status: 'Active', age: '2d', labels: 'system' }, // { name: 'kube-system', status: 'Active', age: '2d', labels: 'system' },
@@ -14,35 +15,42 @@ export default function Namespaces() {
// { name: 'ingress-nginx', status: 'Active', age: '1d', labels: 'ingress' }, // { 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 { useEffect(() => {
const data = await response.json() const storedClusterName = localStorage.getItem('selectedCluster')
console.error(data.message || 'Failed to fetch clusters') if (storedClusterName) {
} setClusterName(storedClusterName)
} catch (error) {
console.error('Failed to fetch clusters', error)
} }
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)
}
} }
useEffect(() => {
fetchNamespaces()
}, [])
return ( return (
<div className="space-y-6"> <div className="space-y-6">
<div> <div>