mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-22 18:00:17 +01:00
sort formatted filter values
This commit is contained in:
parent
8a4623eb7b
commit
d5eddeae24
@ -1,6 +1,6 @@
|
|||||||
import { useState } from 'react';
|
import { useState, useMemo } from 'react';
|
||||||
import { Form, FormRow, Item, Flexbox, Dropdown, Button } from 'react-basics';
|
import { Form, FormRow, Item, Flexbox, Dropdown, Button } from 'react-basics';
|
||||||
import { useMessages, useFilters, useFormat } from 'components/hooks';
|
import { useMessages, useFilters, useFormat, useLocale } from 'components/hooks';
|
||||||
import styles from './FieldFilterForm.module.css';
|
import styles from './FieldFilterForm.module.css';
|
||||||
|
|
||||||
export default function FieldFilterForm({
|
export default function FieldFilterForm({
|
||||||
@ -16,14 +16,26 @@ export default function FieldFilterForm({
|
|||||||
const [value, setValue] = useState();
|
const [value, setValue] = useState();
|
||||||
const { getFilters } = useFilters();
|
const { getFilters } = useFilters();
|
||||||
const { formatValue } = useFormat();
|
const { formatValue } = useFormat();
|
||||||
|
const { locale } = useLocale();
|
||||||
const filters = getFilters(type);
|
const filters = getFilters(type);
|
||||||
|
|
||||||
|
const formattedValues = useMemo(() => {
|
||||||
|
const formatted = {};
|
||||||
|
const { compare } = new Intl.Collator(locale, { numeric: true });
|
||||||
|
const format = val => {
|
||||||
|
formatted[val] = formatValue(val, name);
|
||||||
|
return formatted[val];
|
||||||
|
};
|
||||||
|
values.sort((a, b) => compare(formatted[a] ?? format(a), formatted[b] ?? format(b)));
|
||||||
|
return formatted;
|
||||||
|
}, [values]);
|
||||||
|
|
||||||
const renderFilterValue = value => {
|
const renderFilterValue = value => {
|
||||||
return filters.find(f => f.value === value)?.label;
|
return filters.find(f => f.value === value)?.label;
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderValue = value => {
|
const renderValue = value => {
|
||||||
return formatValue(value, name);
|
return formattedValues[value];
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleAdd = () => {
|
const handleAdd = () => {
|
||||||
@ -59,7 +71,7 @@ export default function FieldFilterForm({
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{value => {
|
{value => {
|
||||||
return <Item key={value}>{formatValue(value, name)}</Item>;
|
return <Item key={value}>{formattedValues[value]}</Item>;
|
||||||
}}
|
}}
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
</Flexbox>
|
</Flexbox>
|
||||||
|
Loading…
Reference in New Issue
Block a user