Skip to content

ERA-11239: track styles: patrol tracks (2) #1251

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
merged 2 commits into from
Mar 6, 2025
Merged

ERA-11239: track styles: patrol tracks (2) #1251

merged 2 commits into from
Mar 6, 2025

Conversation

luixlive
Copy link
Contributor

@luixlive luixlive commented Mar 6, 2025

What does this PR do?

During QA process, @AlanCalvillo found out the following issues that are fixed here:

  • Bug in patrol filters (it wasn't working at all)
  • Patrol titles in the track legend should be prefixed by "Patro: " to make then distinguishable from subject tracks
  • There wasn't any gap between the new patrol legends and the heatmap legends

Relevant link(s)

ERA-11239

Where / how to start reviewing (optional)

See the comments added in each file explaining the fix to the listed issues.

@@ -1,7 +1,7 @@
{
"patrolTrackLegend": {
"icon": "Icon for {{title}}",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two updates in the translations file:

  • Simplify the item description since it was taking too much space unnecessarily
  • Add the "Patrol: " prefix to the item title
    image

@@ -12,6 +12,7 @@
flex-wrap: wrap;
height: var(--legend-height);
line-height: normal;
margin-bottom: 0.5rem;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add gap between the heatmap legend and the patrol track legend:
image

@@ -33,7 +34,7 @@ const PatrolFilter = ({ className }) => {
const containerRef = useRef(null);
const { t } = useTranslation('filters', { keyPrefix: 'patrolFilters' });
const dispatch = useDispatch();
const patrolStore = useSelector((state) => state.data.patrolStore);
const patrolsFeedMappedFromStore = useSelector(selectPatrolsFeedMappedFromStore);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new selector that gets the response of the latest patrol feed request with the filtering params, and maps them to their patrol store objects, filtering the ones that are not defined, to calculate the total feed count:
image

length: `${patrolData.trackData ? length(patrolData.trackData.track).toFixed(2): 0.00}km`,
}),
icon: <DasIcon className={styles.itemIcon} iconId={iconId} title={t('icon', { title })} type="events" />,
description: `${patrolData.trackData ? length(patrolData.trackData.track).toFixed(2): 0.00}km`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new translation for the item title and remove the unnecessary translation for the description, leave just the distance.


const onItemClick = useCallback((id) => navigate(id), [navigate]);
const patrolsFeedMappedFromStore = useSelector(selectPatrolsFeedMappedFromStore);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, use the new selector to get the array of patrol objects that should be rendered in the patrol feed. These consider the latest response from the patrols feed request using the configured filters:
image

import cloneDeep from 'lodash/cloneDeep';
import { useDispatch, useSelector } from 'react-redux';

import { fetchPatrols } from '../../ducks/patrols';
import { fetchPatrolsFeed } from '../../ducks/patrols';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only logical change in this file is rename the old fetchPatrols to fetchPatrolsFeed (more explicit) but I did a bit of refactoring to clean an unnecessay useCallback.

@@ -313,3 +274,49 @@ export const patrolTracksReducer = (state = INITIAL_PATROL_TRACKS_STATE, { type,

return state;
};

// Actions
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename and refactor the fetchPatrols method, now called fetchPatrolsFeed, and add back the reducer I removed (original cause of the feed issue) but in a cleaner way. Not storing the whole Axios response, but just the mapped ids of the patrols.

@@ -68,6 +68,7 @@ const rootReducer = combineReducers({
data: combineReducers({
baseLayers: baseLayersReducer,
eventStore: eventStoreReducer,
patrolsFeed: patrolsFeedReducer,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add back the clean version of the patrols reducer, now called patrolsFeed which is more explicit. Remember that the patrolStore reducer will have many patrols, but they don't correspond to the applied filters. This reducer contains the latest response of the patrols feed request, storing an array of the ids of the patrols that should be rendered in the feed. Those ids need to be resolved using the patrolStore.

@@ -111,6 +112,12 @@ export const selectPatrolLeadersWithLastPosition = createSelector(
}) : null
);

export const selectPatrolsFeedMappedFromStore = createSelector(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new selector that maps the patrols feed stored in the new reducer to their patrol objects in the patrol store.

Copy link
Collaborator

@JoshuaVulcan JoshuaVulcan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, nice turnaround time

@JoshuaVulcan JoshuaVulcan merged commit eea0f89 into develop Mar 6, 2025
5 checks passed
@JoshuaVulcan JoshuaVulcan deleted the ERA-11239 branch March 6, 2025 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants