Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes conversation name overflow w/ scrollbar, pinned icon size, and adds bulk selection/actions #194

Merged
merged 2 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
265 changes: 174 additions & 91 deletions workbench-app/src/components/FrontDoor/Controls/ConversationItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Caption1,
Card,
CardHeader,
Checkbox,
makeStyles,
Menu,
MenuItem,
Expand Down Expand Up @@ -31,15 +32,35 @@ import { Utility } from '../../../libs/Utility';
import { Conversation } from '../../../models/Conversation';

const useClasses = makeStyles({
root: {},
cardHeader: {
overflow: 'hidden',

// Required to prevent overflow of the header and description
// to support ellipsis and text overflow handling
'& .fui-CardHeader__header': {
overflow: 'hidden',
},

'& .fui-CardHeader__description': {
overflow: 'hidden',
},
},
header: {
display: 'flex',
flexDirection: 'row',
flex: 1,
gap: tokens.spacingHorizontalS,
gap: tokens.spacingHorizontalXS,
alignItems: 'center',
justifyContent: 'space-between',
width: '260px',
width: '100%',
},
action: {
flex: '0 0 auto',
display: 'flex',
flexDirection: 'column',
},
pin: {
flex: '0 0 auto',
},
title: {
flexGrow: 1,
Expand All @@ -49,11 +70,9 @@ const useClasses = makeStyles({
minWidth: 0,
},
date: {
marginLeft: tokens.spacingHorizontalXS,
flexShrink: 0,
},
hidden: {
visibility: 'hidden',
},
unread: {
color: tokens.colorStrokeFocus2,
fontWeight: '600',
Expand All @@ -62,28 +81,62 @@ const useClasses = makeStyles({
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis',
maxWidth: '260px',
width: '100%',
},
showingActions: {
'& .fui-CardHeader__header': {
width: 'calc(100% - 40px)',
},

'& .fui-CardHeader__description': {
width: 'calc(100% - 40px)',
},
},
selectCheckbox: {
height: '24px',
},
moreButton: {
paddingTop: 0,
paddingBottom: 0,
},
});

interface ConversationItemProps {
conversation: Conversation;
owned?: boolean;
selected?: boolean;
showSelectForActions?: boolean;
selectedForActions?: boolean;
onSelect?: (conversation: Conversation) => void;
onExport?: (conversation: Conversation) => void;
onRename?: (conversation: Conversation) => void;
onDuplicate?: (conversation: Conversation) => void;
onShare?: (conversation: Conversation) => void;
onRemove?: (conversation: Conversation) => void;
onSelectForActions?: (conversation: Conversation, selected: boolean) => void;
}

export const ConversationItem: React.FC<ConversationItemProps> = (props) => {
const { conversation, owned, selected, onSelect, onExport, onRename, onDuplicate, onShare, onRemove } = props;
const {
conversation,
owned,
selected,
onSelect,
onExport,
onRename,
onDuplicate,
onShare,
onRemove,
showSelectForActions,
selectedForActions,
onSelectForActions,
} = props;
const classes = useClasses();
const [isHovered, setIsHovered] = React.useState(false);
const { hasUnreadMessages, isPinned, setPinned } = useConversationUtility();

const showActions = isHovered || showSelectForActions;

const action = React.useMemo(() => {
const handleMenuItemClick = (
event: React.MouseEvent<HTMLDivElement>,
Expand All @@ -99,70 +152,101 @@ export const ConversationItem: React.FC<ConversationItemProps> = (props) => {
};

return (
<Menu key={conversation.id} positioning="below-end">
<MenuTrigger disableButtonEnhancement>
<Tooltip content="More options" relationship="label">
<Button appearance="transparent" icon={<MoreHorizontalRegular />} />
</Tooltip>
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem
icon={isPinned(conversation) ? <PinOffRegular /> : <PinRegular />}
onClick={(event) => handleMenuItemClick(event, onPinned)}
>
{isPinned(conversation) ? 'Unpin' : 'Pin'}
</MenuItem>
{onRename && (
<div className={classes.action}>
<Checkbox
className={classes.selectCheckbox}
checked={selectedForActions}
onChange={() => onSelectForActions?.(conversation, !selectedForActions)}
/>
<Menu key={conversation.id} positioning="below-end">
<MenuTrigger disableButtonEnhancement>
<Button
appearance="transparent"
className={classes.moreButton}
icon={<MoreHorizontalRegular />}
/>
</MenuTrigger>
<MenuPopover>
<MenuList>
<MenuItem
icon={<EditRegular />}
onClick={(event) => handleMenuItemClick(event, onRename)}
disabled={!owned}
icon={isPinned(conversation) ? <PinOffRegular /> : <PinRegular />}
onClick={(event) => handleMenuItemClick(event, onPinned)}
>
Rename
{isPinned(conversation) ? 'Unpin' : 'Pin'}
</MenuItem>
)}
{onExport && (
<MenuItem
icon={<ArrowDownloadRegular />}
onClick={(event) => handleMenuItemClick(event, onExport)}
>
Export
</MenuItem>
)}
{onDuplicate && (
<MenuItem
icon={<SaveCopyRegular />}
onClick={(event) => handleMenuItemClick(event, onDuplicate)}
>
Duplicate
</MenuItem>
)}
{onShare && (
<MenuItem icon={<ShareRegular />} onClick={(event) => handleMenuItemClick(event, onShare)}>
Share
</MenuItem>
)}
{onRemove && (
<MenuItem
icon={<PlugDisconnectedRegular />}
onClick={(event) => handleMenuItemClick(event, onRemove)}
disabled={selected}
>
{selected ? (
<Tooltip content="Cannot remove currently active conversation" relationship="label">
<Text>Remove</Text>
</Tooltip>
) : (
'Remove'
)}
</MenuItem>
)}
</MenuList>
</MenuPopover>
</Menu>
{onRename && (
<MenuItem
icon={<EditRegular />}
onClick={(event) => handleMenuItemClick(event, onRename)}
disabled={!owned}
>
Rename
</MenuItem>
)}
{onExport && (
<MenuItem
icon={<ArrowDownloadRegular />}
onClick={(event) => handleMenuItemClick(event, onExport)}
>
Export
</MenuItem>
)}
{onDuplicate && (
<MenuItem
icon={<SaveCopyRegular />}
onClick={(event) => handleMenuItemClick(event, onDuplicate)}
>
Duplicate
</MenuItem>
)}
{onShare && (
<MenuItem
icon={<ShareRegular />}
onClick={(event) => handleMenuItemClick(event, onShare)}
>
Share
</MenuItem>
)}
{onRemove && (
<MenuItem
icon={<PlugDisconnectedRegular />}
onClick={(event) => handleMenuItemClick(event, onRemove)}
disabled={selected}
>
{selected ? (
<Tooltip
content="Cannot remove currently active conversation"
relationship="label"
>
<Text>Remove</Text>
</Tooltip>
) : (
'Remove'
)}
</MenuItem>
)}
</MenuList>
</MenuPopover>
</Menu>
</div>
);
}, [conversation, isPinned, onRename, owned, onExport, onDuplicate, onShare, onRemove, selected, setPinned]);
}, [
classes.action,
classes.selectCheckbox,
classes.moreButton,
selectedForActions,
conversation,
isPinned,
onRename,
owned,
onExport,
onDuplicate,
onShare,
onRemove,
selected,
setPinned,
onSelectForActions,
]);

const unread = hasUnreadMessages(conversation);

Expand All @@ -173,29 +257,29 @@ export const ConversationItem: React.FC<ConversationItemProps> = (props) => {

return (
<div className={classes.header}>
{isPinned(conversation) && <Pin12Regular />}
{isPinned(conversation) && (
<div className={classes.pin}>
<Pin12Regular />
</div>
)}
<Text className={classes.title} weight={unread ? 'bold' : 'regular'}>
{conversation.title}
</Text>
<Caption1
className={mergeClasses(
classes.date,
unread ? classes.unread : undefined,
isHovered ? classes.hidden : undefined,
)}
>
{formattedDate}
</Caption1>
{!showActions && (
<Caption1 className={mergeClasses(classes.date, unread ? classes.unread : undefined)}>
{formattedDate}
</Caption1>
)}
</div>
);
}, [
classes.date,
conversation,
classes.header,
classes.hidden,
classes.pin,
classes.title,
classes.date,
classes.unread,
conversation,
isHovered,
showActions,
isPinned,
unread,
]);
Expand All @@ -209,25 +293,24 @@ export const ConversationItem: React.FC<ConversationItemProps> = (props) => {
const sender = conversation.participants.find((p) => p.id === participantId);
const content = conversation.latest_message.content;

return (
<Caption1 className={mergeClasses(classes.description, unread ? classes.unread : undefined)}>
{sender ? `${sender.name}: ${content}` : content}
</Caption1>
);
}, [conversation.latest_message, conversation.participants, classes.description, classes.unread, unread]);
return <Caption1 className={classes.description}>{sender ? `${sender.name}: ${content}` : content}</Caption1>;
}, [conversation.latest_message, conversation.participants, classes.description]);

return (
<Card
className={classes.root}
size="small"
appearance="subtle"
selected={selected}
onSelectionChange={() => onSelect?.(conversation)}
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
floatingAction={isHovered ? action : undefined}
floatingAction={showActions ? action : undefined}
>
<CardHeader header={header} description={description} />
<CardHeader
className={mergeClasses(classes.cardHeader, showActions ? classes.showingActions : undefined)}
header={header}
description={description}
/>
</Card>
);
};
Loading