chore: Add title to IconButtonWithMenu and group by functionality
This commit is contained in:
parent
587cc3989f
commit
bd0a7009a3
2 changed files with 32 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
import { Chip, Menu, MenuItem } from '@mui/joy'
|
import { Chip, Menu, MenuItem, Typography } from '@mui/joy'
|
||||||
import IconButton from '@mui/joy/IconButton'
|
import IconButton from '@mui/joy/IconButton'
|
||||||
import React, { useEffect, useRef, useState } from 'react'
|
import React, { useEffect, useRef, useState } from 'react'
|
||||||
import { getTextColorFromBackgroundColor } from '../../utils/LabelColors'
|
import { getTextColorFromBackgroundColor } from '../../utils/LabelColors'
|
||||||
|
@ -12,6 +12,7 @@ const IconButtonWithMenu = ({
|
||||||
setSelectedItem,
|
setSelectedItem,
|
||||||
isActive,
|
isActive,
|
||||||
useChips,
|
useChips,
|
||||||
|
title,
|
||||||
}) => {
|
}) => {
|
||||||
const [anchorEl, setAnchorEl] = useState(null)
|
const [anchorEl, setAnchorEl] = useState(null)
|
||||||
const menuRef = useRef(null)
|
const menuRef = useRef(null)
|
||||||
|
@ -58,6 +59,13 @@ const IconButtonWithMenu = ({
|
||||||
open={Boolean(anchorEl)}
|
open={Boolean(anchorEl)}
|
||||||
onClose={handleMenuClose}
|
onClose={handleMenuClose}
|
||||||
>
|
>
|
||||||
|
{title && (
|
||||||
|
<MenuItem key={`${key}-title`} disabled>
|
||||||
|
<Typography level='body-sm' sx={{ fontWeight: 'bold' }}>
|
||||||
|
{title}
|
||||||
|
</Typography>
|
||||||
|
</MenuItem>
|
||||||
|
)}
|
||||||
{options?.map(item => (
|
{options?.map(item => (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
key={`${key}-${item?.id}`}
|
key={`${key}-${item?.id}`}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import {
|
||||||
ExpandCircleDown,
|
ExpandCircleDown,
|
||||||
FilterAlt,
|
FilterAlt,
|
||||||
PriorityHigh,
|
PriorityHigh,
|
||||||
|
Sort,
|
||||||
Style,
|
Style,
|
||||||
Unarchive,
|
Unarchive,
|
||||||
} from '@mui/icons-material'
|
} from '@mui/icons-material'
|
||||||
|
@ -50,6 +51,7 @@ const MyChores = () => {
|
||||||
const [filteredChores, setFilteredChores] = useState([])
|
const [filteredChores, setFilteredChores] = useState([])
|
||||||
const [selectedFilter, setSelectedFilter] = useState('All')
|
const [selectedFilter, setSelectedFilter] = useState('All')
|
||||||
const [choreSections, setChoreSections] = useState([])
|
const [choreSections, setChoreSections] = useState([])
|
||||||
|
const [selectedChoreSection, setSelectedChoreSection] = useState('due_date')
|
||||||
const [openChoreSections, setOpenChoreSections] = useState({})
|
const [openChoreSections, setOpenChoreSections] = useState({})
|
||||||
const [searchTerm, setSearchTerm] = useState('')
|
const [searchTerm, setSearchTerm] = useState('')
|
||||||
const [activeUserId, setActiveUserId] = useState(0)
|
const [activeUserId, setActiveUserId] = useState(0)
|
||||||
|
@ -436,6 +438,7 @@ const MyChores = () => {
|
||||||
/>
|
/>
|
||||||
<IconButtonWithMenu
|
<IconButtonWithMenu
|
||||||
icon={<PriorityHigh />}
|
icon={<PriorityHigh />}
|
||||||
|
title='Filter by Priority'
|
||||||
options={Priorities}
|
options={Priorities}
|
||||||
selectedItem={selectedFilter}
|
selectedItem={selectedFilter}
|
||||||
onItemSelect={selected => {
|
onItemSelect={selected => {
|
||||||
|
@ -449,6 +452,7 @@ const MyChores = () => {
|
||||||
// TODO : this need simplification we want to display both user labels and chore labels
|
// TODO : this need simplification we want to display both user labels and chore labels
|
||||||
// that why we are merging them here.
|
// that why we are merging them here.
|
||||||
// we also filter out the labels that user created as those will be part of user labels
|
// we also filter out the labels that user created as those will be part of user labels
|
||||||
|
title='Filter by Label'
|
||||||
options={[
|
options={[
|
||||||
...userLabels,
|
...userLabels,
|
||||||
...chores
|
...chores
|
||||||
|
@ -537,6 +541,25 @@ const MyChores = () => {
|
||||||
))}
|
))}
|
||||||
</Menu>
|
</Menu>
|
||||||
</List>
|
</List>
|
||||||
|
<Divider orientation='vertical' />
|
||||||
|
<IconButtonWithMenu
|
||||||
|
title='Group by'
|
||||||
|
icon={<Sort />}
|
||||||
|
options={[
|
||||||
|
{ name: 'Due Date', value: 'due_date' },
|
||||||
|
{ name: 'Priority', value: 'priority' },
|
||||||
|
{ name: 'Labels', value: 'labels' },
|
||||||
|
]}
|
||||||
|
selectedItem={selectedChoreSection}
|
||||||
|
onItemSelect={selected => {
|
||||||
|
const section = sectionSorter(selected.value, chores)
|
||||||
|
setChoreSections(section)
|
||||||
|
setSelectedChoreSection(selected.value)
|
||||||
|
setFilteredChores(chores)
|
||||||
|
setSelectedFilter('All')
|
||||||
|
}}
|
||||||
|
mouseClickHandler={handleMenuOutsideClick}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
{selectedFilter !== 'All' && (
|
{selectedFilter !== 'All' && (
|
||||||
<Chip
|
<Chip
|
||||||
|
|
Loading…
Add table
Reference in a new issue