|
1 | 1 | <script lang="ts" setup> |
2 | | -import { watchEffect } from "vue"; |
3 | | -import { getDataStores, getProjects } from "~/composables/useAPIFetch"; |
4 | | -import { formatDataRow } from "~/utils/format-data-row"; |
5 | | -import type { ModifiedDetailedService } from "~/services/modifiedApiInterfaces"; |
6 | | -import type { |
7 | | - DetailedAnalysis, |
8 | | - ListServices, |
9 | | - Project, |
10 | | - Route, |
11 | | -} from "~/services/Api"; |
| 2 | +import { useDataStoreList } from "~/composables/useDataStoreList"; |
12 | 3 | import DetailedDataStoreTable from "~/components/data-stores/DetailedDataStoreTable.vue"; |
13 | 4 |
|
14 | | -const dataStores = ref<ModifiedDetailedService[]>([]); |
15 | | -const projectNameMap = ref<Map<string, string | undefined>>( |
16 | | - new Map<string, string | undefined>(), |
17 | | -); |
18 | | -
|
19 | | -const loading = ref(true); |
20 | | -
|
21 | | -const dataRowUnixCols = ["created_at", "updated_at"]; |
22 | | -const expandRowEntries = []; |
23 | | -
|
24 | | -const { |
25 | | - data: dsResp, |
26 | | - status: dsStatus, |
27 | | - error: dsError, |
28 | | - refresh: dsRefresh, |
29 | | -} = await getDataStores(true, { lazy: true }); |
30 | | -
|
31 | | -const { data: projectResp } = await getProjects({ lazy: true }); |
32 | | -
|
33 | | -watchEffect(() => { |
34 | | - if (dsResp.value?.data) { |
35 | | - const dataStoreData = dsResp.value.data as ListServices; |
36 | | - loadDetailedDataStoreTable(dataStoreData, dsStatus.value, dsError); |
37 | | - } |
38 | | -}); |
39 | | -
|
40 | | -watchEffect(() => { |
41 | | - if (projectResp.value) { |
42 | | - const projects = projectResp.value || []; |
43 | | - projectNameMap.value = mapDataFromHub(projects); |
44 | | - } |
45 | | -}); |
46 | | -
|
47 | | -async function loadDetailedDataStoreTable( |
48 | | - responseData: ListServices, |
49 | | - status: string, |
50 | | - error, |
51 | | -) { |
52 | | - if (status === "success") { |
53 | | - let formattedDataStores = formatDataRow( |
54 | | - responseData, |
55 | | - dataRowUnixCols, |
56 | | - expandRowEntries, |
57 | | - ) as ModifiedDetailedService[]; |
58 | | -
|
59 | | - formattedDataStores = formattedDataStores.filter( |
60 | | - (store: ModifiedDetailedService) => store.name !== "kong-admin-service", |
61 | | - ); |
62 | | -
|
63 | | - formattedDataStores.forEach((store: ModifiedDetailedService) => { |
64 | | - if (store.routes) { |
65 | | - store.routes = formatDataRow( |
66 | | - store.routes, |
67 | | - dataRowUnixCols, |
68 | | - expandRowEntries, |
69 | | - ); |
70 | | - store.routes?.forEach((proj: Route) => { |
71 | | - proj["projectId"] = extractProjectIdFromPath(proj.paths! as string[]); |
72 | | - }); |
73 | | - } |
74 | | - }); |
75 | | - dataStores.value = formattedDataStores; |
76 | | - } else if (error.value?.statusCode === 500) { |
77 | | - dataStores.value = []; |
78 | | - } |
79 | | - loading.value = false; |
80 | | -} |
81 | | -
|
82 | | -function mapDataFromHub(hubData: Project[] | DetailedAnalysis[]) { |
83 | | - let mappedNames = new Map<string, string | undefined>(); |
84 | | - if (hubData && hubData.length > 0) { |
85 | | - hubData.forEach((entry: Project | DetailedAnalysis) => { |
86 | | - if (entry.id) { |
87 | | - mappedNames.set(entry.id, entry.name ? entry.name : "N/A"); |
88 | | - } |
89 | | - }); |
90 | | - } |
91 | | - return mappedNames; |
92 | | -} |
93 | | -
|
94 | | -function extractProjectIdFromPath(paths: string[]): string { |
95 | | - return paths[0].split("/")[1]; |
96 | | -} |
| 5 | +const { dataStores, projectNameMap, loading, refresh } = await useDataStoreList(); |
97 | 6 |
|
98 | 7 | function onDeleteDataStore(dsName: string) { |
99 | | - dataStores.value = dataStores.value.filter( |
100 | | - (store: ModifiedDetailedService) => store.name !== dsName, |
101 | | - ); |
102 | | - dsRefresh(); |
| 8 | + dataStores.value = dataStores.value.filter((store) => store.name !== dsName); |
| 9 | + refresh(); |
103 | 10 | } |
104 | 11 | </script> |
105 | 12 |
|
|
0 commit comments