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

feat(catalog): restructure share action and add delete action #855

Merged
merged 4 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 29 additions & 10 deletions src/custom/CatalogDetail/ActionButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { CircularProgress } from '../../base';
import { CopyIcon, EditIcon, KanvasIcon, PublishIcon } from '../../icons';
import { CopyIcon, EditIcon, KanvasIcon, PublishIcon, ShareLineIcon } from '../../icons';
import Download from '../../icons/Download/Download';
import { charcoal, useTheme } from '../../theme';
import { Pattern } from '../CustomCatalog/CustomCard';
Expand All @@ -21,6 +21,8 @@ interface ActionButtonsProps {
onOpenPlaygroundClick: (designId: string, name: string) => void;
showInfoAction?: boolean;
handleInfoClick?: () => void;
showShareAction?: boolean;
handleShare: () => void;
}

const ActionButtons: React.FC<ActionButtonsProps> = ({
Expand All @@ -35,7 +37,9 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
showOpenPlaygroundAction,
onOpenPlaygroundClick,
showInfoAction,
handleInfoClick
handleInfoClick,
showShareAction,
handleShare
}) => {
const cleanedType = type.replace('my-', '').replace(/s$/, '');
const theme = useTheme();
Expand Down Expand Up @@ -132,23 +136,38 @@ const ActionButtons: React.FC<ActionButtonsProps> = ({
}}
onClick={handleInfoClick}
>
<EditIcon width={24} height={24} fill={charcoal[10]} />
<EditIcon width={24} height={24} fill={theme.palette.icon.default} />
Edit
</ActionButton>
)}
{showUnpublishAction && (
<UnpublishAction
{showShareAction && (
<ActionButton
sx={{
borderRadius: '0.2rem',
gap: '10px'
backgroundColor: 'transparent',
border: `1px solid ${theme.palette.border.normal}`,
gap: '10px',
color: charcoal[10]
}}
onClick={handleUnpublish}
onClick={handleShare}
>
<PublishIcon width={24} height={24} fill={charcoal[100]} />
Unpublish
</UnpublishAction>
<ShareLineIcon width="24" height="24" fill={theme.palette.icon.default} />
Share
</ActionButton>
)}
</div>
{showUnpublishAction && (
<UnpublishAction
sx={{
borderRadius: '0.2rem',
gap: '10px'
}}
onClick={handleUnpublish}
>
<PublishIcon width={24} height={24} fill={charcoal[100]} />
Unpublish
</UnpublishAction>
)}
</StyledActionWrapper>
);
};
Expand Down
8 changes: 7 additions & 1 deletion src/custom/CatalogDetail/LeftPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ interface LeftPanelProps {
onOpenPlaygroundClick: (designId: string, name: string) => void;
showInfoAction?: boolean;
handleInfoClick?: () => void;
showShareAction?: boolean;
handleShare: () => void;
}

const LeftPanel: React.FC<LeftPanelProps> = ({
Expand All @@ -44,7 +46,9 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
showOpenPlaygroundAction = true,
onOpenPlaygroundClick,
showInfoAction = false,
handleInfoClick
handleInfoClick,
showShareAction = false,
handleShare
}) => {
const theme = useTheme();

Expand Down Expand Up @@ -89,6 +93,8 @@ const LeftPanel: React.FC<LeftPanelProps> = ({
onOpenPlaygroundClick={onOpenPlaygroundClick}
showInfoAction={showInfoAction}
handleInfoClick={handleInfoClick}
showShareAction={showShareAction}
handleShare={handleShare}
/>
{showTechnologies && (
<TechnologySection
Expand Down
64 changes: 24 additions & 40 deletions src/custom/CatalogDetail/SocialSharePopper.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { Lock, Public } from '@mui/icons-material';
import { Box, IconButton, Menu, MenuItem } from '@mui/material';
import React, { useState } from 'react';
import { FacebookShareButton, LinkedinShareButton, TwitterShareButton } from 'react-share';
import { Typography } from '../../base';
import { ChainIcon, FacebookIcon, LinkedinIcon, ShareIcon, TwitterIcon } from '../../icons';

import {
ChainIcon,
FacebookIcon,
LinkedinIcon,
LockIcon,
PublicIcon,
ShareIcon,
TwitterIcon
} from '../../icons';
import { useTheme } from '../../theme';
import { Pattern } from '../CustomCatalog/CustomCard';
import { CustomTooltip } from '../CustomTooltip';
import { ErrorBoundary } from '../ErrorBoundary';

import { VisibilityChipMenu } from '../VisibilityChipMenu';
import { VIEW_VISIBILITY } from '../VisibilityChipMenu/VisibilityChipMenu';
import { CopyShareIconWrapper, ShareButton, ShareButtonGroup, ShareSideButton } from './style';
import { CopyShareIconWrapper } from './style';

interface SocialSharePopperProps {
details: Pattern;
Expand All @@ -29,9 +37,7 @@ const SocialSharePopper: React.FC<SocialSharePopperProps> = ({
cardId,
title,
getUrl,
handleCopyUrl,
showShareAction,
handleShare
handleCopyUrl
}) => {
const theme = useTheme();
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
Expand All @@ -55,41 +61,19 @@ const SocialSharePopper: React.FC<SocialSharePopperProps> = ({
onChange={() => {}}
enabled={false}
options={[
[VIEW_VISIBILITY.PUBLIC, Public],
[VIEW_VISIBILITY.PRIVATE, Lock]
[VIEW_VISIBILITY.PUBLIC, PublicIcon],
[VIEW_VISIBILITY.PRIVATE, LockIcon]
]}
/>
{showShareAction ? (
<ShareButtonGroup variant="contained">
<CustomTooltip title="Change access and visibility">
<ShareButton variant="contained" onClick={handleShare}>
<Typography>Share</Typography>
</ShareButton>
</CustomTooltip>
<CustomTooltip title="Copy link to design">
<ShareSideButton
variant="contained"
size="small"
onClick={() => handleCopyUrl(cleanedType, details?.name, details?.id)}
>
<ChainIcon height={'24'} width={'24'} fill={theme.palette.icon.inverse} />
</ShareSideButton>
</CustomTooltip>
</ShareButtonGroup>
) : (
<>
{details?.visibility !== 'private' && (
<CustomTooltip title="Copy Link" placement="top" arrow>
<IconButton
sx={{ borderRadius: '0.1rem', padding: '0.5rem' }}
onClick={() => handleCopyUrl(cleanedType, details?.name, details?.id)}
>
<ChainIcon height={'24'} width={'24'} fill={theme.palette.icon.secondary} />
</IconButton>
</CustomTooltip>
)}
</>
)}

<CustomTooltip title="Copy Link" placement="top" arrow>
<IconButton
sx={{ borderRadius: '0.1rem', padding: '0.5rem' }}
onClick={() => handleCopyUrl(cleanedType, details?.name, details?.id)}
>
<ChainIcon height={'24'} width={'24'} fill={theme.palette.icon.secondary} />
</IconButton>
</CustomTooltip>

{(details?.visibility === 'published' || details?.visibility === 'public') && (
<>
Expand Down
128 changes: 71 additions & 57 deletions src/custom/ShareModal/ShareModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { ChainIcon, DeleteIcon, LockIcon, PublicIcon } from '../../icons';
import { useTheme } from '../../theme';
import { BLACK, WHITE } from '../../theme/colors';
import { CustomTooltip } from '../CustomTooltip';
import { Modal, ModalBody, ModalButtonPrimary, ModalButtonSecondary, ModalFooter } from '../Modal';
import UserShareSearch from '../UserSearchField/UserSearchField';
import {
Expand Down Expand Up @@ -97,13 +98,15 @@ const AccessList: React.FC<AccessListProps> = ({
{ownerData.id === actorData.id ? (
<div>Owner</div>
) : (
<IconButton
edge="end"
aria-label="delete"
onClick={() => handleDelete(actorData.email)}
>
<DeleteIcon fill={theme.palette.background.neutral?.default} />
</IconButton>
<CustomTooltip title="Remove Access" placement="top" arrow>
<IconButton
edge="end"
aria-label="delete"
onClick={() => handleDelete(actorData.email)}
>
<DeleteIcon fill={theme.palette.background.neutral?.default} />
</IconButton>
</CustomTooltip>
)}
</ListItemSecondaryAction>
</ListItem>
Expand Down Expand Up @@ -185,6 +188,9 @@ const ShareModal: React.FC<ShareModalProps> = ({
const handleMenuClose = () => setMenu(false);

const isShareDisabled = () => {
// Ensure at least one user other than the owner is selected
const otherUsersSelected = shareUserData.some((user) => user.id !== ownerData.id);

const existingAccessIds = shareUserData.map((user) => user.id);
const ownerDataId = ownerData?.id;

Expand All @@ -195,10 +201,10 @@ const ShareModal: React.FC<ShareModalProps> = ({
const hasMismatchedUsers = !shareUserData.every((user) => existingAccessIds.includes(user.id));

return (
shareUserData.length === existingAccessIds.length &&
!hasMismatchedUsers &&
(selectedOption === selectedResource?.visibility ||
shareUserData.length !== existingAccessIds.length)
!otherUsersSelected || // Disable if no other users are selected
(shareUserData.length === existingAccessIds.length &&
!hasMismatchedUsers &&
selectedOption === selectedResource?.visibility)
);
};

Expand Down Expand Up @@ -238,52 +244,60 @@ const ShareModal: React.FC<ShareModalProps> = ({
}
fetchSuggestions={fetchSuggestions}
/>
<CustomListItemText>
<Typography variant="h6">General Access</Typography>
</CustomListItemText>
<CustomDialogContentText>
<FormControlWrapper size="small">
<div style={{ display: 'flex', justifyContent: 'start', alignItems: 'center' }}>
<VisibilityIconWrapper>
{selectedOption === SHARE_MODE.PUBLIC ? (
<PublicIcon
width={24}
height={24}
stroke={theme.palette.mode === 'dark' ? WHITE : BLACK}
/>
) : (
<LockIcon
width={24}
height={24}
stroke={theme.palette.mode === 'dark' ? WHITE : BLACK}
/>
)}
</VisibilityIconWrapper>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<CustomSelect
variant="outlined"
defaultValue={selectedOption}
labelId="share-menu-select"
id="share-menu"
open={openMenu}
onClose={handleMenuClose}
onOpen={() => setMenu(true)}
onChange={handleOptionClick}
disabled={isVisibilitySelectorDisabled}
>
{Object.values(SHARE_MODE).map((option) => (
<MenuItem key={option} selected={option === selectedOption} value={option}>
{option.charAt(0).toUpperCase() + option.slice(1)}
</MenuItem>
))}
</CustomSelect>
<Typography component="span" variant="body2">
{selectedOption === SHARE_MODE.PRIVATE ? options.PRIVATE : options.PUBLIC}
</Typography>
</div>
</div>
</FormControlWrapper>
</CustomDialogContentText>
{selectedResource?.visibility !== 'published' && (
<>
<CustomListItemText>
<Typography variant="h6">General Access</Typography>
</CustomListItemText>
<CustomDialogContentText>
<FormControlWrapper size="small">
<div style={{ display: 'flex', justifyContent: 'start', alignItems: 'center' }}>
<VisibilityIconWrapper>
{selectedOption === SHARE_MODE.PUBLIC ? (
<PublicIcon
width={24}
height={24}
stroke={theme.palette.mode === 'dark' ? WHITE : BLACK}
/>
) : (
<LockIcon
width={24}
height={24}
stroke={theme.palette.mode === 'dark' ? WHITE : BLACK}
/>
)}
</VisibilityIconWrapper>
<div style={{ display: 'flex', flexDirection: 'column' }}>
<CustomSelect
variant="outlined"
defaultValue={selectedOption}
labelId="share-menu-select"
id="share-menu"
open={openMenu}
onClose={handleMenuClose}
onOpen={() => setMenu(true)}
onChange={handleOptionClick}
disabled={isVisibilitySelectorDisabled}
>
{Object.values(SHARE_MODE).map((option) => (
<MenuItem
key={option}
selected={option === selectedOption}
value={option}
>
{option.charAt(0).toUpperCase() + option.slice(1)}
</MenuItem>
))}
</CustomSelect>
<Typography component="span" variant="body2">
{selectedOption === SHARE_MODE.PRIVATE ? options.PRIVATE : options.PUBLIC}
</Typography>
</div>
</div>
</FormControlWrapper>
</CustomDialogContentText>
</>
)}
</ModalBody>

<ModalFooter
Expand Down
Loading