-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
- Loading branch information
Frank Jogeleit
committed
Feb 7, 2024
1 parent
b4524b2
commit d88bb06
Showing
21 changed files
with
164 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
type Store = { | ||
kinds: { namespaced: string[]; cluster: string[] }, | ||
namespaces: string[] | ||
categories: string[] | ||
} | ||
|
||
const sources: { [source: string]: Store } = {} | ||
|
||
export const useSourceStore = (source?: string) => { | ||
const key = source || 'global' | ||
|
||
if (!sources[key]) { | ||
sources[key] = reactive({ | ||
kinds: { namespaced: [], cluster: [] }, | ||
namespaces: [], | ||
categories: [], | ||
}) | ||
} | ||
|
||
const store = sources[key] | ||
|
||
const loading = ref(false) | ||
const error = ref<Error | null>(null) | ||
|
||
const load = () => { | ||
loading.value = true | ||
error.value = null | ||
|
||
return Promise.all([ | ||
callAPI(api => api.namespaces({ sources: source ? [source] : undefined })), | ||
callAPI(api => api.namespacedKinds(source)), | ||
callAPI(api => api.clusterKinds(source)), | ||
callAPI(api => api.categoryTree(undefined, { sources: source ? [source] : undefined })), | ||
]).then(([namespaces, nsKinds, clusterKinds, categoryTrees]) => { | ||
store.kinds.namespaced = nsKinds || [] | ||
store.kinds.cluster = clusterKinds || [] | ||
store.namespaces = namespaces || [] | ||
store.categories = (categoryTrees || []).reduce<string[]>((categories, source) => { | ||
return [...categories, ...source.categories.map(c => c.name)] | ||
}, []) | ||
}).catch((err) => { | ||
error.value = err | ||
}).finally(() => { | ||
loading.value = false | ||
}) | ||
} | ||
|
||
return { | ||
store, | ||
loading, | ||
error, | ||
load | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.