Skip to content

Commit

Permalink
refactor: restructure clients module for better maintainability
Browse files Browse the repository at this point in the history
Signed-off-by: hexiaodai <[email protected]>
  • Loading branch information
hexiaodai committed Jan 14, 2025
1 parent 5a42b5b commit e538ab0
Show file tree
Hide file tree
Showing 51 changed files with 5,025 additions and 2,935 deletions.
22 changes: 17 additions & 5 deletions src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { useState } from 'react'
import { useEffect, useRef, useState } from 'react'
import { App, ConfigProvider, Select } from 'antd'
import { PageContainer, ProLayout } from '@ant-design/pro-components'
import { NavLink, useLocation } from 'react-router-dom'
import { LayoutSettings } from '@/layout-config'
import { NamespaceProvider, useNamespace } from '@/common/context'
import { ResourceType } from '@/clients/ts/types/types'
import { useListResources } from './hooks/use-resource'
import { Namespace, watchNamespaces } from './clients/namespace'
import AppRouter from '@/router'
import styles from '@/styles/app.module.less'
import useUnmount from './hooks/use-unmount'

export default () => {
const location = useLocation()
Expand All @@ -16,7 +16,19 @@ export default () => {

const [collapsed, setCollapsed] = useState(false)

const { resources: namespaces } = useListResources(ResourceType.NAMESPACE)
const [namespaces, setNamespaces] = useState<Namespace[]>()

const abortCtrl = useRef<AbortController>()

useEffect(() => {
abortCtrl.current?.abort()
abortCtrl.current = new AbortController()
watchNamespaces(setNamespaces, abortCtrl.current.signal, undefined, undefined, undefined)
}, [])

useUnmount(() => {
abortCtrl.current?.abort()
})

return (
<ConfigProvider
Expand Down Expand Up @@ -49,7 +61,7 @@ export default () => {
onChange={(value) => setNamespace(value)}
options={[
{ value: '', label: '全部工作空间' },
...namespaces.map((ns: any) => ({
...(namespaces ?? []).map((ns: any) => ({
value: ns.metadata.name,
label: ns.metadata.name
}))
Expand Down
Loading

0 comments on commit e538ab0

Please sign in to comment.