-
Notifications
You must be signed in to change notification settings - Fork 24
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
PSP-5951 refactor left hand file navigation - Acquisition ONLY #3288
Merged
Merged
Changes from 13 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
310cedc
Update useQuery global hook
asanchezr 08469d3
Update shared tabbed forms
asanchezr 2cd481c
Refactor property tabs to work with state OR routing
asanchezr dd8892a
Refactor acquisition left hand navigation to use routing
asanchezr 2d4ecb4
Remove setContainerState callback from acquisition forms
asanchezr aeabddd
Test corrections
asanchezr 7884923
Improve tab names for properties
asanchezr 004d3ff
Set header title based on current tab route
asanchezr f1d152e
Fix routing issue with requisition compensations
asanchezr 399e362
Update snapshots
asanchezr 6bcd184
Fix failing tests
asanchezr 2eeb023
Merge branch 'dev' into psp-5951-sidebar-routing
asanchezr ea9ec62
Merge branch 'dev' into psp-5951-sidebar-routing
asanchezr 6b37f94
Merge branch 'dev' into psp-5951-sidebar-routing
asanchezr 7d1d4bf
Fix bug when removing property from File
asanchezr c1e5b91
Add tests for routing in Acquisition View
asanchezr 812b0a6
Redirect to default tabs when editing and path doesn't match
asanchezr dde59f2
Merge remote-tracking branch 'upstream/dev' into psp-5951-sidebar-rou…
asanchezr 72e9b67
Test corrections
asanchezr a91a303
Fix dereference error when accessing non-existing property index
asanchezr 0c4329b
Remove unused code
asanchezr 6379a18
Move router components to router folder
asanchezr 0b215ec
Test corrections
asanchezr 9582015
Merge remote-tracking branch 'upstream/dev' into psp-5951-sidebar-rou…
asanchezr 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 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 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 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
98 changes: 98 additions & 0 deletions
98
source/frontend/src/features/mapSideBar/acquisition/AcquisitionRouter.tsx
This file contains 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,98 @@ | ||
import { FormikProps } from 'formik'; | ||
import React from 'react'; | ||
import { Redirect, Route, Switch, useRouteMatch } from 'react-router-dom'; | ||
|
||
import { InventoryTabNames } from '@/features/mapSideBar/property/InventoryTabs'; | ||
import { FileTabType } from '@/features/mapSideBar/shared/detail/FileTabs'; | ||
import { Api_AcquisitionFile } from '@/models/api/AcquisitionFile'; | ||
import { stripTrailingSlash } from '@/utils'; | ||
|
||
import { EditFormType } from './EditFormNames'; | ||
import { AcquisitionFileTabs } from './tabs/AcquisitionFileTabs'; | ||
import { UpdateAgreementsContainer } from './tabs/agreement/update/UpdateAgreementsContainer'; | ||
import { UpdateAgreementsForm } from './tabs/agreement/update/UpdateAgreementsForm'; | ||
import { UpdateAcquisitionChecklistContainer } from './tabs/checklist/update/UpdateAcquisitionChecklistContainer'; | ||
import { UpdateAcquisitionChecklistForm } from './tabs/checklist/update/UpdateAcquisitionChecklistForm'; | ||
import { UpdateAcquisitionContainer } from './tabs/fileDetails/update/UpdateAcquisitionContainer'; | ||
import { UpdateAcquisitionForm } from './tabs/fileDetails/update/UpdateAcquisitionForm'; | ||
import { UpdateStakeHolderContainer } from './tabs/stakeholders/update/UpdateStakeHolderContainer'; | ||
import { UpdateStakeHolderForm } from './tabs/stakeholders/update/UpdateStakeHolderForm'; | ||
|
||
export interface IAcquisitionRouterProps { | ||
formikRef: React.Ref<FormikProps<any>>; | ||
acquisitionFile?: Api_AcquisitionFile; | ||
isEditing: boolean; | ||
setIsEditing: (value: boolean) => void; | ||
activeEditForm?: EditFormType; | ||
defaultFileTab: FileTabType; | ||
defaultPropertyTab: InventoryTabNames; | ||
onSuccess: () => void; | ||
} | ||
|
||
export const AcquisitionRouter: React.FC<IAcquisitionRouterProps> = props => { | ||
const { path, url } = useRouteMatch(); | ||
|
||
if (props.acquisitionFile === undefined || props.acquisitionFile === null) { | ||
return null; | ||
} | ||
|
||
// render edit forms | ||
if (props.isEditing) { | ||
return ( | ||
<Switch> | ||
<Route exact path={`${stripTrailingSlash(path)}/${FileTabType.FILE_DETAILS}`}> | ||
<UpdateAcquisitionContainer | ||
ref={props.formikRef} | ||
acquisitionFile={props.acquisitionFile} | ||
onSuccess={props.onSuccess} | ||
View={UpdateAcquisitionForm} | ||
/> | ||
</Route> | ||
<Route exact path={`${stripTrailingSlash(path)}/${FileTabType.CHECKLIST}`}> | ||
<UpdateAcquisitionChecklistContainer | ||
formikRef={props.formikRef} | ||
acquisitionFile={props.acquisitionFile} | ||
onSuccess={props.onSuccess} | ||
View={UpdateAcquisitionChecklistForm} | ||
/> | ||
</Route> | ||
<Route exact path={`${stripTrailingSlash(path)}/${FileTabType.AGREEMENTS}`}> | ||
<UpdateAgreementsContainer | ||
acquisitionFileId={props.acquisitionFile.id || -1} | ||
View={UpdateAgreementsForm} | ||
formikRef={props.formikRef} | ||
onSuccess={() => props.setIsEditing(false)} | ||
/> | ||
</Route> | ||
<Route exact path={`${stripTrailingSlash(path)}/${FileTabType.STAKEHOLDERS}`}> | ||
<UpdateStakeHolderContainer | ||
View={UpdateStakeHolderForm} | ||
formikRef={props.formikRef} | ||
acquisitionFile={props.acquisitionFile} | ||
onSuccess={() => props.setIsEditing(false)} | ||
/> | ||
</Route> | ||
</Switch> | ||
); | ||
} else { | ||
// render read-only views | ||
return ( | ||
<Switch> | ||
{/* Ignore property-related routes (which are handled in separate FilePropertyRouter) */} | ||
<Route path={`${stripTrailingSlash(path)}/property`}> | ||
<></> | ||
</Route> | ||
<Route path={`${stripTrailingSlash(path)}/:tab`}> | ||
<AcquisitionFileTabs | ||
acquisitionFile={props.acquisitionFile} | ||
defaultTab={props.defaultFileTab} | ||
setIsEditing={props.setIsEditing} | ||
/> | ||
</Route> | ||
<Redirect from={`${path}`} to={`${stripTrailingSlash(url)}/${FileTabType.FILE_DETAILS}`} /> | ||
</Switch> | ||
); | ||
} | ||
}; | ||
|
||
export default AcquisitionRouter; |
This file contains 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what should we do if we are editing and our path doesn't match one of these? currently we display an empty edit screen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The old code in ViewSelector throws an error -
throw Error('Active edit form not defined');
I can create a default route that does the same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. We redirect to the default File tab (file details)