Skip to content

Commit

Permalink
chore: Remove sorting button (#1392) (#1396)
Browse files Browse the repository at this point in the history
chore: Remove sorting button (#1392)
  • Loading branch information
alexdigdir authored Nov 25, 2024
1 parent 4e4c4b1 commit bbb66cc
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 219 deletions.
16 changes: 2 additions & 14 deletions packages/frontend/src/components/FosToolbar/FosToolbar.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
import { ArrowsUpDownIcon, BookmarkIcon, PlusIcon } from '@navikt/aksel-icons';
import { BookmarkIcon, PlusIcon } from '@navikt/aksel-icons';
import { useTranslation } from 'react-i18next';
import { ProfileButton } from '../ProfileButton';

import styles from './fosToolbar.module.css';

interface FosToolbarProps {
onFilterBtnClick?: () => void;
onSortBtnClick?: () => void;
onSaveBtnClick: () => void;
hideSaveButton?: boolean;
}
/*
* FosToolbar is a floating toolbar that is only visible on mobile and contains action buttons for filtering, sorting and saving search.
* @param onFilterBtnClick - Function that is called when the filter button is clicked.
* @param onSortBtnClick - Function that is called when the sort button is clicked.
* @param onSaveBtnClick - Function that is called when the save button is clicked.
* @param hideSaveButton - Optional boolean that determines if the save button should be hidden. Default is false
* @returns A floating toolbar with action buttons for filtering, sorting and saving search.
*/
export const FosToolbar = ({
onFilterBtnClick,
onSaveBtnClick,
onSortBtnClick,
hideSaveButton = false,
}: FosToolbarProps) => {
export const FosToolbar = ({ onFilterBtnClick, onSaveBtnClick, hideSaveButton = false }: FosToolbarProps) => {
const { t } = useTranslation();
return (
<div className={styles.fosToolbar}>
Expand All @@ -33,11 +26,6 @@ export const FosToolbar = ({
<PlusIcon fontSize="1.5rem" /> {t('fos.buttons.filter')}
</ProfileButton>
)}
{onSortBtnClick && (
<ProfileButton onClick={onSortBtnClick} size="sm" variant="tertiary">
<ArrowsUpDownIcon fontSize="1.5rem" /> {t('fos.buttons.sort')}
</ProfileButton>
)}
{hideSaveButton ? null : (
<ProfileButton onClick={onSaveBtnClick} size="sm" variant="tertiary">
<BookmarkIcon fontSize="1.5rem" /> {t('fos.buttons.save_search')}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion packages/frontend/src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './FilterBar';
export * from './BottomDrawer';
export * from './PageLayout';
export * from './DropdownMenu';
export * from './SortOrderDropdown';
export * from './Snackbar';
export * from './HorizontalLine';
export * from './Badge';
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/i18n/resources/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"footer.nav.service_messages": "Service messages",
"fos.buttons.filter": "Filter",
"fos.buttons.save_search": "Save",
"fos.buttons.sort": "Sort",
"header.searchPlaceholder": "Search in inbox",
"inbox.attachment.count": "{count, plural, =0 {No attachments} one {# attachment} other {# attachments}}",
"inbox.attachment.link": "Link as attachment",
Expand Down
1 change: 0 additions & 1 deletion packages/frontend/src/i18n/resources/nb.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
"footer.nav.service_messages": "Driftsmeldinger",
"fos.buttons.filter": "Filter",
"fos.buttons.save_search": "Lagre",
"fos.buttons.sort": "Sorter",
"header.searchPlaceholder": "Søk i innboks",
"inbox.attachment.count": "{count, plural, =0 {Ingen vedlegg} one {# vedlegg} other {# vedlegg}}",
"inbox.attachment.link": "Lenke som vedlegg",
Expand Down
43 changes: 4 additions & 39 deletions packages/frontend/src/pages/Inbox/Inbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
InboxItem,
InboxItems,
PartyDropdown,
SortOrderDropdown,
useSearchString,
useSelectedDialogs,
useSnackbar,
Expand All @@ -25,14 +24,13 @@ import type { FilterBarRef } from '../../components/FilterBar/FilterBar.tsx';
import { FosToolbar } from '../../components/FosToolbar';
import { InboxItemsHeader } from '../../components/InboxItem/InboxItemsHeader.tsx';
import { SaveSearchButton } from '../../components/SavedSearchButton/SaveSearchButton.tsx';
import type { SortOrderDropdownRef, SortingOrder } from '../../components/SortOrderDropdown/SortOrderDropdown.tsx';
import { QUERY_KEYS } from '../../constants/queryKeys.ts';
import { FeatureFlagKeys, useFeatureFlag } from '../../featureFlags';
import { useFormat } from '../../i18n/useDateFnsLocale.tsx';
import { InboxSkeleton } from './InboxSkeleton.tsx';
import { filterDialogs, getFilterBarSettings } from './filters.ts';
import styles from './inbox.module.css';
import { clearFiltersInQueryParams, getFiltersFromQueryParams, getSortingOrderFromQueryParams } from './queryParams.ts';
import { clearFiltersInQueryParams, getFiltersFromQueryParams } from './queryParams.ts';

interface InboxProps {
viewType: InboxViewType;
Expand Down Expand Up @@ -69,30 +67,19 @@ interface DialogCategory {
items: InboxItemInput[];
}

const sortDialogs = (dialogs: InboxItemInput[], sortOrder: SortingOrder): InboxItemInput[] => {
return dialogs.sort((a, b) => {
if (sortOrder === 'updated_desc') {
return new Date(b.updatedAt).getTime() - new Date(a.updatedAt).getTime();
}
return new Date(a.updatedAt).getTime() - new Date(b.updatedAt).getTime();
});
};

export const Inbox = ({ viewType }: InboxProps) => {
const format = useFormat();
const filterBarRef = useRef<FilterBarRef>(null);
const sortOrderDropdownRef = useRef<SortOrderDropdownRef>(null);
const queryClient = useQueryClient();

const disableBulkActions = useFeatureFlag<boolean>(FeatureFlagKeys.DisableBulkActions);

const location = useLocation();
const { t } = useTranslation();
const [searchParams, setSearchParams] = useSearchParams();
const [searchParams] = useSearchParams();
const { selectedItems, setSelectedItems, selectedItemCount, inSelectionMode } = useSelectedDialogs();
const { openSnackbar } = useSnackbar();
const [isSavingSearch, setIsSavingSearch] = useState<boolean>(false);
const [selectedSortOrder, setSelectedSortOrder] = useState<SortingOrder>('updated_desc');

const { selectedParties } = useParties();
const { searchString } = useSearchString();
Expand All @@ -112,8 +99,8 @@ export const Inbox = ({ viewType }: InboxProps) => {

// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed
const itemsToDisplay = useMemo(() => {
return sortDialogs(filterDialogs(dataSource, activeFilters, format), selectedSortOrder);
}, [dataSource, activeFilters, selectedSortOrder]);
return filterDialogs(dataSource, activeFilters, format);
}, [dataSource, activeFilters]);

// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed
useEffect(() => {
Expand All @@ -125,19 +112,8 @@ export const Inbox = ({ viewType }: InboxProps) => {
// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed
useEffect(() => {
setInitialFilters(getFiltersFromQueryParams(searchParams));
const sortBy = getSortingOrderFromQueryParams(searchParams);
if (sortBy && sortBy !== selectedSortOrder) {
setSelectedSortOrder(getSortingOrderFromQueryParams(searchParams));
}
}, [location.pathname]);

// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed
useEffect(() => {
const newSearchParams = new URLSearchParams(searchParams);
newSearchParams.set('sortBy', selectedSortOrder);
setSearchParams(newSearchParams, { replace: true });
}, [selectedSortOrder]);

const shouldShowSearchResults = !isFetchingSearchResults && showingSearchResults;

// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed
Expand Down Expand Up @@ -283,14 +259,6 @@ export const Inbox = ({ viewType }: InboxProps) => {
activeFilters={activeFilters}
/>
</div>
<div className={styles.sortOrderContainer}>
<SortOrderDropdown
ref={sortOrderDropdownRef}
onSelect={setSelectedSortOrder}
selectedSortOrder={selectedSortOrder}
btnClassName={styles.hideForSmallScreens}
/>
</div>
</div>
<FosToolbar
onFilterBtnClick={
Expand All @@ -300,9 +268,6 @@ export const Inbox = ({ viewType }: InboxProps) => {
}
: undefined
}
onSortBtnClick={() => {
sortOrderDropdownRef?.current?.openSortOrder();
}}
onSaveBtnClick={handleSaveSearch}
hideSaveButton={savedSearchDisabled}
/>
Expand Down
5 changes: 0 additions & 5 deletions packages/frontend/src/pages/Inbox/queryParams.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { Filter } from '../../components';
import type { SortingOrder } from '../../components/SortOrderDropdown/SortOrderDropdown.tsx';

export const getFiltersFromQueryParams = (searchParams: URLSearchParams): Filter[] => {
const compressedData = searchParams.get('filters');
Expand All @@ -12,10 +11,6 @@ export const clearFiltersInQueryParams = (): void => {
window.history.replaceState({}, '', `${window.location.pathname}?${searchParams}`);
};

export const getSortingOrderFromQueryParams = (searchParams: URLSearchParams): SortingOrder => {
return searchParams.get('sortBy') as SortingOrder;
};

export const getSearchStringFromQueryParams = (searchParams: URLSearchParams): string => {
return searchParams.get('search') || '';
};
Expand Down

This file was deleted.

0 comments on commit bbb66cc

Please sign in to comment.