1
1
import { FiTrash } from "solid-icons/fi" ;
2
- import { isChunkGroupPageDTO , type ChunkGroupDTO } from "../utils/apiTypes" ;
2
+ import {
3
+ indirectHasOwnProperty ,
4
+ isChunkGroupPageDTO ,
5
+ type ChunkGroupDTO ,
6
+ } from "../utils/apiTypes" ;
3
7
import {
4
8
For ,
5
9
Setter ,
@@ -20,20 +24,76 @@ export interface GroupUserPageViewProps {
20
24
setShowConfirmModal : Setter < boolean > ;
21
25
}
22
26
27
+ export type GetChunkGroupCountResponse = {
28
+ count : number ;
29
+ group_id : string ;
30
+ } ;
31
+
23
32
export const GroupUserPageView = ( props : GroupUserPageViewProps ) => {
24
33
const apiHost = import . meta. env . VITE_API_HOST as string ;
25
34
const datasetAndUserContext = useContext ( DatasetAndUserContext ) ;
26
35
27
36
const $dataset = datasetAndUserContext . currentDataset ;
28
37
const $user = datasetAndUserContext . user ;
29
38
const [ groups , setGroups ] = createSignal < ChunkGroupDTO [ ] > ( [ ] ) ;
39
+ const [ groupCounts , setGroupCounts ] = createSignal <
40
+ GetChunkGroupCountResponse [ ]
41
+ > ( [ ] ) ;
30
42
const [ groupPage , setGroupPage ] = createSignal ( 1 ) ;
31
43
const [ groupPageCount , setGroupPageCount ] = createSignal ( 1 ) ;
32
44
const [ deleting , setDeleting ] = createSignal ( false ) ;
33
45
const [ loading , setLoading ] = createSignal ( true ) ;
34
46
35
47
const serverConfig = useDatasetServerConfig ( ) ;
36
48
49
+ createEffect ( ( ) => {
50
+ const currentDataset = $dataset ?.( ) ;
51
+ if ( ! currentDataset ) return ;
52
+
53
+ const all_counts = groups ( ) . map ( async ( group ) => {
54
+ const response = await fetch ( `${ apiHost } /chunk_group/count` , {
55
+ method : "POST" ,
56
+ credentials : "include" ,
57
+ body : JSON . stringify ( { group_id : group . id } ) ,
58
+ headers : {
59
+ "X-API-version" : "2.0" ,
60
+ "TR-Dataset" : currentDataset . dataset . id ,
61
+ "Content-Type" : "application/json" ,
62
+ } ,
63
+ } ) ;
64
+
65
+ if ( response . ok ) {
66
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
67
+ const data = await response . json ( ) ;
68
+ console . log ( "data" , data ) ;
69
+ if (
70
+ data !== null &&
71
+ typeof data === "object" &&
72
+ indirectHasOwnProperty ( data , "count" ) &&
73
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
74
+ typeof data . count === "number" &&
75
+ indirectHasOwnProperty ( data , "group_id" ) &&
76
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
77
+ typeof data . group_id === "string"
78
+ ) {
79
+ console . log ( "Invalid response" , data ) ;
80
+ return {
81
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
82
+ group_id : data . group_id ,
83
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
84
+ count : data . count ,
85
+ } as GetChunkGroupCountResponse ;
86
+ }
87
+ }
88
+ } ) ;
89
+
90
+ void Promise . all ( all_counts ) . then ( ( counts ) => {
91
+ const filteredGroupCounts = counts . filter ( ( c ) => c !== undefined ) ;
92
+ console . log ( "setGroupCounts" , filteredGroupCounts ) ;
93
+ setGroupCounts ( filteredGroupCounts ) ;
94
+ } ) ;
95
+ } ) ;
96
+
37
97
createEffect ( ( ) => {
38
98
const userId = $user ?.( ) ?. id ;
39
99
if ( userId === undefined ) return ;
@@ -149,7 +209,7 @@ export const GroupUserPageView = (props: GroupUserPageViewProps) => {
149
209
scope = "col"
150
210
class = "px-3 py-3.5 text-left text-base font-semibold dark:text-white"
151
211
>
152
- Description
212
+ Chunk Count
153
213
</ th >
154
214
< th
155
215
scope = "col"
@@ -181,7 +241,10 @@ export const GroupUserPageView = (props: GroupUserPageViewProps) => {
181
241
</ a >
182
242
</ td >
183
243
< td class = "whitespace-nowrap text-wrap px-3 py-4 text-sm text-gray-900 dark:text-gray-300" >
184
- { group . description }
244
+ {
245
+ groupCounts ( ) . find ( ( c ) => c . group_id == group . id )
246
+ ?. count
247
+ }
185
248
</ td >
186
249
< td class = "whitespace-nowrap px-3 py-4 text-left text-sm text-gray-900 dark:text-gray-300" >
187
250
{ getLocalTime ( group . created_at ) . toLocaleDateString ( ) +
0 commit comments