diff --git a/clients/ts-sdk/openapi.json b/clients/ts-sdk/openapi.json index 4d6be9fa3..114f27f0e 100644 --- a/clients/ts-sdk/openapi.json +++ b/clients/ts-sdk/openapi.json @@ -10698,7 +10698,8 @@ }, "total_pages": { "type": "integer", - "format": "int32" + "format": "int32", + "minimum": 0 } } }, diff --git a/frontends/search/src/components/OrgGroupPageView.tsx b/frontends/search/src/components/OrgGroupPageView.tsx index 9558a4833..dce5a9b75 100644 --- a/frontends/search/src/components/OrgGroupPageView.tsx +++ b/frontends/search/src/components/OrgGroupPageView.tsx @@ -1,5 +1,9 @@ import { FiTrash } from "solid-icons/fi"; -import { isChunkGroupPageDTO, type ChunkGroupDTO } from "../utils/apiTypes"; +import { + indirectHasOwnProperty, + isChunkGroupPageDTO, + type ChunkGroupDTO, +} from "../utils/apiTypes"; import { For, Setter, @@ -20,6 +24,11 @@ export interface GroupUserPageViewProps { setShowConfirmModal: Setter; } +export type GetChunkGroupCountResponse = { + count: number; + group_id: string; +}; + export const GroupUserPageView = (props: GroupUserPageViewProps) => { const apiHost = import.meta.env.VITE_API_HOST as string; const datasetAndUserContext = useContext(DatasetAndUserContext); @@ -27,6 +36,9 @@ export const GroupUserPageView = (props: GroupUserPageViewProps) => { const $dataset = datasetAndUserContext.currentDataset; const $user = datasetAndUserContext.user; const [groups, setGroups] = createSignal([]); + const [groupCounts, setGroupCounts] = createSignal< + GetChunkGroupCountResponse[] + >([]); const [groupPage, setGroupPage] = createSignal(1); const [groupPageCount, setGroupPageCount] = createSignal(1); const [deleting, setDeleting] = createSignal(false); @@ -34,6 +46,52 @@ export const GroupUserPageView = (props: GroupUserPageViewProps) => { const serverConfig = useDatasetServerConfig(); + createEffect(() => { + const currentDataset = $dataset?.(); + if (!currentDataset) return; + + const all_counts = groups().map(async (group) => { + const response = await fetch(`${apiHost}/chunk_group/count`, { + method: "POST", + credentials: "include", + body: JSON.stringify({ group_id: group.id }), + headers: { + "X-API-version": "2.0", + "TR-Dataset": currentDataset.dataset.id, + "Content-Type": "application/json", + }, + }); + + if (response.ok) { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const data = await response.json(); + console.log("data", data); + if ( + data !== null && + typeof data === "object" && + indirectHasOwnProperty(data, "count") && + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + typeof data.count === "number" && + indirectHasOwnProperty(data, "group_id") && + // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access + typeof data.group_id === "string" + ) { + console.log("Invalid response", data); + return { + group_id: data.group_id, + count: data.count, + } as GetChunkGroupCountResponse; + } + } + }); + + void Promise.all(all_counts).then((counts) => { + const filteredGroupCounts = counts.filter((c) => c !== undefined); + console.log("setGroupCounts", filteredGroupCounts); + setGroupCounts(filteredGroupCounts); + }); + }); + createEffect(() => { const userId = $user?.()?.id; if (userId === undefined) return; @@ -149,7 +207,7 @@ export const GroupUserPageView = (props: GroupUserPageViewProps) => { scope="col" class="px-3 py-3.5 text-left text-base font-semibold dark:text-white" > - Description + Chunk Count { - {group.description} + { + groupCounts().find((c) => c.group_id == group.id) + ?.count + } {getLocalTime(group.created_at).toLocaleDateString() +