Skip to content

Commit

Permalink
feat(small): show the number of active filters on Filter button
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Jan 23, 2024
1 parent b41934d commit f5cd4b6
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 9 deletions.
6 changes: 4 additions & 2 deletions src/frontend/components/app/action-header/action-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const ActionHeader: React.FC<ActionHeaderProps> = (props) => {
const location = useLocation()
const actionResponseHandler = useActionResponseHandler(actionPerformed)
const modalFunctions = useModal()
const { toggleFilter } = useFilterDrawer()
const { toggleFilter, filtersCount } = useFilterDrawer()

if (action.hideActionHeader) {
return null
Expand Down Expand Up @@ -74,8 +74,10 @@ const ActionHeader: React.FC<ActionHeaderProps> = (props) => {
})

if (typeof isFilterButtonVisible === 'function' || isFilterButtonVisible) {
const filterTranslationKey = filtersCount > 0 ? 'filterActive' : 'filter'

actionButtons.push({
label: translateButton('filter', resource.id),
label: translateButton(filterTranslationKey, resource.id, { count: filtersCount }),
onClick: toggleFilter,
icon: 'Filter',
'data-css': getResourceElementCss(resource.id, 'filter-button'),
Expand Down
10 changes: 5 additions & 5 deletions src/frontend/hooks/use-filter-drawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useQueryParams } from './use-query-params.js'

export const useFilterDrawer = () => {
const [filtersCount, setFiltersCount] = useState(0)
const dispach = useDispatch()
const dispatch = useDispatch()
const isVisible = useSelector((state: ReduxState) => state.filterDrawer.isVisible)

const { showFilters, filters = {} } = useQueryParams()
Expand All @@ -17,20 +17,20 @@ export const useFilterDrawer = () => {

useEffect(() => {
if (showFilters) {
dispach(showFilterDrawer())
dispatch(showFilterDrawer())
}
}, [showFilters])

const toggleFilter = () => {
dispach(isVisible ? hideFilterDrawer() : showFilterDrawer())
dispatch(isVisible ? hideFilterDrawer() : showFilterDrawer())
}

const open = () => {
dispach(showFilterDrawer())
dispatch(showFilterDrawer())
}

const close = () => {
dispach(hideFilterDrawer())
dispatch(hideFilterDrawer())
}

return {
Expand Down
1 change: 1 addition & 0 deletions src/locale/de/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "Speichern",
"addNewItem": "Neuen Eintrag hinzufügen",
"filter": "Filter",
"filterActive": "Filter ({{count}})",
"applyChanges": "Änderungen übernehmen",
"resetFilter": "Zurücksetzen",
"confirmRemovalMany": "Bestätigen Sie das Löschen des Eintrag",
Expand Down
2 changes: 1 addition & 1 deletion src/locale/en/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "Save",
"addNewItem": "Add new item",
"filter": "Filter",
"filterActive": "Filter ({{count}})",
"applyChanges": "Apply changes",
"resetFilter": "Reset",
"confirmRemovalMany": "Confirm the removal of {{count}} record",
Expand Down Expand Up @@ -118,7 +119,6 @@
"initialKey": "Key-{{number}}",
"keyInUse": "Object keys must be unique",
"keyValuePropertyDefaultDescription": "All values are stored as text. Keys must be unique, duplicate keys will not be saved.",

"pageNotFound_title": "Page not found",
"pageNotFound_subtitle": "Page <strong>\"{{pageName}}\"</strong> does not exist",
"componentNotFound_title": "No component specified",
Expand Down
1 change: 1 addition & 0 deletions src/locale/es/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "Guardar",
"addNewItem": "Agregar nuevo elemento",
"filter": "Filtrar",
"filterActive": "Filtrar ({{count}})",
"applyChanges": "Aplicar cambios",
"resetFilter": "Reiniciar",
"confirmRemovalMany": "Confirmar la eliminación de {{count}} registro",
Expand Down
1 change: 1 addition & 0 deletions src/locale/it/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "Salva",
"addNewItem": "Aggiungi nuovo elemento",
"filter": "Filtro",
"filterActive": "Filtro ({{count}})",
"applyChanges": "Applica modifiche",
"resetFilter": "Resetta filtro",
"confirmRemovalMany": "Conferma la rimozione di {{count}} elementi",
Expand Down
1 change: 1 addition & 0 deletions src/locale/ja/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "保存",
"addNewItem": "新しいアイテムを追加",
"filter": "フィルタ",
"filterActive": "フィルタ ({{count}})",
"applyChanges": "変更を適用",
"resetFilter": "リセット",
"confirmRemovalMany": "{{count}} 件のレコードを削除しますか",
Expand Down
3 changes: 2 additions & 1 deletion src/locale/pl/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"buttons": {
"save": "Zapisz",
"addNewItem": "Nowy",
"filter": "Filtr",
"filter": "Filtry",
"filterActive": "Filtry ({{count}})",
"applyChanges": "Zastosuj zmiany",
"resetFilter": "Wyczyść",
"confirmRemovalMany": "Potwierdź usunięcie {{count}} pozycji",
Expand Down
1 change: 1 addition & 0 deletions src/locale/pt-BR/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "Salvar",
"addNewItem": "Adicionar Novo Item",
"filter": "Filtrar",
"filterActive": "Filtrar ({{count}})",
"applyChanges": "Aplicar mudanças",
"resetFilter": "Redefinir",
"confirmRemovalMany": "Confirma a remoção de {{count}} registro",
Expand Down
1 change: 1 addition & 0 deletions src/locale/ua/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "Зберегти",
"addNewItem": "Додати новий елемент",
"filter": "Фільтр",
"filterActive": "Фільтр ({{count}})",
"applyChanges": "Застосувати зміни",
"resetFilter": "Очистити фільтри",
"confirmRemovalMany": "Підтвердити видалення {{count}} запису",
Expand Down
1 change: 1 addition & 0 deletions src/locale/zh-CN/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"save": "保存",
"addNewItem": "添加新的项目",
"filter": "筛选",
"filterActive": "筛选 ({{count}})",
"applyChanges": "应用更改",
"resetFilter": "重置筛选器",
"confirmRemovalMany": "确认删除 {{count}} 个记录",
Expand Down

0 comments on commit f5cd4b6

Please sign in to comment.