Skip to content

LF-4672 (1) - Rtk upgrade/locations rebase#4083

Open
Duncan-Brain wants to merge 84 commits intointegrationfrom
rtk-upgrade/locations-rebase
Open

LF-4672 (1) - Rtk upgrade/locations rebase#4083
Duncan-Brain wants to merge 84 commits intointegrationfrom
rtk-upgrade/locations-rebase

Conversation

@Duncan-Brain
Copy link
Collaborator

@Duncan-Brain Duncan-Brain commented Mar 12, 2026

Description

This is phase 1 of 3 of locations migration away from sagas to rtk-query.

Major changes:

  • creates endpoints in api for location to eventually replace all location sagas
  • migrates most selectors to hooks from locationSlice
  • removes selector stubs for sensors
  • only render map if assets are ready -- add temporary loading screen for maps as it can take some time (Part 2 follows figma design) (sensors was broken so in order to test changes I needed this)
  • removed as many references as possible to location type selectors (eg. barnSelector) without refactoring the location type containers and selectors details Part 3 will consolidate all those individual area selectors

Review Notes:

  • Looks scarier than it is: File changes are broad because they are core selectors but lines of code changes is limited to only a few files
  • Check that selectors all have a hook or that selector was unused
    • useLocation hook is core hook - update and add endpoints currently unused until part 3
    • useExternalLocations hook mirrors the locations hook very closely but does not need cleaning or flattening
    • all other hooks use the base hooks fairly simply
    • useAvailableFilterSetting is only used in /Map so that is why it is not top level
  • Types are a lot of code but I think up to you if you want to understand it
    • essentially has to mirror our backend get construct which is annoying format
  • New selector stubs made to satisfy management plan and task selectors that need that access until we migrate those parts of the app

Other notes

  • pre-existing bugs:
    • Flash of just farm centre before assets load on farm with external sensors
    • zoom does not work on taskLocations very well, farm center is always included so cross country locations dont behave as expected.
    • flicker on locationPicker
    • blinkiness, flashing of 'points' when selecting a menu item or filtering
  • backend sends us very messy data (eg location: { type: barn, barn: {...}, greenhouse: null, area: {...}, line: null ..})
  • should be able to remove refetch of sensors on /Home isFetching blocker prevents case where data does not exist -- also it didn't work for me on integration.

Jira link: LF-4672

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Passes test case
  • UI components visually reviewed on desktop view
  • UI components visually reviewed on mobile view
  • Other (please explain)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • The precommit and linting ran successfully
  • I have added or updated language tags for text that's part of the UI
  • I have ordered translation keys alphabetically (optional: run pnpm i18n to help with this)
  • I have added the GNU General Public License to all new files

@Duncan-Brain Duncan-Brain changed the title Rtk upgrade/locations rebase LF-4672 - Rtk upgrade/locations rebase Mar 12, 2026
filterSettings,
onFilterMenuClick,
onAddMenuClick,
availableFilterSettings = {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was a duplicated part of a selector migration, also locationEnum should be phased out for typescript versions.

icon: () => <Sensor style={{ transform: 'translate(-5px, 5px)' }} />,
key: locationEnum.sensor,
},
{
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Part of the sensors vs sensor array being filtered separately discussion with Loic.

}),
}));

export default function LoadingMapModal({ isOpen }: { isOpen: boolean }) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This temporary component will be deleted with part 2 where I implement Loic's loading design.

)
</>
)}
{isLocationsFetching && <LoadingMapModal isOpen={isLocationsFetching} />}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The desired behaviour for me is that this should be isLocationsLoading - block render if current data does not exist. And then isLocationsFetching is used to refresh/redraw the data if it changes.

There is a variety of rendering issues with this component that make this hard to implement right now. The old way the selector updates were instantaneous and now we wait for a round trip back from invalidating tags.

I tried a method similar to the method recently removed when redraw was needed here: 9944bf8 As noted in that PR we will need something like that again when we start adding locations in the new add location redesign. But this is a good compromise until that time.

There is a too many re-rendering problem with this component and I think if we can solve that in the future this component will look much simpler. But lets also wait until we update our drawing library.

export const barnSelector = (location_id) =>
createSelector(barnEntitiesSelector, (entities) => entities[location_id]);

export const barnStatusSelector = createSelector(
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These are unused

@Duncan-Brain Duncan-Brain changed the title LF-4672 - Rtk upgrade/locations rebase LF-4672 (1) - Rtk upgrade/locations rebase Mar 13, 2026
@Duncan-Brain Duncan-Brain marked this pull request as ready for review March 13, 2026 16:52
@Duncan-Brain Duncan-Brain requested review from a team as code owners March 13, 2026 16:52
@Duncan-Brain Duncan-Brain requested review from kathyavini and removed request for a team March 13, 2026 16:52
@Duncan-Brain Duncan-Brain self-assigned this Mar 13, 2026
@Duncan-Brain Duncan-Brain requested a review from SayakaOno March 13, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant