-
Notifications
You must be signed in to change notification settings - Fork 4k
Resolve optimistic agent edit route after creation #96473
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
Open
nabi-ebrahimi
wants to merge
37
commits into
Expensify:main
Choose a base branch
from
nabi-ebrahimi:fix/disable-pending-agent-edit-navigation
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
4c1d660
fix: disable edit navigation for pending agents
nabi-ebrahimi de3562d
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi cfeff19
Fix optimistic agent edit page lookup
nabi-ebrahimi 94d3e01
Classify optimistic agent mapping for export
nabi-ebrahimi f456a43
Use RAM-only agent ID mapping
nabi-ebrahimi 7b96d52
classify agent mapping for export
nabi-ebrahimi e5dcc93
test: Cover agent mapping fallback
nabi-ebrahimi 7fb2d59
test: Cover agent mapping selector
nabi-ebrahimi 143a525
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi 44db2e4
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi f598f4f
Fix optimistic agent route param
nabi-ebrahimi c16e191
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi 2ecdbbf
Refine agent ID mapping selector
nabi-ebrahimi a5c0e4a
Refine agent ID mapping selector
nabi-ebrahimi f882573
Target agent route param update
nabi-ebrahimi 232dfb6
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi e41cc75
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi 2268ca2
Fix agent edit navigation for optimistic accountIDs
nabi-ebrahimi d900c68
Resolve optimistic agent accountID via persisted mapping
nabi-ebrahimi 0e19104
fix: lint
nabi-ebrahimi 09bfdee
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi 75fac6e
Fix agent navigation accountID inconsistency
nabi-ebrahimi 5b1fc9a
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi cf36124
Remove stale entries from optimisticAgentAccountIDMapping
nabi-ebrahimi 2a6549c
Add unit tests for agent mapping resolution and pruning
nabi-ebrahimi 8a45f67
Fix lint errors in agent mapping tests
nabi-ebrahimi 2ee26d7
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi aad8450
Add blank line before comments
nabi-ebrahimi 15b55eb
Clean up mapping from ProfilePage too
nabi-ebrahimi 185142f
Backfill missing mapping timestamps
nabi-ebrahimi 9d3e196
Combine agent mapping into a derived value
nabi-ebrahimi 412c328
Use OnyxUtils.get instead of connectWithoutView in test
nabi-ebrahimi c38518c
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi 0ecee43
Merge branch 'main' into fix/disable-pending-agent-edit-navigation
nabi-ebrahimi d4a61f6
Trim comment
nabi-ebrahimi a057933
split max-age constant into days
nabi-ebrahimi e7b9193
Read agent mapping via connectWithoutView, fix resolve race
nabi-ebrahimi 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 |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import {backfillOptimisticAccountIDMappingCreatedAt} from '@libs/actions/Agent'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import {useEffect} from 'react'; | ||
|
|
||
| import useOnyx from './useOnyx'; | ||
|
|
||
| /** | ||
| * Resolves an agent's optimistic accountID to the real one CreateAgent assigns, via the persisted | ||
| * `OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING`, so an agent screen opened on the optimistic accountID (even after a reload) | ||
| * shows the real agent instead of "Hmm... it's not here". | ||
| * | ||
| * The derived `OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING_ENTRIES` defers its first compute until all its dependency | ||
| * connections are established, which can briefly lag behind the raw key on a cold cache — long enough to flash a | ||
| * not-found page in between. It's still used for `createdAt` below, which has no such timing sensitivity. | ||
| * | ||
| * Without a stamped `createdAt`, an entry is invisible to createAgent()'s pruning and never expires — this can | ||
| * happen when the mapping arrives via sync from another device/tab that resolved it first. | ||
| * | ||
| * @returns `[resolvedAccountID, isMappingLoaded]` - a not-found screen should wait for `isMappingLoaded` to avoid a | ||
| * brief not-found flash while the mapping loads. No-op (returns the input) when there's no mapping entry. | ||
| */ | ||
|
nabi-ebrahimi marked this conversation as resolved.
|
||
| function useResolvedAgentAccountID(routeAccountID: number): [number, boolean] { | ||
| const [realAccountID, mappingMetadata] = useOnyx(ONYXKEYS.OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING, {selector: (mapping) => mapping?.[routeAccountID]}); | ||
| const [createdAt, createdAtMetadata] = useOnyx(ONYXKEYS.DERIVED.OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING_ENTRIES, {selector: (entries) => entries?.[routeAccountID]?.createdAt}); | ||
|
|
||
| useEffect(() => { | ||
| if (realAccountID === undefined || createdAt !== undefined || createdAtMetadata.status !== 'loaded') { | ||
| return; | ||
| } | ||
| backfillOptimisticAccountIDMappingCreatedAt(routeAccountID); | ||
| }, [realAccountID, createdAt, createdAtMetadata.status, routeAccountID]); | ||
|
|
||
| return [realAccountID ?? routeAccountID, mappingMetadata.status === 'loaded']; | ||
| } | ||
|
|
||
| export default useResolvedAgentAccountID; | ||
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
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
28 changes: 28 additions & 0 deletions
28
src/libs/actions/OnyxDerived/configs/optimisticAgentAccountIDMappingEntries.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,28 @@ | ||
| import createOnyxDerivedValueConfig from '@userActions/OnyxDerived/createOnyxDerivedValueConfig'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type {OptimisticAgentAccountIDMappingEntriesDerivedValue} from '@src/types/onyx'; | ||
|
|
||
| /** | ||
| * Combines OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING (backend-owned) and OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING_CREATED_AT | ||
| * (client-owned) into one key per optimistic accountID, so consumers read a single always-in-sync source instead | ||
| * of two parallel keys that would otherwise have to be kept manually in lockstep. | ||
| */ | ||
| export default createOnyxDerivedValueConfig({ | ||
| key: ONYXKEYS.DERIVED.OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING_ENTRIES, | ||
| dependencies: [ONYXKEYS.OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING, ONYXKEYS.OPTIMISTIC_AGENT_ACCOUNT_ID_MAPPING_CREATED_AT], | ||
| compute: ([mapping, createdAtByOptimisticAccountID]) => { | ||
| if (!mapping) { | ||
| return {}; | ||
| } | ||
|
|
||
| const entries: OptimisticAgentAccountIDMappingEntriesDerivedValue = {}; | ||
| for (const [optimisticAccountID, realAccountID] of Object.entries(mapping)) { | ||
| if (realAccountID === undefined) { | ||
| continue; | ||
| } | ||
| entries[optimisticAccountID] = {realAccountID, createdAt: createdAtByOptimisticAccountID?.[optimisticAccountID]}; | ||
| } | ||
| return entries; | ||
| }, | ||
| }); |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.