Skip to content
This repository has been archived by the owner on Dec 27, 2024. It is now read-only.

Commit

Permalink
Refactor announcements infoCard (#89)
Browse files Browse the repository at this point in the history
* refactor: replace card by generic infocard

Signed-off-by: Gaël G <[email protected]>

* refactor: move action buttons to a edit menu

Signed-off-by: Gaël G <[email protected]>

* Update screenshot

Signed-off-by: Gaël G <[email protected]>

---------

Signed-off-by: Gaël G <[email protected]>
  • Loading branch information
gaelgoth authored Nov 16, 2023
1 parent 88b197c commit 95c94c0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/warm-pigs-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@procore-oss/backstage-plugin-announcements': minor
---

Update announcement card layout. That fixes color font that was incorrect with light theme
Binary file modified docs/images/announcements_page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
Link,
ItemCardGrid,
Progress,
ItemCardHeader,
ContentHeader,
LinkButton,
} from '@backstage/core-components';
Expand All @@ -28,12 +27,15 @@ import {
import Alert from '@material-ui/lab/Alert';
import DeleteIcon from '@material-ui/icons/Delete';
import EditIcon from '@material-ui/icons/Edit';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import {
Button,
Card,
CardActions,
CardContent,
CardMedia,
CardHeader,
IconButton,
ListItemIcon,
Menu,
MenuItem,
makeStyles,
} from '@material-ui/core';
import {
Expand All @@ -51,6 +53,7 @@ import { ContextMenu } from './ContextMenu';
const useStyles = makeStyles(theme => ({
cardHeader: {
color: theme.palette.text.primary,
fontSize: '1.5rem',
},
pagination: {
display: 'flex',
Expand Down Expand Up @@ -106,27 +109,64 @@ const AnnouncementCard = ({
const { loading: loadingUpdatePermission, allowed: canUpdate } =
usePermission({ permission: announcementUpdatePermission });

const AnnouncementEditMenu = () => {
const [open, setOpen] = React.useState(false);
const [anchorEl, setAnchorEl] = React.useState<undefined | HTMLElement>(
undefined,
);

const handleOpenEditMenu = (event: React.MouseEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
setOpen(true);
};

const handleCloseEditClose = () => {
setAnchorEl(undefined);
setOpen(false);
};
return (
<>
<IconButton
data-testid="announcement-edit-menu"
aria-label="more"
onClick={handleOpenEditMenu}
>
<MoreVertIcon />
</IconButton>
<Menu anchorEl={anchorEl} open={open} onClose={handleCloseEditClose}>
{!loadingUpdatePermission && canUpdate && (
<MenuItem
data-testid="edit-announcement"
component={LinkButton}
to={editAnnouncementLink({ id: announcement.id })}
>
<ListItemIcon>
<EditIcon />
</ListItemIcon>
EDIT
</MenuItem>
)}
{!loadingDeletePermission && canDelete && (
<MenuItem onClick={onDelete}>
<ListItemIcon>
<DeleteIcon />
</ListItemIcon>
DELETE
</MenuItem>
)}
</Menu>
</>
);
};

return (
<Card>
<CardMedia>
<ItemCardHeader title={title} subtitle={subTitle} />
</CardMedia>
<CardHeader
action={<AnnouncementEditMenu />}
title={title}
subheader={subTitle}
/>
<CardContent>{announcement.excerpt}</CardContent>
<CardActions>
{!loadingUpdatePermission && canUpdate && (
<LinkButton
to={editAnnouncementLink({ id: announcement.id })}
color="default"
>
<EditIcon />
</LinkButton>
)}
{!loadingDeletePermission && canDelete && (
<Button onClick={onDelete} color="default">
<DeleteIcon />
</Button>
)}
</CardActions>
</Card>
);
};
Expand Down

0 comments on commit 95c94c0

Please sign in to comment.