Skip to content

Commit

Permalink
fix(groupModeAction): Make the full line clickable
Browse files Browse the repository at this point in the history
Before, only way to de-group was to click on the  switch. Now it's the line in the options menu that does the action (the switch is contained inside).

I've taken advantage of this to make the user return to the root when he chooses to ungroup a folder so that he doesn't stay on a route that doesn't display anything. This could lead to strange behaviour when they chose to group it again
  • Loading branch information
cballevre committed Nov 18, 2024
1 parent f181106 commit 4419c2e
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/components/Sections/actions/groupModeAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,19 @@ import {
computeGroupMode,
handleSectionAction
} from 'components/Sections/utils'

const StateSwitch = ({
handleClick,
checked
}: {
handleClick: () => void
checked: boolean
}): JSX.Element => {
return <Switch checked={checked} onChange={handleClick} color="primary" />
}
import { useNavigate } from 'react-router-dom'

export const groupModeAction = (): (() => Action) => () => ({
name: `sectionAction_group`,
Component: React.forwardRef<{ docs?: Section[] }>(
function SectionActionComponent(props: { docs?: Section[] }, ref) {
const navigate = useNavigate()
const { t } = useI18n()
const { isMobile } = useBreakpoints()
const { values, save } = useSettings('home', ['shortcutsLayout'])
const section = props.docs?.[0] as SectionViewProps['section']
const currentGroupMode = computeGroupMode(isMobile, section)
const handleClick = (): void =>
const handleClick = (): void => {
handleSectionAction(
section,
isMobile,
Expand All @@ -47,17 +39,20 @@ export const groupModeAction = (): (() => Action) => () => ({
values,
save
)
if (currentGroupMode === GroupMode.GROUPED) {
navigate('/connected')
}
}

return (
<ActionsMenuItem {...props} ref={ref}>
<ActionsMenuItem {...props} ref={ref} onClick={handleClick}>
<ListItemText
className="u-mr-half"
primary={t(`sections.label_grouped`)}
/>

<StateSwitch
handleClick={handleClick}
<Switch
checked={currentGroupMode === GroupMode.GROUPED}
color="primary"
/>
</ActionsMenuItem>
)
Expand Down

0 comments on commit 4419c2e

Please sign in to comment.