fix mobile view for admin screens and nav. update equals and not equals filter to be multiselect.
This commit is contained in:
1 parent
8530329e14
commit
67626652f9
12 files changed
+188
-48
No files matched your search
@@ -1,6 +1,17 @@
|
||||
import { Button, Column, Grid, Icon, Label, ListItem, Select, TextField } from '@umami/react-zen';
|
||||
import {
|
||||
Button,
|
||||
Column,
|
||||
Grid,
|
||||
Icon,
|
||||
Label,
|
||||
ListItem,
|
||||
Loading,
|
||||
Select,
|
||||
TextField,
|
||||
} from '@umami/react-zen';
|
||||
import { useState } from 'react';
|
||||
import { Empty } from '@/components/common/Empty';
|
||||
import { MultiSelect } from '@/components/common/MultiSelect';
|
||||
import { useFilters, useFormat, useWebsiteValuesQuery } from '@/components/hooks';
|
||||
import { X } from '@/components/icons';
|
||||
import { isSearchOperator } from '@/lib/params';
|
||||
@@ -12,7 +23,7 @@ export interface FilterRecordProps {
|
||||
endDate: Date;
|
||||
name: string;
|
||||
operator: string;
|
||||
value: string;
|
||||
value: string | string[];
|
||||
onSelect?: (name: string, value: any) => void;
|
||||
onRemove?: (name: string) => void;
|
||||
onChange?: (name: string, value: string) => void;
|
||||
@@ -31,7 +42,8 @@ export function FilterRecord({
|
||||
onChange,
|
||||
}: FilterRecordProps) {
|
||||
const { fields, operators } = useFilters();
|
||||
const [selected, setSelected] = useState(value);
|
||||
const initValues = Array.isArray(value) ? value : value ? value.split(',') : [];
|
||||
const [selected, setSelected] = useState<string[]>(initValues);
|
||||
const [search, setSearch] = useState('');
|
||||
const { formatValue } = useFormat();
|
||||
const { data, isLoading } = useWebsiteValuesQuery({
|
||||
@@ -53,10 +65,15 @@ export function FilterRecord({
|
||||
};
|
||||
|
||||
const handleSelectValue = (value: string) => {
|
||||
setSelected(value);
|
||||
setSelected([value]);
|
||||
onChange?.(name, value);
|
||||
};
|
||||
|
||||
const handleMultiSelectValue = (values: string[]) => {
|
||||
setSelected(values);
|
||||
onChange?.(name, values.join(','));
|
||||
};
|
||||
|
||||
return (
|
||||
<Column>
|
||||
<Label>{fields.find(f => f.name === name)?.label}</Label>
|
||||
@@ -72,26 +89,30 @@ export function FilterRecord({
|
||||
))}
|
||||
</Select>
|
||||
{isSearch && (
|
||||
<TextField value={selected} defaultValue={selected} onChange={handleSelectValue} />
|
||||
<TextField
|
||||
value={selected[0] || ''}
|
||||
defaultValue={selected[0] || ''}
|
||||
onChange={handleSelectValue}
|
||||
/>
|
||||
)}
|
||||
{!isSearch && (
|
||||
<Select
|
||||
<MultiSelect
|
||||
value={selected}
|
||||
onChange={handleSelectValue}
|
||||
onChange={handleMultiSelectValue}
|
||||
searchValue={search}
|
||||
onSearch={handleSearch}
|
||||
isLoading={isLoading}
|
||||
listProps={{ renderEmptyState: () => <Empty /> }}
|
||||
renderValue={values =>
|
||||
values.length > 0 ? values.map(v => formatValue(v, type)).join(', ') : undefined
|
||||
}
|
||||
renderEmptyState={() => (isLoading ? <Loading icon="dots" /> : <Empty />)}
|
||||
allowSearch
|
||||
>
|
||||
{items?.map(({ value }) => {
|
||||
return (
|
||||
<ListItem key={value} id={value}>
|
||||
{formatValue(value, type)}
|
||||
</ListItem>
|
||||
);
|
||||
})}
|
||||
</Select>
|
||||
{items.map(({ value }) => (
|
||||
<ListItem key={value} id={value}>
|
||||
{formatValue(value, type)}
|
||||
</ListItem>
|
||||
))}
|
||||
</MultiSelect>
|
||||
)}
|
||||
</Grid>
|
||||
<Column justifyContent="flex-start">
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Button, Column, Icon, List, MenuTrigger, Popover, SearchField } from '@umami/react-zen';
|
||||
import type { ReactNode } from 'react';
|
||||
import { ChevronRight } from '@/components/icons';
|
||||
|
||||
interface MultiSelectProps {
|
||||
value?: string[];
|
||||
onChange?: (values: string[]) => void;
|
||||
searchValue?: string;
|
||||
onSearch?: (value: string) => void;
|
||||
placeholder?: string;
|
||||
allowSearch?: boolean;
|
||||
renderEmptyState?: () => ReactNode;
|
||||
renderValue?: (values: string[]) => ReactNode;
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
export function MultiSelect({
|
||||
value = [],
|
||||
onChange,
|
||||
searchValue,
|
||||
onSearch,
|
||||
placeholder = 'Select an item',
|
||||
allowSearch,
|
||||
renderEmptyState,
|
||||
renderValue,
|
||||
children,
|
||||
}: MultiSelectProps) {
|
||||
const displayValue = renderValue
|
||||
? renderValue(value)
|
||||
: value.length > 0
|
||||
? value.join(', ')
|
||||
: null;
|
||||
|
||||
return (
|
||||
<MenuTrigger>
|
||||
<Button
|
||||
variant="outline"
|
||||
className="w-full justify-between"
|
||||
style={{ maxWidth: '100%', overflow: 'hidden' }}
|
||||
>
|
||||
<span style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' }}>
|
||||
{displayValue ?? placeholder}
|
||||
</span>
|
||||
<Icon rotate={90} size="sm" aria-hidden="true">
|
||||
<ChevronRight />
|
||||
</Icon>
|
||||
</Button>
|
||||
<Popover style={{ minWidth: 'var(--trigger-width)', maxWidth: 'var(--trigger-width)' }}>
|
||||
<Column
|
||||
gap="2"
|
||||
padding="2"
|
||||
border
|
||||
borderRadius="md"
|
||||
shadow="lg"
|
||||
className="bg-surface-overlay"
|
||||
>
|
||||
{allowSearch && <SearchField value={searchValue} onSearch={onSearch} autoFocus />}
|
||||
<List
|
||||
selectionMode="multiple"
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
showCheckmark
|
||||
renderEmptyState={renderEmptyState}
|
||||
>
|
||||
{children}
|
||||
</List>
|
||||
</Column>
|
||||
</Popover>
|
||||
</MenuTrigger>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user