@@ -27,11 +27,13 @@ import { TextContent } from '@patternfly/react-core/dist/esm/components/Text/Tex
27
27
import OutlinedQuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/outlined-question-circle-icon' ;
28
28
import { Popover } from '@patternfly/react-core/dist/esm/components/Popover' ;
29
29
import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon' ;
30
+ import { Gallery } from '@patternfly/react-core' ;
30
31
31
32
const Index : React . FunctionComponent = ( ) => {
32
33
const { data : session } = useSession ( ) ;
33
34
const [ pullRequests , setPullRequests ] = React . useState < PullRequest [ ] > ( [ ] ) ;
34
35
const [ error , setError ] = React . useState < string | null > ( null ) ;
36
+ const [ isGridView , setIsGridView ] = React . useState ( false ) ;
35
37
const router = useRouter ( ) ;
36
38
37
39
const fetchAndSetPullRequests = React . useCallback ( async ( ) => {
@@ -74,6 +76,14 @@ const Index: React.FunctionComponent = () => {
74
76
}
75
77
} ;
76
78
79
+ const handleListViewClick = ( ) => {
80
+ setIsGridView ( false ) ; // Set view to list
81
+ } ;
82
+
83
+ const handleGridViewClick = ( ) => {
84
+ setIsGridView ( true ) ; // Set view to grid
85
+ } ;
86
+
77
87
if ( ! session ) {
78
88
return < div > Loading...</ div > ;
79
89
}
@@ -108,7 +118,17 @@ const Index: React.FunctionComponent = () => {
108
118
</ TextContent >
109
119
</ PageSection >
110
120
< PageSection >
111
- < div style = { { marginBottom : '20px' } } />
121
+ { /* Only show toggle buttons if there are pull requests */ }
122
+ { pullRequests . length > 0 && (
123
+ < div style = { { marginBottom : '20px' } } >
124
+ < Button variant = { isGridView ? 'secondary' : 'primary' } onClick = { handleListViewClick } style = { { marginRight : '10px' } } >
125
+ List View
126
+ </ Button >
127
+ < Button variant = { isGridView ? 'primary' : 'secondary' } onClick = { handleGridViewClick } >
128
+ Grid View
129
+ </ Button >
130
+ </ div >
131
+ ) }
112
132
{ error && < div > { error } </ div > }
113
133
{ pullRequests . length === 0 ? (
114
134
< EmptyState >
@@ -154,6 +174,40 @@ const Index: React.FunctionComponent = () => {
154
174
</ EmptyStateActions >
155
175
</ EmptyStateFooter >
156
176
</ EmptyState >
177
+ ) : isGridView ? (
178
+ < Gallery hasGutter >
179
+ { pullRequests . map ( ( pr ) => (
180
+ < Card key = { pr . number } >
181
+ < CardTitle > { pr . title } </ CardTitle >
182
+ < CardBody >
183
+ < Flex justifyContent = { { default : 'justifyContentSpaceBetween' } } >
184
+ < FlexItem > State: { pr . state } </ FlexItem >
185
+ < FlexItem > Created At: { new Date ( pr . created_at ) . toLocaleString ( ) } </ FlexItem >
186
+ < FlexItem > Updated At: { new Date ( pr . updated_at ) . toLocaleString ( ) } </ FlexItem >
187
+ < FlexItem >
188
+ { pr . labels . map ( ( label ) => (
189
+ < Label key = { label . name } color = "blue" style = { { marginRight : '5px' } } >
190
+ { label . name }
191
+ </ Label >
192
+ ) ) }
193
+ </ FlexItem >
194
+ < FlexItem alignSelf = { { default : 'alignSelfFlexEnd' } } flex = { { default : 'flexNone' } } >
195
+ < Button variant = "secondary" component = "a" href = { pr . html_url } target = "_blank" rel = "noopener noreferrer" >
196
+ View PR
197
+ </ Button >
198
+ </ FlexItem >
199
+ < FlexItem alignSelf = { { default : 'alignSelfFlexEnd' } } flex = { { default : 'flexNone' } } >
200
+ { pr . state === 'open' && (
201
+ < Button variant = "primary" onClick = { ( ) => handleEditClick ( pr ) } >
202
+ Edit
203
+ </ Button >
204
+ ) }
205
+ </ FlexItem >
206
+ </ Flex >
207
+ </ CardBody >
208
+ </ Card >
209
+ ) ) }
210
+ </ Gallery >
157
211
) : (
158
212
< Stack hasGutter >
159
213
{ pullRequests . map ( ( pr ) => (
0 commit comments