1
1
import React , { useEffect } from 'react' ;
2
- import { SearchInput , Title , Toolbar , ToolbarContent , ToolbarItem , Pagination } from '@patternfly/react-core' ;
2
+ import {
3
+ SearchInput ,
4
+ Title ,
5
+ Toolbar ,
6
+ ToolbarContent ,
7
+ ToolbarItem ,
8
+ Pagination ,
9
+ Drawer ,
10
+ DrawerPanelContent ,
11
+ DrawerContent ,
12
+ DrawerContentBody ,
13
+ DrawerHead ,
14
+ DrawerActions ,
15
+ DrawerCloseButton ,
16
+ Button
17
+ } from '@patternfly/react-core' ;
3
18
import { Table , Thead , Tr , Th , ThProps , Tbody , Td } from '@patternfly/react-table' ;
4
19
import { fetch } from 'cross-fetch'
5
-
20
+ import { DetailsDrawer } from './DetailsDrawer' ;
21
+ import { MouseEventHandler } from 'react' ;
6
22
interface ImageData {
7
23
name : string ;
8
24
version : string ;
@@ -22,6 +38,23 @@ export const ImageTable: React.FunctionComponent = () => {
22
38
const [ activeSortDirection , setActiveSortDirection ] = React . useState < 'asc' | 'desc' | undefined > ( undefined ) ;
23
39
const [ page , setPage ] = React . useState ( 1 ) ;
24
40
const [ perPage , setPerPage ] = React . useState ( 20 ) ;
41
+ const [ isDrawerExpanded , setIsExpanded ] = React . useState ( false ) ;
42
+ const [ selectedImage , setSelectedImage ] = React . useState ( { } ) ;
43
+ const drawerRef = React . useRef < HTMLDivElement > ( ) ;
44
+
45
+ const onDrawerExpand = ( ) => {
46
+ drawerRef . current && drawerRef . current . focus ( ) ;
47
+ } ;
48
+
49
+ const onDrawerOpenClick = ( details ) => {
50
+ setIsExpanded ( true ) ;
51
+ setSelectedImage ( details )
52
+ } ;
53
+
54
+ const onDrawerCloseClick = ( ) => {
55
+ setIsExpanded ( false ) ;
56
+ } ;
57
+
25
58
const columnNames = {
26
59
name : 'Name' ,
27
60
provider : 'Provider' ,
@@ -105,6 +138,15 @@ export const ImageTable: React.FunctionComponent = () => {
105
138
}
106
139
} ) ;
107
140
}
141
+
142
+ const panelContent = (
143
+ < DetailsDrawer
144
+ onCloseClick = { onDrawerCloseClick }
145
+ drawerRef = { drawerRef }
146
+ isExpanded = { isDrawerExpanded }
147
+ details = { selectedImage } />
148
+ ) ;
149
+
108
150
return (
109
151
< React . Fragment >
110
152
< Title headingLevel = 'h1' > Browse Images</ Title >
@@ -132,33 +174,50 @@ export const ImageTable: React.FunctionComponent = () => {
132
174
</ ToolbarItem >
133
175
</ ToolbarContent >
134
176
</ Toolbar >
135
- < Table
136
- aria-label = "RHEL Cloud Images"
137
- variant = { 'compact' }
138
- >
139
- < Thead >
140
- < Tr >
141
- < Th sort = { getSortParams ( 0 ) } > { columnNames . name } </ Th >
142
- < Th sort = { getSortParams ( 1 ) } > { columnNames . provider } </ Th >
143
- < Th sort = { getSortParams ( 2 ) } > { columnNames . region } </ Th >
144
- < Th sort = { getSortParams ( 3 ) } > { columnNames . arch } </ Th >
145
- < Th sort = { getSortParams ( 4 ) } > { columnNames . date } </ Th >
146
- < Th > </ Th >
147
- </ Tr >
148
- </ Thead >
149
- < Tbody >
150
- { sortedImageData . map ( ( image : ImageData ) => (
151
- < Tr key = { image . name } >
152
- < Td dataLabel = { columnNames . name } > { image . name } </ Td >
153
- < Td dataLabel = { columnNames . provider } > { image . provider } </ Td >
154
- < Td dataLabel = { columnNames . region } > { image . region } </ Td >
155
- < Td dataLabel = { columnNames . arch } > { image . arch } </ Td >
156
- < Td dataLabel = { columnNames . date } > < p > { new Date ( image . date ) . toDateString ( ) } </ p > </ Td >
157
- < Td > { < a href = '' > Launch now</ a > } </ Td >
158
- </ Tr >
159
- ) ) }
160
- </ Tbody >
161
- </ Table >
177
+
178
+ < Drawer isExpanded = { isDrawerExpanded } position = "right" onExpand = { onDrawerExpand } >
179
+ < DrawerContent panelContent = { panelContent } >
180
+ < DrawerContentBody >
181
+
182
+ < Table
183
+ aria-label = "RHEL Cloud Images"
184
+ variant = { 'compact' }
185
+ >
186
+ < Thead >
187
+ < Tr >
188
+ < Th sort = { getSortParams ( 0 ) } > { columnNames . name } </ Th >
189
+ < Th sort = { getSortParams ( 1 ) } > { columnNames . provider } </ Th >
190
+ < Th sort = { getSortParams ( 2 ) } > { columnNames . region } </ Th >
191
+ < Th sort = { getSortParams ( 3 ) } > { columnNames . arch } </ Th >
192
+ < Th sort = { getSortParams ( 4 ) } > { columnNames . date } </ Th >
193
+ < Th > </ Th >
194
+ </ Tr >
195
+ </ Thead >
196
+ < Tbody >
197
+ { sortedImageData . map ( ( image : ImageData ) => (
198
+ < Tr key = { image . name } >
199
+ < Td dataLabel = { columnNames . name } > { image . name } </ Td >
200
+ < Td dataLabel = { columnNames . provider } > { image . provider } </ Td >
201
+ < Td dataLabel = { columnNames . region } > { image . region } </ Td >
202
+ < Td dataLabel = { columnNames . arch } > { image . arch } </ Td >
203
+ < Td dataLabel = { columnNames . date } > < p > { new Date ( image . date ) . toDateString ( ) } </ p > </ Td >
204
+ < Td >
205
+ < Button
206
+ aria-expanded = { isDrawerExpanded }
207
+ onClick = { e => onDrawerOpenClick ( image ) }
208
+ variant = 'link'
209
+ isInline >
210
+ Launch now
211
+ </ Button >
212
+ </ Td >
213
+ </ Tr >
214
+ ) ) }
215
+ </ Tbody >
216
+ </ Table >
217
+ </ DrawerContentBody >
218
+ </ DrawerContent >
219
+ </ Drawer >
220
+
162
221
< Toolbar id = "toolbar-bottom" >
163
222
< ToolbarContent >
164
223
< ToolbarItem alignment = { {
0 commit comments