-
Notifications
You must be signed in to change notification settings - Fork 2
BA-2169 BaseApp Activity Log - Filter by Date #200
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
Merged
anicioalexandre
merged 6 commits into
master
from
BA-2169-fe-package-base-app-activity-log-filter-by-date
Feb 26, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8ab7d13
add filter
mathieubouhelier fc0e0a4
refactoring
mathieubouhelier 5fd80ee
use swapdrawer
mathieubouhelier 934f75d
update IFetchParameters
mathieubouhelier 5520a99
restore activitylogfragment__generated
mathieubouhelier 4fa51eb
restore activitylogfragment__generated
mathieubouhelier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,16 @@ | ||
| import { ReactNode } from 'react' | ||
|
|
||
| export type SocialUpsertForm = { | ||
| body: string | ||
| } | ||
|
|
||
| export interface SearchNotFoundStateProps { | ||
| message?: string | ||
| } | ||
|
|
||
| export interface MobileDrawerProps { | ||
| open: boolean | ||
| onClose: () => void | ||
| title?: string | ||
| children: ReactNode | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
packages/components/modules/activity-log/DateFilterChip/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| import { FC, useState } from 'react' | ||
|
|
||
| import { SwipeableDrawer } from '@baseapp-frontend/design-system/components/web/drawers' | ||
| import { DATE_FORMAT, formatDate } from '@baseapp-frontend/utils' | ||
|
|
||
| import { KeyboardArrowDown } from '@mui/icons-material' | ||
| import { Box, Chip, Divider, Menu, Theme, Typography, useMediaQuery } from '@mui/material' | ||
| import { DateTime } from 'luxon' | ||
|
|
||
| import DateFilterComponent from '../DateFilterComponent' | ||
| import { DateFilterChipProps } from './types' | ||
|
|
||
| const DateFilterChip: FC<DateFilterChipProps> = ({ fetchParameters, executeRefetch }) => { | ||
| const [drawerOpen, setDrawerOpen] = useState(false) | ||
| const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null) | ||
| const isMobile = useMediaQuery<Theme>((theme) => theme.breakpoints.down('sm')) | ||
|
|
||
| const handleDrawerOpen = () => setDrawerOpen(true) | ||
| const handleDrawerClose = () => setDrawerOpen(false) | ||
| const handleMenuClose = () => setAnchorEl(null) | ||
|
|
||
| const { createdFrom, createdTo } = fetchParameters | ||
| const hasDateSelected = createdFrom || createdTo | ||
|
|
||
| const parseDate = (date: string | null): DateTime | null => | ||
| date ? DateTime.fromFormat(date, DATE_FORMAT.api) : null | ||
|
|
||
| const formatLabelDate = (date: string | null): string | null => | ||
| date ? formatDate(date, { toFormat: DATE_FORMAT[3] }) : null | ||
|
|
||
| const labelRender = () => { | ||
| const fromDate = formatLabelDate(createdFrom) | ||
| const toDate = formatLabelDate(createdTo) | ||
| if (createdFrom && createdTo) return `${fromDate} - ${toDate}` | ||
|
|
||
| if (createdFrom) return `From ${fromDate}` | ||
| if (createdTo) return `Until ${toDate}` | ||
| return 'Period' | ||
| } | ||
|
|
||
| const handleOnClickOnChip = (event: React.MouseEvent<HTMLElement>) => { | ||
| if (isMobile) { | ||
mathieubouhelier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| handleDrawerOpen() | ||
| } else { | ||
| setAnchorEl(event.currentTarget) | ||
| } | ||
| } | ||
|
|
||
| const renderDateFilterComponent = (onClose: () => void) => ( | ||
| <> | ||
| <Typography variant="subtitle1" m={4} align="center"> | ||
| Period | ||
| </Typography> | ||
| <Divider sx={{ marginBottom: 2 }} /> | ||
| <DateFilterComponent | ||
| createdFrom={parseDate(createdFrom)} | ||
| createdTo={parseDate(createdTo)} | ||
| executeRefetch={executeRefetch} | ||
| onApply={onClose} | ||
| onClearFilter={onClose} | ||
| /> | ||
| </> | ||
| ) | ||
|
|
||
| return ( | ||
| <> | ||
| <Chip | ||
| label={ | ||
| <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}> | ||
| <span>{labelRender()}</span> | ||
| <KeyboardArrowDown color="action" /> | ||
| </Box> | ||
| } | ||
| onClick={handleOnClickOnChip} | ||
| variant={hasDateSelected ? 'filled' : 'soft'} | ||
| color="default" | ||
| /> | ||
| {isMobile ? ( | ||
| <SwipeableDrawer globalHeight="auto" open={drawerOpen} onClose={handleDrawerClose}> | ||
| {renderDateFilterComponent(handleDrawerClose)} | ||
| </SwipeableDrawer> | ||
| ) : ( | ||
| <Menu anchorEl={anchorEl} open={Boolean(anchorEl)} onClose={handleMenuClose}> | ||
| <Box padding={2}>{renderDateFilterComponent(handleMenuClose)}</Box> | ||
| </Menu> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| export default DateFilterChip | ||
6 changes: 6 additions & 0 deletions
6
packages/components/modules/activity-log/DateFilterChip/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { FetchParameters } from '../common/types' | ||
|
|
||
| export interface DateFilterChipProps { | ||
| fetchParameters: FetchParameters | ||
| executeRefetch: (params: Partial<FetchParameters>) => void | ||
| } |
116 changes: 116 additions & 0 deletions
116
packages/components/modules/activity-log/DateFilterComponent/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import React, { FC, useState } from 'react' | ||
|
|
||
| import { Box, Button } from '@mui/material' | ||
| import { DateValidationError, LocalizationProvider } from '@mui/x-date-pickers' | ||
| import { AdapterLuxon } from '@mui/x-date-pickers/AdapterLuxon' | ||
| import { DatePicker } from '@mui/x-date-pickers/DatePicker' | ||
| import { DateTime } from 'luxon' | ||
|
|
||
| import { DateFilterComponentProps } from './types' | ||
|
|
||
| const DateFilterComponent: FC<DateFilterComponentProps> = ({ | ||
| createdFrom, | ||
| createdTo, | ||
| executeRefetch, | ||
| onApply, | ||
| onClearFilter, | ||
| }) => { | ||
| const [tempCreatedFrom, setTempCreatedFrom] = useState<DateTime | null>(createdFrom ?? null) | ||
| const [tempCreatedTo, setTempCreatedTo] = useState<DateTime | null>(createdTo ?? null) | ||
|
|
||
| const [error, setError] = useState<DateValidationError | null>(null) | ||
|
|
||
| const errorMessage = React.useMemo(() => { | ||
| switch (error) { | ||
| case 'minDate': | ||
| return 'End date cannot be earlier than start date.' | ||
| case 'invalidDate': | ||
| return 'Your date is not valid' | ||
| default: | ||
| return '' | ||
| } | ||
| }, [error]) | ||
|
|
||
| const handleApply = () => { | ||
| if (tempCreatedTo && tempCreatedFrom && tempCreatedTo < tempCreatedFrom) { | ||
| setError('minDate') | ||
| return | ||
| } | ||
|
|
||
| setError(null) | ||
| executeRefetch({ | ||
| createdFrom: tempCreatedFrom ? tempCreatedFrom.toISODate() : null, | ||
| createdTo: tempCreatedTo ? tempCreatedTo.toISODate() : null, | ||
| }) | ||
| onApply?.() | ||
| } | ||
|
|
||
| const handleClear = () => { | ||
| if (createdFrom || createdTo) { | ||
| executeRefetch({ | ||
| createdFrom: null, | ||
| createdTo: null, | ||
| }) | ||
| } | ||
| setTempCreatedFrom(null) | ||
| setTempCreatedTo(null) | ||
| onClearFilter?.() | ||
| } | ||
|
|
||
| const disableStartDate = (date: DateTime) => (tempCreatedTo ? date > tempCreatedTo : false) | ||
|
|
||
| const disableEndDate = (date: DateTime) => (tempCreatedFrom ? date < tempCreatedFrom : false) | ||
|
|
||
| return ( | ||
| <Box display="flex" gap={2} flexDirection="column"> | ||
| <LocalizationProvider dateAdapter={AdapterLuxon}> | ||
| <DatePicker | ||
| label="Start date" | ||
| onChange={(newValue) => setTempCreatedFrom(newValue)} | ||
| disableFuture | ||
| value={tempCreatedFrom} | ||
| shouldDisableDate={disableStartDate} | ||
| slotProps={{ | ||
| day: (dayProps) => ({ | ||
| sx: { | ||
| ...(disableStartDate(dayProps.day) && { | ||
| backgroundColor: 'error.lighter', | ||
| }), | ||
| }, | ||
| }), | ||
| }} | ||
| /> | ||
| <DatePicker | ||
| label="End date" | ||
| value={tempCreatedTo} | ||
| onChange={(newValue) => setTempCreatedTo(newValue)} | ||
| onError={(newError) => setError(newError)} | ||
| disableFuture | ||
| shouldDisableDate={disableEndDate} | ||
| slotProps={{ | ||
| textField: { | ||
| helperText: errorMessage, | ||
| }, | ||
| day: (dayProps) => ({ | ||
| sx: { | ||
| ...(disableEndDate(dayProps.day) && { | ||
| backgroundColor: 'error.lighter', | ||
| }), | ||
| }, | ||
| }), | ||
| }} | ||
| /> | ||
| </LocalizationProvider> | ||
| <Box display="flex" gap={2} flexDirection="column" mt={4} mb={2}> | ||
| <Button onClick={handleApply} variant="contained" color="inherit"> | ||
| Filter | ||
| </Button> | ||
| <Button onClick={handleClear} variant="outlined" color="inherit"> | ||
| Clear Filter | ||
| </Button> | ||
| </Box> | ||
| </Box> | ||
| ) | ||
| } | ||
|
|
||
| export default DateFilterComponent |
11 changes: 11 additions & 0 deletions
11
packages/components/modules/activity-log/DateFilterComponent/types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { DateTime } from 'luxon' | ||
|
|
||
| import { FetchParameters } from '../common/types' | ||
|
|
||
| export interface DateFilterComponentProps { | ||
| createdFrom: DateTime | null | ||
| createdTo: DateTime | null | ||
| executeRefetch: (params: Partial<FetchParameters>) => void | ||
| onApply?: () => void | ||
| onClearFilter?: () => void | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.