Skip to content

Commit

Permalink
fix dashboard kind filter
Browse files Browse the repository at this point in the history
Signed-off-by: Frank Jogeleit <[email protected]>
  • Loading branch information
Frank Jogeleit committed Apr 29, 2024
1 parent 538cb9c commit 8ce8c59
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
21 changes: 15 additions & 6 deletions frontend/composables/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ type Store = {
kinds: { namespaced: string[]; cluster: string[] },
namespaces: string[]
categories: string[]
key: string
}

const sources: { [source: string]: Store } = reactive({})

export const useSourceStore = (key?: string) => {
const getStore = (key?: string) => {
if (!key) { key = 'global' }

if (!sources[key]) {
sources[key] = {
kinds: { namespaced: [], cluster: [] },
namespaces: [],
categories: [],
key,
}
}

const store = sources[key]
return sources[key]
}

export const useSourceStore = (key?: string) => {
const store = getStore(key)

const loading = ref(false)
const error = ref<Error | null>(null)
Expand All @@ -29,7 +35,10 @@ export const useSourceStore = (key?: string) => {
loading.value = true
error.value = null

let loadStore = store

if (typeof source === 'string') {
loadStore = getStore(source)
source = [source]
} else if (Array.isArray(source) && !source.length) {
source = undefined
Expand All @@ -41,10 +50,10 @@ export const useSourceStore = (key?: string) => {
callAPI(api => api.clusterKinds(source as string[])),
callAPI(api => api.categoryTree(undefined, { sources: source as string[] })),
]).then(([namespaces, nsKinds, clusterKinds, categoryTrees]) => {
store.kinds.namespaced = nsKinds || []
store.kinds.cluster = clusterKinds || []
store.namespaces = namespaces || []
store.categories = (categoryTrees || []).reduce<string[]>((categories, source) => {
loadStore.kinds.namespaced = nsKinds || []
loadStore.kinds.cluster = clusterKinds || []
loadStore.namespaces = namespaces || []
loadStore.categories = (categoryTrees || []).reduce<string[]>((categories, source) => {
return [...categories, ...source.categories.map(c => c.name)]
}, [])
}).catch((err) => {
Expand Down
11 changes: 9 additions & 2 deletions frontend/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ watch(filter, onChange(refresh))
provide(APIFilter, filter)
useSourceContext(computed(() => {
const source = computed(() => {
if (data.value?.sources.length !== 1) return undefined
return data.value?.sources[0]
}))
})
watch(source, (s?: string) => {
if (!s) return
store.load(s)
})
useSourceContext(source)
useStatusProvider(data)
</script>

0 comments on commit 8ce8c59

Please sign in to comment.