@@ -5,13 +5,13 @@ import {
5
5
} from '@apollo/client' ;
6
6
import {
7
7
Button ,
8
- Chip ,
9
8
createDateColumn ,
10
9
createStringColumn ,
11
10
Pager ,
12
11
Table ,
13
12
} from '@togglecorp/toggle-ui' ;
14
13
14
+ import Chip , { ChipVariant } from '#components/Chip' ;
15
15
import Container from '#components/Container' ;
16
16
import { createElementColumn } from '#components/CreateElementColumn' ;
17
17
import {
@@ -26,11 +26,11 @@ import ContentActions from './ContentActions';
26
26
27
27
import styles from './styles.module.css' ;
28
28
29
- type ContentListTable = NonNullable < NonNullable < NonNullable < ContentListQuery [ 'private' ] > [ 'contents' ] > [ 'items' ] > [ number ] ;
29
+ type ContentListTable = NonNullable < NonNullable < NonNullable < ContentListQuery [ 'private' ] > [ 'contents' ] > [ 'items' ] > [ number ] & { serialNumber : string ; } ;
30
30
31
31
const contentKeySelector = ( option : ContentListTable ) => option . id ;
32
32
33
- const PAGE_SIZE = 2 ;
33
+ const PAGE_SIZE = 10 ;
34
34
35
35
const CREATE_CONTENT_QUERY = gql `
36
36
query ContentList(
@@ -71,7 +71,7 @@ const CONTENT_ENUMS = gql`
71
71
72
72
const statusVariant : Record < string , string > = {
73
73
Pending : 'default' ,
74
- 'Text extracted' : 'default ' ,
74
+ 'Text extracted' : 'primary ' ,
75
75
'Added to vector' : 'success' ,
76
76
'Deleted from vector' : 'warning' ,
77
77
Failure : 'danger' ,
@@ -86,16 +86,24 @@ export function Component() {
86
86
createdAtGte ?: string ;
87
87
createdAtLte ?: string ;
88
88
documentType ?: string ;
89
- documentStatus ?: string ;
89
+ documentStatus ?: string ;
90
90
} > ( {
91
91
pageSize : PAGE_SIZE ,
92
92
filter : { } ,
93
93
} ) ;
94
-
95
94
const {
96
95
data : contentResult ,
97
96
} = useQuery < ContentListQuery , ContentListQueryVariables > (
98
97
CREATE_CONTENT_QUERY ,
98
+ {
99
+ variables : {
100
+ pagination : {
101
+ limit : 10 ,
102
+ offset : ( page - 1 ) * PAGE_SIZE ,
103
+ } ,
104
+
105
+ } ,
106
+ } ,
99
107
) ;
100
108
101
109
const {
@@ -108,7 +116,17 @@ export function Component() {
108
116
109
117
const documentStatus = contentEnumsResponse ?. enums . ContentDocumentStatus ;
110
118
119
+ const data = contentResult ?. private . contents . items ?. map ( ( user , index ) => ( {
120
+ ...user ,
121
+ serialNumber : ( page - 1 ) * PAGE_SIZE + index + 1 ,
122
+ } ) ) as unknown as ContentListTable [ ] ;
123
+
111
124
const columns = useMemo ( ( ) => ( [
125
+ createStringColumn < ContentListTable , string > (
126
+ 'sn' ,
127
+ 'S.N' ,
128
+ ( item ) => String ( item . serialNumber ) ,
129
+ ) ,
112
130
createStringColumn < ContentListTable , string > (
113
131
'title' ,
114
132
'Title' ,
@@ -125,8 +143,9 @@ export function Component() {
125
143
'documentTypeDisplay' ,
126
144
'File Type' ,
127
145
( item ) => documentType ?. find (
128
- ( type ) => type . key === item . documentType ,
146
+ ( type : { key : string ; } ) => type . key === item . documentType ,
129
147
) ?. label ,
148
+ { columnClassName : styles . actions } ,
130
149
) ,
131
150
createStringColumn < ContentListTable , string > (
132
151
'tag' ,
@@ -138,15 +157,16 @@ export function Component() {
138
157
{ status : string | undefined ; variant : string } > (
139
158
'documentStatusDisplay' ,
140
159
'Status' ,
141
- ( { status } ) => (
160
+ ( { status, variant } ) => (
142
161
< Chip
143
162
className = { styles . status }
144
163
label = { status }
164
+ variant = { variant as ChipVariant }
145
165
/>
146
166
) ,
147
167
( _key , item ) => {
148
168
const statusLabel = documentStatus ?. find (
149
- ( status ) => status . key === item . documentStatus ,
169
+ ( status : { key : string ; } ) => status . key === item . documentStatus ,
150
170
) ?. label ;
151
171
const variant = statusLabel ? statusVariant [ statusLabel ] : '' ;
152
172
return {
@@ -156,7 +176,7 @@ export function Component() {
156
176
} ,
157
177
{ columnClassName : styles . actions } ,
158
178
) ,
159
- createElementColumn < ContentListTable , string , { id : number } > (
179
+ createElementColumn < ContentListTable , string , { id : number } > (
160
180
'actions' ,
161
181
'Actions' ,
162
182
ContentActions ,
@@ -167,8 +187,6 @@ export function Component() {
167
187
) ,
168
188
] ) , [ documentType , documentStatus ] ) ;
169
189
170
- const data = contentResult ?. private . contents ;
171
-
172
190
return (
173
191
< Container
174
192
className = { styles . container }
@@ -178,7 +196,7 @@ export function Component() {
178
196
< Button
179
197
name = "Add Content"
180
198
variant = "primary"
181
- onClick = { ( ) => { } }
199
+ onClick = { ( ) => { } }
182
200
disabled
183
201
>
184
202
Add
@@ -189,7 +207,7 @@ export function Component() {
189
207
infoHidden
190
208
itemsPerPageControlHidden
191
209
activePage = { page }
192
- itemsCount = { data ?. count ?? 0 }
210
+ itemsCount = { contentResult ?. private ?. contents ?. count ?? 0 }
193
211
maxItemsPerPage = { PAGE_SIZE }
194
212
onActivePageChange = { setPage }
195
213
/>
@@ -199,7 +217,7 @@ export function Component() {
199
217
className = { styles . table }
200
218
headerCellClassName = { styles . headerCell }
201
219
headerRowClassName = { styles . headerRow }
202
- data = { data ?. items }
220
+ data = { data }
203
221
columns = { columns }
204
222
keySelector = { contentKeySelector }
205
223
/>
0 commit comments