mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 14:17:13 +01:00
Add unit select and backend implementation. Fix compare for websitestats. Remove unused params from stats, metrics, weekly
This commit is contained in:
parent
3f173889ea
commit
e73432dd26
14 changed files with 139 additions and 57 deletions
71
src/components/input/UnitFilter.tsx
Normal file
71
src/components/input/UnitFilter.tsx
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import { ListItem, Row, Select } from '@umami/react-zen';
|
||||
import { useMessages, useNavigation } from '@/components/hooks';
|
||||
import { DATE_RANGE_CONFIG, DEFAULT_DATE_RANGE_VALUE } from '@/lib/constants';
|
||||
import { getItem } from '@/lib/storage';
|
||||
|
||||
export function UnitFilter() {
|
||||
const { formatMessage, labels } = useMessages();
|
||||
const { router, query, updateParams } = useNavigation();
|
||||
|
||||
const DATE_RANGE_UNIT_CONFIG = {
|
||||
'0week': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'7day': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'0month': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'30day': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'hour'],
|
||||
},
|
||||
'90day': {
|
||||
defaultUnit: 'day',
|
||||
availableUnits: ['day', 'month'],
|
||||
},
|
||||
'6month': {
|
||||
defaultUnit: 'month',
|
||||
availableUnits: ['month', 'day'],
|
||||
},
|
||||
};
|
||||
|
||||
const unitConfig =
|
||||
DATE_RANGE_UNIT_CONFIG[query.date || getItem(DATE_RANGE_CONFIG) || DEFAULT_DATE_RANGE_VALUE];
|
||||
|
||||
if (!unitConfig) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleChange = (value: string) => {
|
||||
router.push(updateParams({ unit: value }));
|
||||
};
|
||||
|
||||
const options = unitConfig.availableUnits.map(unit => ({
|
||||
id: unit,
|
||||
label: formatMessage(labels[unit]),
|
||||
}));
|
||||
|
||||
const selectedUnit = query.unit ?? unitConfig.defaultUnit;
|
||||
|
||||
return (
|
||||
<Row>
|
||||
<Select
|
||||
value={selectedUnit}
|
||||
onChange={handleChange}
|
||||
popoverProps={{ placement: 'bottom right' }}
|
||||
style={{ width: 100 }}
|
||||
>
|
||||
{options.map(({ id, label }) => (
|
||||
<ListItem key={id} id={id}>
|
||||
{label}
|
||||
</ListItem>
|
||||
))}
|
||||
</Select>
|
||||
</Row>
|
||||
);
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ export function WebsiteDateFilter({
|
|||
}),
|
||||
);
|
||||
} else {
|
||||
router.push(updateParams({ date, offset: undefined }));
|
||||
router.push(updateParams({ date, offset: undefined, unit: undefined }));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue