Skip to content

Commit

Permalink
adding dropwdown menu
Browse files Browse the repository at this point in the history
  • Loading branch information
jue-henry committed Nov 7, 2024
1 parent e667c90 commit 1868c61
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 61 deletions.
70 changes: 9 additions & 61 deletions src/features/filters/FiltersPanelFooter.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
import React from 'react';
import { styled, keyframes } from '../../theme/stitches.config.js';
import { selectUserCurrentRoles } from '../auth/authSlice.js';
import {
hasRole,
READ_STATS_ROLES,
DELETE_IMAGES_ROLES,
EXPORT_DATA_ROLES,
} from '../auth/roles.js';
import { hasRole, READ_STATS_ROLES } from '../auth/roles.js';
import { useDispatch, useSelector } from 'react-redux';
import {
selectImagesCount,
selectImagesCountLoading,
setDeleteImagesAlertOpen,
} from '../images/imagesSlice.js';
import { selectImagesCount, selectImagesCountLoading } from '../images/imagesSlice.js';
import {
selectModalOpen,
selectSelectedProject,
Expand All @@ -21,14 +12,15 @@ import {
fetchProjects,
} from '../projects/projectsSlice.js';
import { toggleOpenLoupe } from '../loupe/loupeSlice.js';
import { InfoCircledIcon, DownloadIcon, SymbolIcon, TrashIcon } from '@radix-ui/react-icons';
import { InfoCircledIcon, SymbolIcon } from '@radix-ui/react-icons';
import IconButton from '../../components/IconButton.jsx';
import {
Tooltip,
TooltipContent,
TooltipArrow,
TooltipTrigger,
} from '../../components/Tooltip.jsx';
import FiltersPanelFooterDropdown from './FiltersPanelFooterDropdown.jsx';

const RefreshButton = styled('div', {
height: '100%',
Expand All @@ -46,15 +38,7 @@ const InfoButton = styled('div', {
padding: '0 $1',
});

const ExportCSVButton = styled('div', {
height: '100%',
borderLeft: '1px solid $border',
display: 'flex',
alignItems: 'center',
padding: '0 $1',
});

const DeleteImagesButton = styled('div', {
const DropDownButton = styled('div', {
height: '100%',
borderLeft: '1px solid $border',
display: 'flex',
Expand Down Expand Up @@ -118,6 +102,7 @@ const FiltersPanelFooter = () => {
};

const handleModalToggle = (content) => {
console.log(content);
dispatch(setModalOpen(!modalOpen));
dispatch(setModalContent(content));
};
Expand Down Expand Up @@ -152,46 +137,6 @@ const FiltersPanelFooter = () => {
</TooltipContent>
</Tooltip>
)}
{hasRole(userRoles, EXPORT_DATA_ROLES) && (
<Tooltip>
<TooltipTrigger asChild>
<ExportCSVButton>
<IconButton
variant="ghost"
size="large"
onClick={() => handleModalToggle('export-modal')}
>
<DownloadIcon />
</IconButton>
</ExportCSVButton>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={5}>
Export data
<TooltipArrow />
</TooltipContent>
</Tooltip>
)}
{hasRole(userRoles, DELETE_IMAGES_ROLES) && (
<Tooltip>
<TooltipTrigger asChild>
<DeleteImagesButton>
<IconButton
variant="ghost"
size="large"
onClick={() => {
dispatch(setDeleteImagesAlertOpen(true));
}}
>
<TrashIcon />
</IconButton>
</DeleteImagesButton>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={5}>
Delete all filtered images
<TooltipArrow />
</TooltipContent>
</Tooltip>
)}
<Tooltip>
<TooltipTrigger asChild>
<RefreshButton>
Expand All @@ -205,6 +150,9 @@ const FiltersPanelFooter = () => {
<TooltipArrow />
</TooltipContent>
</Tooltip>
<DropDownButton>
<FiltersPanelFooterDropdown handleModalToggle={handleModalToggle} />
</DropDownButton>
</StyledFiltersPanelFooter>
);
};
Expand Down
57 changes: 57 additions & 0 deletions src/features/filters/FiltersPanelFooterDropdown.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { styled } from '../../theme/stitches.config';
import {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuArrow,
} from '../../components/Dropdown.jsx';
import { selectUserCurrentRoles } from '../auth/authSlice.js';
import { hasRole, DELETE_IMAGES_ROLES, EXPORT_DATA_ROLES } from '../auth/roles.js';
import { DotsHorizontalIcon } from '@radix-ui/react-icons';
import { setDeleteImagesAlertOpen } from '../images/imagesSlice';

const StyledDropdownMenuTrigger = styled(DropdownMenuTrigger, {
height: '100%',
width: '40px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
border: 'none',
backgroundColor: 'transparent',
padding: '0',
});

const FiltersPanelFooterDropdown = (props) => {
const dispatch = useDispatch();
const userRoles = useSelector(selectUserCurrentRoles);

const handleDeleteImageItemClick = () => {
dispatch(setDeleteImagesAlertOpen(true));
};

return (
<DropdownMenu>
<StyledDropdownMenuTrigger size="large">
<DotsHorizontalIcon />
</StyledDropdownMenuTrigger>
<DropdownMenuContent sideOffset={5}>
{hasRole(userRoles, EXPORT_DATA_ROLES) && (
<DropdownMenuItem onClick={() => props.handleModalToggle('export-modal')}>
Export data
</DropdownMenuItem>
)}
{hasRole(userRoles, DELETE_IMAGES_ROLES) && (
<DropdownMenuItem onClick={handleDeleteImageItemClick}>
Delete Filtered Images
</DropdownMenuItem>
)}
<DropdownMenuArrow offset={12} />
</DropdownMenuContent>
</DropdownMenu>
);
};

export default FiltersPanelFooterDropdown;

0 comments on commit 1868c61

Please sign in to comment.