1
- import {
2
- useMemo ,
3
- useState ,
4
- } from 'react' ;
1
+ import { useMemo } from 'react' ;
5
2
import {
6
3
gql ,
7
4
useQuery ,
8
5
} from '@apollo/client' ;
9
6
import {
10
7
Button ,
8
+ Chip ,
11
9
createDateColumn ,
12
10
createStringColumn ,
13
11
Pager ,
@@ -17,9 +15,12 @@ import {
17
15
import Container from '#components/Container' ;
18
16
import { createElementColumn } from '#components/CreateElementColumn' ;
19
17
import {
18
+ ContentEnumsQuery ,
19
+ ContentEnumsQueryVariables ,
20
20
ContentListQuery ,
21
21
ContentListQueryVariables ,
22
22
} from '#generated/types/graphql' ;
23
+ import useFilterState from '#hooks/useFilterState' ;
23
24
24
25
import ContentActions from './ContentActions' ;
25
26
@@ -29,14 +30,14 @@ type ContentListTable = NonNullable<NonNullable<NonNullable<ContentListQuery['pr
29
30
30
31
const contentKeySelector = ( option : ContentListTable ) => option . id ;
31
32
32
- const PAGE_SIZE = 5 ;
33
+ const PAGE_SIZE = 2 ;
33
34
34
35
const CREATE_CONTENT_QUERY = gql `
35
36
query ContentList(
36
- $input : OffsetPaginationInput
37
+ $pagination : OffsetPaginationInput,
37
38
) {
38
39
private {
39
- contents(pagination: $input ) {
40
+ contents(pagination: $pagination ) {
40
41
count
41
42
items {
42
43
createdAt
@@ -53,31 +54,61 @@ const CREATE_CONTENT_QUERY = gql`
53
54
}
54
55
` ;
55
56
57
+ const CONTENT_ENUMS = gql `
58
+ query ContentEnums {
59
+ enums {
60
+ ContentDocumentStatus {
61
+ key
62
+ label
63
+ }
64
+ ContentDocumentType {
65
+ key
66
+ label
67
+ }
68
+ }
69
+ }
70
+ ` ;
71
+
72
+ const statusVariant : Record < string , string > = {
73
+ Pending : 'default' ,
74
+ 'Text extracted' : 'default' ,
75
+ 'Added to vector' : 'success' ,
76
+ 'Deleted from vector' : 'warning' ,
77
+ Failure : 'danger' ,
78
+ } ;
56
79
/** @knipignore */
57
80
// eslint-disable-next-line import/prefer-default-export
58
81
export function Component ( ) {
59
- const [ page , setPage ] = useState < number > ( 1 ) ;
82
+ const {
83
+ page,
84
+ setPage,
85
+ } = useFilterState < {
86
+ createdAtGte ?: string ;
87
+ createdAtLte ?: string ;
88
+ documentType ?: string ;
89
+ documentStatus ?: string ;
90
+ } > ( {
91
+ pageSize : PAGE_SIZE ,
92
+ filter : { } ,
93
+ } ) ;
94
+
60
95
const {
61
96
data : contentResult ,
62
97
} = useQuery < ContentListQuery , ContentListQueryVariables > (
63
98
CREATE_CONTENT_QUERY ,
64
- {
65
- variables : {
66
- input : {
67
- limit : PAGE_SIZE ,
68
- offset : page ,
69
- } ,
70
- } ,
71
- } ,
72
99
) ;
73
100
74
- const columns = useMemo ( ( ) => ( [
75
- createStringColumn < ContentListTable , string > (
76
- 'sn' ,
77
- 'S.N' ,
78
- ( item ) => ( item . id ) ,
79
- ) ,
101
+ const {
102
+ data : contentEnumsResponse ,
103
+ } = useQuery < ContentEnumsQuery , ContentEnumsQueryVariables > (
104
+ CONTENT_ENUMS ,
105
+ ) ;
106
+
107
+ const documentType = contentEnumsResponse ?. enums . ContentDocumentType ;
108
+
109
+ const documentStatus = contentEnumsResponse ?. enums . ContentDocumentStatus ;
80
110
111
+ const columns = useMemo ( ( ) => ( [
81
112
createStringColumn < ContentListTable , string > (
82
113
'title' ,
83
114
'Title' ,
@@ -93,30 +124,50 @@ export function Component() {
93
124
createStringColumn < ContentListTable , string > (
94
125
'documentTypeDisplay' ,
95
126
'File Type' ,
96
- ( item ) => item . documentType ,
127
+ ( item ) => documentType ?. find (
128
+ ( type ) => type . key === item . documentType ,
129
+ ) ?. label ,
97
130
) ,
98
131
createStringColumn < ContentListTable , string > (
99
132
'tag' ,
100
133
'Tag' ,
101
134
( item ) => item . tag . map ( ( tag : { name : string ; } ) => tag . name ) . join ( ',' ) ,
102
135
{ columnClassName : styles . actions } ,
103
136
) ,
104
- createStringColumn < ContentListTable , string > (
137
+ createElementColumn < ContentListTable , string ,
138
+ { status : string | undefined ; variant : string } > (
105
139
'documentStatusDisplay' ,
106
140
'Status' ,
107
- ( item ) => item . documentStatus ,
141
+ ( { status } ) => (
142
+ < Chip
143
+ className = { styles . status }
144
+ label = { status }
145
+ />
146
+ ) ,
147
+ ( _key , item ) => {
148
+ const statusLabel = documentStatus ?. find (
149
+ ( status ) => status . key === item . documentStatus ,
150
+ ) ?. label ;
151
+ const variant = statusLabel ? statusVariant [ statusLabel ] : '' ;
152
+ return {
153
+ status : statusLabel ,
154
+ variant,
155
+ } ;
156
+ } ,
108
157
{ columnClassName : styles . actions } ,
109
158
) ,
110
- createElementColumn < ContentListTable , string , { contentId : number } > (
159
+ createElementColumn < ContentListTable , string , { id : number } > (
111
160
'actions' ,
112
161
'Actions' ,
113
162
ContentActions ,
114
163
( _key , datum ) => ( {
115
- contentId : Number ( datum . id ) ,
164
+ id : Number ( datum . id ) ,
116
165
} ) ,
117
166
{ columnClassName : styles . actions } ,
118
167
) ,
119
- ] ) , [ ] ) ;
168
+ ] ) , [ documentType , documentStatus ] ) ;
169
+
170
+ const data = contentResult ?. private . contents ;
120
171
121
172
return (
122
173
< Container
@@ -138,7 +189,7 @@ export function Component() {
138
189
infoHidden
139
190
itemsPerPageControlHidden
140
191
activePage = { page }
141
- itemsCount = { contentResult ?. private . contents . count ?? 0 }
192
+ itemsCount = { data ? .count ?? 0 }
142
193
maxItemsPerPage = { PAGE_SIZE }
143
194
onActivePageChange = { setPage }
144
195
/>
@@ -148,7 +199,7 @@ export function Component() {
148
199
className = { styles . table }
149
200
headerCellClassName = { styles . headerCell }
150
201
headerRowClassName = { styles . headerRow }
151
- data = { contentResult ?. private . contents . items }
202
+ data = { data ? .items }
152
203
columns = { columns }
153
204
keySelector = { contentKeySelector }
154
205
/>
0 commit comments