-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FiltersPanel): support sort filter
- Loading branch information
1 parent
3f61db1
commit 6e0dd45
Showing
15 changed files
with
284 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -7,5 +7,6 @@ | |
"Tags": "Tags", | ||
"Estimate": "Estimate", | ||
"Limit": "Limit", | ||
"Preset": "Preset" | ||
"Preset": "Preset", | ||
"Sort": "Sort" | ||
} |
This file contains 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 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 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 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 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,10 @@ | ||
{ | ||
"title": "Title", | ||
"state": "State", | ||
"priority": "Priority", | ||
"project": "Project", | ||
"activity": "Issuer", | ||
"owner": "Owner", | ||
"updatedAt": "Updated", | ||
"createdAt": "Created" | ||
} |
This file contains 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,17 @@ | ||
/* eslint-disable */ | ||
// Do not edit, use generator to update | ||
import { i18n, fmt, I18nLangSet } from 'easy-typed-intl'; | ||
import getLang from '../../../utils/getLang'; | ||
|
||
import ru from './ru.json'; | ||
import en from './en.json'; | ||
|
||
export type I18nKey = keyof typeof ru & keyof typeof en; | ||
type I18nLang = 'ru' | 'en'; | ||
|
||
const keyset: I18nLangSet<I18nKey> = {}; | ||
|
||
keyset['ru'] = ru; | ||
keyset['en'] = en; | ||
|
||
export const tr = i18n<I18nLang, I18nKey>(keyset, fmt, getLang); |
This file contains 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,10 @@ | ||
{ | ||
"title": "Название", | ||
"state": "Статус", | ||
"priority": "Приоритет", | ||
"project": "Проект", | ||
"activity": "Автор", | ||
"owner": "Ответственный", | ||
"updatedAt": "Обновлено", | ||
"createdAt": "Создано" | ||
} |
This file contains 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,108 @@ | ||
import { FC, useCallback, useMemo } from 'react'; | ||
import { FiltersDropdownBase, MenuItem, Text } from '@taskany/bricks'; | ||
import { gray8 } from '@taskany/colors'; | ||
|
||
import { tr } from './SortFilter.i18n'; | ||
|
||
export type SortDirection = 'asc' | 'desc' | null; | ||
export type SortableProps = | ||
| 'title' | ||
| 'state' | ||
| 'priority' | ||
| 'project' | ||
| 'activity' | ||
| 'owner' | ||
| 'updatedAt' | ||
| 'createdAt'; | ||
|
||
const getNextDirection = (currentDirection: SortDirection): SortDirection => { | ||
switch (currentDirection) { | ||
case 'asc': | ||
return 'desc'; | ||
case 'desc': | ||
return null; | ||
default: | ||
return 'asc'; | ||
} | ||
}; | ||
|
||
export const SortFilter: FC<{ | ||
text: string; | ||
value: Record<SortableProps, NonNullable<SortDirection>> | Record<string, never>; | ||
onChange: (value: Record<SortableProps, NonNullable<SortDirection>>) => void; | ||
}> = ({ text, value, onChange }) => { | ||
const sortableProps = useMemo<Record<SortableProps, string>>( | ||
() => ({ | ||
title: tr('title'), | ||
state: tr('state'), | ||
priority: tr('priority'), | ||
project: tr('project'), | ||
activity: tr('activity'), | ||
owner: tr('owner'), | ||
updatedAt: tr('updatedAt'), | ||
createdAt: tr('createdAt'), | ||
}), | ||
[], | ||
); | ||
|
||
const items = useMemo( | ||
() => | ||
Object.entries(sortableProps).map(([id, text]) => { | ||
const direction = value[id as SortableProps]; | ||
return { | ||
item: { | ||
id, | ||
data: { | ||
text, | ||
direction, | ||
selected: Boolean(direction), | ||
}, | ||
}, | ||
}; | ||
}), | ||
[value, sortableProps], | ||
); | ||
|
||
type SortFilterItems = typeof items; | ||
|
||
const onClick = useCallback( | ||
(id: SortableProps, direction: SortDirection) => () => { | ||
let newValue = { ...value } as Record<SortableProps, NonNullable<SortDirection>>; | ||
const nextDirection = getNextDirection(direction); | ||
|
||
if (!nextDirection) { | ||
delete newValue[id]; | ||
} else { | ||
newValue = { | ||
...newValue, | ||
[id]: nextDirection, | ||
}; | ||
} | ||
|
||
onChange(newValue); | ||
}, | ||
[value, onChange], | ||
); | ||
|
||
return ( | ||
<FiltersDropdownBase | ||
text={text} | ||
items={items.map((el) => ({ id: el.item.id, data: el.item.data }))} | ||
value={Object.keys(value).length ? [''] : []} | ||
onChange={() => {}} | ||
renderItem={({ | ||
item: { | ||
id, | ||
data: { text, direction }, | ||
}, | ||
}: SortFilterItems[number]) => ( | ||
<MenuItem ghost key={id} onClick={onClick(id as SortableProps, direction)}> | ||
{text}{' '} | ||
<Text as="span" weight="bold" color={gray8} size="xs"> | ||
{direction} | ||
</Text> | ||
</MenuItem> | ||
)} | ||
/> | ||
); | ||
}; |
This file contains 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 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 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 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.