Skip to content

Commit 50ef229

Browse files
F-X64major
authored andcommitted
Add image details drawer
Add new DetailsDrawer component Add drawer layout to ImageTable
1 parent ab9586f commit 50ef229

File tree

2 files changed

+120
-29
lines changed

2 files changed

+120
-29
lines changed

src/app/components/DetailsDrawer.tsx

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import React from 'react';
2+
import {
3+
DrawerPanelContent,
4+
DrawerHead,
5+
DrawerActions,
6+
DrawerCloseButton,
7+
} from '@patternfly/react-core';
8+
import { MouseEventHandler } from 'react';
9+
import DetailsView from './DetailsView';
10+
11+
export const DetailsDrawer: React.FunctionComponent<{
12+
onCloseClick: MouseEventHandler,
13+
isExpanded: Boolean,
14+
drawerRef: any,
15+
details: object,
16+
}> = ({ onCloseClick, isExpanded, drawerRef, details }) => {
17+
return (
18+
<React.Fragment>
19+
<DrawerPanelContent>
20+
<DrawerHead>
21+
<span tabIndex={isExpanded ? 0 : -1} ref={drawerRef}>
22+
<DetailsView details={details} />
23+
</span>
24+
<DrawerActions>
25+
<DrawerCloseButton onClick={onCloseClick} />
26+
</DrawerActions>
27+
</DrawerHead>
28+
</DrawerPanelContent>
29+
</React.Fragment>
30+
);
31+
};
32+

src/app/components/ImageTable.tsx

+88-29
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
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';
318
import { Table, Thead, Tr, Th, ThProps, Tbody, Td } from '@patternfly/react-table';
419
import { fetch } from 'cross-fetch'
5-
20+
import { DetailsDrawer } from './DetailsDrawer';
21+
import { MouseEventHandler } from 'react';
622
interface ImageData {
723
name: string;
824
version: string;
@@ -22,6 +38,23 @@ export const ImageTable: React.FunctionComponent = () => {
2238
const [activeSortDirection, setActiveSortDirection] = React.useState<'asc' | 'desc' | undefined>(undefined);
2339
const [page, setPage] = React.useState(1);
2440
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+
2558
const columnNames = {
2659
name: 'Name',
2760
provider: 'Provider',
@@ -105,6 +138,15 @@ export const ImageTable: React.FunctionComponent = () => {
105138
}
106139
});
107140
}
141+
142+
const panelContent = (
143+
<DetailsDrawer
144+
onCloseClick={onDrawerCloseClick}
145+
drawerRef={drawerRef}
146+
isExpanded={isDrawerExpanded}
147+
details={selectedImage} />
148+
);
149+
108150
return (
109151
<React.Fragment>
110152
<Title headingLevel='h1'>Browse Images</Title>
@@ -132,33 +174,50 @@ export const ImageTable: React.FunctionComponent = () => {
132174
</ToolbarItem>
133175
</ToolbarContent>
134176
</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+
162221
<Toolbar id="toolbar-bottom">
163222
<ToolbarContent>
164223
<ToolbarItem alignment={{

0 commit comments

Comments
 (0)