-
Notifications
You must be signed in to change notification settings - Fork 6
4756 - AreaSelector: Allow sorting #5671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mergify
merged 8 commits into
4756-toolbar-area-selector---add-status-filter-updated-sorting
from
4756-sorting
Jan 28, 2026
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8a53cd8
5057 - Introduce component SortableHeader
sorja 382b0bb
5057 - AreaSelect/Group: use SortableHeaders and separate headers to…
sorja 48ed7c2
5057 - AreaSelect: Support sorting
sorja 6b43ad6
5057 - Limit feature by roles
sorja 123e9dd
5057 - Group ordering by role
sorja ec34d44
5057 - Update icon color
sorja 9fa6839
5057 - use isAReviewer and introduce isARegionalFocalPoint
sorja da29bf0
5057 - AreaSelect: Increase width only when sorting is available
sorja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -8,12 +8,16 @@ import { UserRoles } from 'meta/user/roles' | |
| import { Users } from 'meta/user/users' | ||
|
|
||
| import { useAppDispatch } from 'client/store/hooks' | ||
| import { useCycle } from 'client/store/meta/hooks/cycles' | ||
| import { AreaSelectorActions } from 'client/store/ui/areaSelector/actions' | ||
| import { useIsAreaSelectorExpanded } from 'client/store/ui/areaSelector/hooks/areaSelector' | ||
| import { useUser } from 'client/store/user/hooks/user' | ||
| import { useCountryRouteParams } from 'client/hooks/routeParams' | ||
| import Button from 'client/components/Buttons/Button' | ||
| import { Option } from 'client/components/Inputs/Select' | ||
| import CountryListDownload from 'client/components/PageLayout/Toolbar/AreaSelect/Group/CountryListDownload' | ||
| import { useHeaders } from 'client/components/PageLayout/Toolbar/AreaSelect/Group/hooks/useHeaders' | ||
| import SortableHeader from 'client/components/PageLayout/Toolbar/AreaSelect/Group/SortableHeader' | ||
| import { OptionsGroupArea } from 'client/components/PageLayout/Toolbar/AreaSelect/types' | ||
|
|
||
| type Props = GroupProps<Option, boolean, OptionsGroupArea> | ||
|
|
@@ -22,11 +26,18 @@ const Group: React.FC<Props> = (props) => { | |
| const { data } = props | ||
|
|
||
| const { t } = useTranslation() | ||
| const user = useUser() | ||
| const dispatch = useAppDispatch() | ||
| const { countryIso } = useCountryRouteParams() | ||
| const cycle = useCycle() | ||
| const user = useUser() | ||
| const expanded = useIsAreaSelectorExpanded() | ||
| const headers = useHeaders() | ||
|
|
||
| const isAdmin = Users.isAdministrator(user) | ||
| const isRegionalFocalPoint = Users.isRegionalFocalPoint(user, countryIso, cycle) | ||
| const isReviewer = Users.isReviewer(user, countryIso, cycle) | ||
|
||
| // only allow sorting when we have more than one country and user has specific role | ||
| const sortable = data.options.length > 1 && (isAdmin || isRegionalFocalPoint || isReviewer) | ||
|
|
||
| return ( | ||
| <> | ||
|
|
@@ -44,15 +55,18 @@ const Group: React.FC<Props> = (props) => { | |
| <div>{t(Users.getI18nRoleLabelKey(data.roleName))}</div> | ||
| <div>{t('common.status')}</div> | ||
|
|
||
| {expanded && ( | ||
| <> | ||
| <div>{t('audit.edited')}</div> | ||
| <div>{t('common.submittedToReview')}</div> | ||
| <div>{t('common.submittedForApproval')}</div> | ||
| <div>{t('common.accepted')}</div> | ||
| </> | ||
| {headers.map((header) => | ||
| sortable ? ( | ||
| <SortableHeader | ||
| key={header.sortBy} | ||
| label={header.label} | ||
| roleName={data.roleName} | ||
| sortByProperty={header.sortBy} | ||
| /> | ||
| ) : ( | ||
| <div key={header.sortBy}>{header.label}</div> | ||
| ) | ||
| )} | ||
| {!expanded && <div>{t('common.updated')}</div>} | ||
|
|
||
| {isAdmin && ( | ||
| <Button | ||
|
|
||
21 changes: 21 additions & 0 deletions
21
src/client/components/PageLayout/Toolbar/AreaSelect/Group/SortableHeader/SortableHeader.scss
This file contains hidden or 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,21 @@ | ||
| @use 'src/client/style/partials' as *; | ||
|
|
||
| .area-select__group-heading-sortable { | ||
| all: unset; // reset all button defaults to inherit or initial | ||
| align-items: start; | ||
| cursor: pointer; | ||
| display: flex; | ||
|
|
||
| svg { | ||
| color: $text-link; | ||
| margin-right: $spacing-xxxxs; | ||
| } | ||
|
|
||
| &:hover { | ||
| color: $text-body; | ||
| } | ||
|
|
||
| &.active svg { | ||
| color: $ui-accent; | ||
| } | ||
| } |
42 changes: 42 additions & 0 deletions
42
src/client/components/PageLayout/Toolbar/AreaSelect/Group/SortableHeader/SortableHeader.tsx
This file contains hidden or 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,42 @@ | ||
| import './SortableHeader.scss' | ||
| import React, { useCallback } from 'react' | ||
| import classNames from 'classnames' | ||
|
|
||
| import { RoleName } from 'meta/user/role/name' | ||
|
|
||
| import { useAppDispatch } from 'client/store/hooks' | ||
| import { AreaSelectorActions } from 'client/store/ui/areaSelector/actions' | ||
| import { useAreaSelectorFilters } from 'client/store/ui/areaSelector/hooks/areaSelector' | ||
| import { AreaSelectorSortBy, AreaSelectorSortDirection } from 'client/store/ui/areaSelector/state' | ||
| import Icon from 'client/components/Icon' | ||
|
|
||
| type Props = { | ||
| label: string | ||
| roleName: RoleName | ||
| sortByProperty: AreaSelectorSortBy | ||
| } | ||
|
|
||
| const SortableHeader: React.FC<Props> = (props) => { | ||
| const { label, roleName, sortByProperty } = props | ||
|
|
||
| const dispatch = useAppDispatch() | ||
| const { orderBy } = useAreaSelectorFilters() | ||
|
|
||
| const current = orderBy[roleName] | ||
| const active = current?.sortBy === sortByProperty | ||
| const iconName = | ||
| active && current?.sortDirection === AreaSelectorSortDirection.asc ? 'sort-amount-asc' : 'sort-amount-desc' | ||
|
|
||
| const onClick = useCallback(() => { | ||
| dispatch(AreaSelectorActions.setSortBy({ roleName, sortBy: sortByProperty })) | ||
| }, [dispatch, roleName, sortByProperty]) | ||
|
|
||
| return ( | ||
| <button className={classNames('area-select__group-heading-sortable', { active })} onClick={onClick} type="button"> | ||
| <Icon name={iconName} /> | ||
| {label} | ||
| </button> | ||
| ) | ||
| } | ||
|
|
||
| export default SortableHeader |
1 change: 1 addition & 0 deletions
1
src/client/components/PageLayout/Toolbar/AreaSelect/Group/SortableHeader/index.ts
This file contains hidden or 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 @@ | ||
| export { default } from './SortableHeader' |
24 changes: 24 additions & 0 deletions
24
src/client/components/PageLayout/Toolbar/AreaSelect/Group/hooks/useHeaders.ts
This file contains hidden or 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,24 @@ | ||
| import { useMemo } from 'react' | ||
| import { useTranslation } from 'react-i18next' | ||
|
|
||
| import { useIsAreaSelectorExpanded } from 'client/store/ui/areaSelector/hooks/areaSelector' | ||
| import { AreaSelectorSortBy } from 'client/store/ui/areaSelector/state' | ||
|
|
||
| export type HeaderConfig = { label: string; sortBy: AreaSelectorSortBy } | ||
|
|
||
| export const useHeaders = (): Array<HeaderConfig> => { | ||
| const { t } = useTranslation() | ||
| const expanded = useIsAreaSelectorExpanded() | ||
|
|
||
| return useMemo<Array<HeaderConfig>>(() => { | ||
| if (expanded) { | ||
| return [ | ||
| { label: t('audit.edited'), sortBy: 'lastEdit' }, | ||
| { label: t('common.submittedToReview'), sortBy: 'lastInReview' }, | ||
| { label: t('common.submittedForApproval'), sortBy: 'lastInApproval' }, | ||
| { label: t('common.accepted'), sortBy: 'lastInAccepted' }, | ||
| ] | ||
| } | ||
| return [{ label: t('common.updated'), sortBy: 'lastUpdate' }] | ||
| }, [expanded, t]) | ||
| } |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,4 +1,7 @@ | ||
| import { useAppSelector } from 'client/store/hooks' | ||
| import { AreaSelectorSelectors } from 'client/store/ui/areaSelector/selectors' | ||
| import { AreaSelectorFilters } from 'client/store/ui/areaSelector/state' | ||
|
|
||
| export const useIsAreaSelectorExpanded = (): boolean => useAppSelector(AreaSelectorSelectors.isExpanded) | ||
|
|
||
| export const useAreaSelectorFilters = (): AreaSelectorFilters => useAppSelector(AreaSelectorSelectors.getFilters) |
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,15 +1,37 @@ | ||
| import { createSlice } from '@reduxjs/toolkit' | ||
| import { createSlice, PayloadAction } from '@reduxjs/toolkit' | ||
|
|
||
| import { AreaSelectorMode, initialState } from 'client/store/ui/areaSelector/state' | ||
| import { | ||
| AreaSelectorMode, | ||
| AreaSelectorSortBy, | ||
| AreaSelectorSortDirection, | ||
| initialState, | ||
| } from 'client/store/ui/areaSelector/state' | ||
|
|
||
| import { AreaSelectorSliceName } from './name' | ||
|
|
||
| type SetSortByPayload = { | ||
| roleName: string | ||
| sortBy: AreaSelectorSortBy | ||
| } | ||
|
|
||
| export const AreaSelectorSlice = createSlice({ | ||
| name: AreaSelectorSliceName, | ||
| initialState, | ||
| reducers: { | ||
| toggleMode: (state) => { | ||
| state.mode = state.mode === AreaSelectorMode.collapsed ? AreaSelectorMode.expanded : AreaSelectorMode.collapsed | ||
| }, | ||
| setSortBy: (state, action: PayloadAction<SetSortByPayload>) => { | ||
| const { roleName, sortBy: property } = action.payload | ||
| const current = state.filters.orderBy[roleName] | ||
|
|
||
| if (current?.sortBy !== property) { | ||
| state.filters.orderBy[roleName] = { sortBy: property, sortDirection: AreaSelectorSortDirection.desc } | ||
| } else if (current.sortDirection === AreaSelectorSortDirection.desc) { | ||
| state.filters.orderBy[roleName] = { sortBy: property, sortDirection: AreaSelectorSortDirection.asc } | ||
| } else { | ||
| delete state.filters.orderBy[roleName] | ||
| } | ||
| }, | ||
| }, | ||
| }) |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.