Enhance ObjectTableViewButton with View Mode Cycling and Typography Updates
- Refactored ObjectTableViewButton to include a cycling feature for view modes, allowing users to switch between list, cards, and kanban views seamlessly. - Updated the component to utilize Ant Design's Typography for improved text styling and consistency. - Removed icons from view mode options to streamline the interface and focused on text labels. - Adjusted button properties to enhance user interaction and accessibility.
This commit is contained in:
parent
ab7919122a
commit
0eae922a9e
@ -1,7 +1,16 @@
|
|||||||
import PropTypes from 'prop-types'
|
import PropTypes from 'prop-types'
|
||||||
import { useContext, useMemo, useState } from 'react'
|
import { useContext, useMemo, useState } from 'react'
|
||||||
import ObjectListViewContext from '../context/ObjectListViewContext'
|
import ObjectListViewContext from '../context/ObjectListViewContext'
|
||||||
import { Button, Divider, Flex, Modal, Popover, Radio, Select } from 'antd'
|
import {
|
||||||
|
Button,
|
||||||
|
Divider,
|
||||||
|
Flex,
|
||||||
|
Modal,
|
||||||
|
Popover,
|
||||||
|
Radio,
|
||||||
|
Select,
|
||||||
|
Typography
|
||||||
|
} from 'antd'
|
||||||
import GridIcon from '../../Icons/GridIcon'
|
import GridIcon from '../../Icons/GridIcon'
|
||||||
import ListIcon from '../../Icons/ListIcon'
|
import ListIcon from '../../Icons/ListIcon'
|
||||||
import KanbanIcon from '../../Icons/KanbanIcon'
|
import KanbanIcon from '../../Icons/KanbanIcon'
|
||||||
@ -10,11 +19,13 @@ import { getModelByName } from '../../../database/ObjectModels'
|
|||||||
import { getViewModeType, normalizeViewMode } from './viewModeUtils'
|
import { getViewModeType, normalizeViewMode } from './viewModeUtils'
|
||||||
|
|
||||||
const VIEW_MODE_OPTIONS = [
|
const VIEW_MODE_OPTIONS = [
|
||||||
{ type: 'list', label: 'List', icon: <ListIcon /> },
|
{ type: 'list', label: 'List' },
|
||||||
{ type: 'cards', label: 'Cards', icon: <GridIcon /> },
|
{ type: 'cards', label: 'Cards' },
|
||||||
{ type: 'kanban', label: 'Kanban', icon: <KanbanIcon /> }
|
{ type: 'kanban', label: 'Kanban' }
|
||||||
]
|
]
|
||||||
|
|
||||||
|
const { Text } = Typography
|
||||||
|
|
||||||
const ObjectTableViewButton = ({
|
const ObjectTableViewButton = ({
|
||||||
objectType,
|
objectType,
|
||||||
viewMode: viewModeProp,
|
viewMode: viewModeProp,
|
||||||
@ -38,6 +49,14 @@ const ObjectTableViewButton = ({
|
|||||||
const hasKanbanOption = stateProperties.length > 0
|
const hasKanbanOption = stateProperties.length > 0
|
||||||
const defaultCategoryProperty = stateProperties[0]?.name
|
const defaultCategoryProperty = stateProperties[0]?.name
|
||||||
|
|
||||||
|
const availableViewModes = useMemo(
|
||||||
|
() =>
|
||||||
|
VIEW_MODE_OPTIONS.filter(
|
||||||
|
(option) => option.type !== 'kanban' || hasKanbanOption
|
||||||
|
).map((option) => option.type),
|
||||||
|
[hasKanbanOption]
|
||||||
|
)
|
||||||
|
|
||||||
const handleTypeChange = (nextType) => {
|
const handleTypeChange = (nextType) => {
|
||||||
if (nextType === 'kanban') {
|
if (nextType === 'kanban') {
|
||||||
setViewMode({
|
setViewMode({
|
||||||
@ -63,6 +82,19 @@ const ObjectTableViewButton = ({
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { onClick: buttonOnClick, ...restButtonProps } = buttonProps
|
||||||
|
|
||||||
|
const handleCycleView = (event) => {
|
||||||
|
buttonOnClick?.(event)
|
||||||
|
|
||||||
|
const currentType = getViewModeType(normalizedViewMode)
|
||||||
|
const currentIndex = availableViewModes.indexOf(currentType)
|
||||||
|
const nextIndex =
|
||||||
|
currentIndex === -1 ? 0 : (currentIndex + 1) % availableViewModes.length
|
||||||
|
|
||||||
|
handleTypeChange(availableViewModes[nextIndex])
|
||||||
|
}
|
||||||
|
|
||||||
const activeIcon =
|
const activeIcon =
|
||||||
normalizedViewMode.type === 'cards' ? (
|
normalizedViewMode.type === 'cards' ? (
|
||||||
<GridIcon />
|
<GridIcon />
|
||||||
@ -86,14 +118,21 @@ const ObjectTableViewButton = ({
|
|||||||
(option) => option.type !== 'kanban' || hasKanbanOption
|
(option) => option.type !== 'kanban' || hasKanbanOption
|
||||||
).map((option) => (
|
).map((option) => (
|
||||||
<Radio key={option.type} value={option.type}>
|
<Radio key={option.type} value={option.type}>
|
||||||
<Flex gap='small' align='center'>
|
<Flex
|
||||||
{option.icon}
|
gap='4px'
|
||||||
{option.label}
|
align='center'
|
||||||
|
style={{ marginLeft: '4px' }}
|
||||||
|
>
|
||||||
|
<Text>{option.label}</Text>
|
||||||
{option.type === 'kanban' && (
|
{option.type === 'kanban' && (
|
||||||
<Button
|
<Button
|
||||||
type='text'
|
type='text'
|
||||||
size='small'
|
size='small'
|
||||||
icon={<SettingsIcon />}
|
icon={
|
||||||
|
<SettingsIcon
|
||||||
|
style={{ fontSize: '14px', marginTop: '2.5px' }}
|
||||||
|
/>
|
||||||
|
}
|
||||||
disabled={normalizedViewMode.type !== 'kanban'}
|
disabled={normalizedViewMode.type !== 'kanban'}
|
||||||
onClick={(event) => {
|
onClick={(event) => {
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
@ -111,8 +150,14 @@ const ObjectTableViewButton = ({
|
|||||||
}
|
}
|
||||||
placement='bottomLeft'
|
placement='bottomLeft'
|
||||||
arrow={false}
|
arrow={false}
|
||||||
|
trigger='hover'
|
||||||
>
|
>
|
||||||
<Button icon={activeIcon} title='View mode' {...buttonProps} />
|
<Button
|
||||||
|
icon={activeIcon}
|
||||||
|
title='View mode'
|
||||||
|
onClick={handleCycleView}
|
||||||
|
{...restButtonProps}
|
||||||
|
/>
|
||||||
</Popover>
|
</Popover>
|
||||||
<Modal
|
<Modal
|
||||||
title='Kanban settings'
|
title='Kanban settings'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user