Skip to content

Commit

Permalink
feat(admin): add reset filters button
Browse files Browse the repository at this point in the history
  • Loading branch information
Mati365 committed Oct 12, 2024
1 parent e2ef007 commit f91668d
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 9 deletions.
1 change: 1 addition & 0 deletions apps/admin/src/components/predefined/buttons/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export * from './archive-button';
export * from './cancel-button';
export * from './create-button';
export * from './reset-filters-button';
export * from './save-button';
export * from './unarchive-button';
export * from './update-button';
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import clsx from 'clsx';

import { useI18n } from '~/i18n';

type Props = Omit<JSX.IntrinsicElements['button'], 'children'>;

export function ResetFiltersButton({ className, ...props }: Props) {
const { pack } = useI18n();

return (
<button
type="button"
className={clsx('uk-button uk-button-default', className)}
{...props}
>
{pack.buttons.resetFilters}
</button>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,15 @@ export function useDebouncedPaginatedSearch<
};

const reset = () => {
const { initialState } = urlPagination;

pagination.setValue({
value: {
...urlPagination.initialState,
offset: 0,
limit: initialState?.limit ?? 10,
...'archived' in initialState && {
archived: false,
},
__revision: Date.now(),
},
});
Expand Down
1 change: 1 addition & 0 deletions apps/admin/src/i18n/packs/i18n-lang-en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export const I18N_PACK_EN = {
update: 'Update',
add: 'Add',
confirm: 'Confirm',
resetFilters: 'Reset filters',
},
badges: {
archive: {
Expand Down
1 change: 1 addition & 0 deletions apps/admin/src/i18n/packs/i18n-lang-pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export const I18N_PACK_PL: I18nLangPack = {
update: 'Aktualizuj',
add: 'Dodaj',
confirm: 'Potwierdź',
resetFilters: 'Resetuj filtry',
},
badges: {
archive: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PaginatedTable,
PaginationSearchToolbarItem,
PaginationToolbar,
ResetFiltersButton,
useDebouncedPaginatedSearch,
} from '~/components';
import { useI18n } from '~/i18n';
Expand Down Expand Up @@ -61,6 +62,8 @@ export function OrganizationsTableContainer() {
}),
})}
/>

<ResetFiltersButton onClick={reset} />
</PaginationToolbar>

<PaginatedTable
Expand Down
3 changes: 3 additions & 0 deletions apps/admin/src/modules/users/table/users-table-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
PaginatedTable,
PaginationSearchToolbarItem,
PaginationToolbar,
ResetFiltersButton,
useDebouncedPaginatedSearch,
} from '~/components';
import { genRandomPassword } from '~/helpers';
Expand Down Expand Up @@ -99,6 +100,8 @@ export function UsersTableContainer() {
prefix={pack.modules.organizations.prefix.organization}
{...pagination.bind.path('organization')}
/>

<ResetFiltersButton onClick={reset} />
</PaginationToolbar>

<PaginatedTable
Expand Down
5 changes: 4 additions & 1 deletion apps/admin/src/modules/users/table/users-table-row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export function UsersTableRow({ item, onUpdated }: Props) {
{(
item.role === 'user'
? (
<Link className="uk-link" href={sitemap.organizations.edit(item.organization.id)}>
<Link
className="uk-link"
href={sitemap.organizations.show(item.organization.id)}
>
{item.organization.name}
</Link>
)
Expand Down
14 changes: 7 additions & 7 deletions apps/admin/src/routes/use-sitemap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export function useSitemap() {
home: '/',
login: '/login',
organizations: {
index: defineRouteGenerator<SearchOrganizationsRouteUrlFiltersT, 'edit'>()('/organizations'),
edit: (id: SdkTableRowIdT) => sitemap.organizations.index.generate({
hash: 'edit',
index: defineRouteGenerator<SearchOrganizationsRouteUrlFiltersT>()('/organizations'),
show: (id: SdkTableRowIdT) => sitemap.organizations.index.generate({
searchParams: {
archived: null,
ids: [id],
},
}),
Expand All @@ -50,10 +50,6 @@ function defineRouteGenerator<
? parameterizeStrictPath(schema, pathParams)
: schema,

hash
? withHash(hash)
: identity,

searchParams || defaultSearchParams
? withSearchParams(
{
Expand All @@ -62,6 +58,10 @@ function defineRouteGenerator<
},
)
: identity,

hash
? withHash(hash)
: identity,
),
});
}
Expand Down

0 comments on commit f91668d

Please sign in to comment.