Skip to content

Commit 668edce

Browse files
authored
Merge pull request #352 from PrivateAIM/refactor-data-store
Refactor data store workflow
2 parents a91115e + 0b9c8f2 commit 668edce

18 files changed

Lines changed: 3623 additions & 1112 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,5 @@ sw.*
9999
.output
100100

101101
# Claude
102-
.claude/
102+
.claude/
103+
docs/

app/components/data-stores/DataStoreList.vue

Lines changed: 4 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,12 @@
11
<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";
123
import DetailedDataStoreTable from "~/components/data-stores/DetailedDataStoreTable.vue";
134
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();
976
987
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();
10310
}
10411
</script>
10512

0 commit comments

Comments
 (0)