fix namespace page
This commit is contained in:
@@ -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,35 +15,42 @@ 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(() => {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
fetchNamespaces()
|
||||
|
||||
}, [])
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div>
|
||||
|
||||
Reference in New Issue
Block a user