Skip to content

Commit 3e60bf7

Browse files
committed
Add a grid view toggle to the dashboard
Signed-off-by: Brent Salisbury <[email protected]>
1 parent 9435276 commit 3e60bf7

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

src/components/Dashboard/index.tsx

+55-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ import { TextContent } from '@patternfly/react-core/dist/esm/components/Text/Tex
2727
import OutlinedQuestionCircleIcon from '@patternfly/react-icons/dist/esm/icons/outlined-question-circle-icon';
2828
import { Popover } from '@patternfly/react-core/dist/esm/components/Popover';
2929
import ExternalLinkAltIcon from '@patternfly/react-icons/dist/esm/icons/external-link-alt-icon';
30+
import { Gallery } from '@patternfly/react-core';
3031

3132
const Index: React.FunctionComponent = () => {
3233
const { data: session } = useSession();
3334
const [pullRequests, setPullRequests] = React.useState<PullRequest[]>([]);
3435
const [error, setError] = React.useState<string | null>(null);
36+
const [isGridView, setIsGridView] = React.useState(false);
3537
const router = useRouter();
3638

3739
const fetchAndSetPullRequests = React.useCallback(async () => {
@@ -74,6 +76,14 @@ const Index: React.FunctionComponent = () => {
7476
}
7577
};
7678

79+
const handleListViewClick = () => {
80+
setIsGridView(false); // Set view to list
81+
};
82+
83+
const handleGridViewClick = () => {
84+
setIsGridView(true); // Set view to grid
85+
};
86+
7787
if (!session) {
7888
return <div>Loading...</div>;
7989
}
@@ -108,7 +118,17 @@ const Index: React.FunctionComponent = () => {
108118
</TextContent>
109119
</PageSection>
110120
<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+
)}
112132
{error && <div>{error}</div>}
113133
{pullRequests.length === 0 ? (
114134
<EmptyState>
@@ -154,6 +174,40 @@ const Index: React.FunctionComponent = () => {
154174
</EmptyStateActions>
155175
</EmptyStateFooter>
156176
</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>
157211
) : (
158212
<Stack hasGutter>
159213
{pullRequests.map((pr) => (

0 commit comments

Comments
 (0)