-
Notifications
You must be signed in to change notification settings - Fork 4k
[TS migration] Migrate 'ReportAttachments' page to TypeScript #33840
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
Changes from all commits
a250834
68635ca
0307a5f
2037137
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,43 +1,47 @@ | ||
| import PropTypes from 'prop-types'; | ||
| import type {StackScreenProps} from '@react-navigation/stack'; | ||
| import React, {useCallback} from 'react'; | ||
| import _ from 'underscore'; | ||
| import AttachmentModal from '@components/AttachmentModal'; | ||
| import ComposerFocusManager from '@libs/ComposerFocusManager'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {AuthScreensParamList} from '@libs/Navigation/types'; | ||
| import * as ReportUtils from '@libs/ReportUtils'; | ||
| import ROUTES from '@src/ROUTES'; | ||
| import type SCREENS from '@src/SCREENS'; | ||
|
|
||
| const propTypes = { | ||
| /** Navigation route context info provided by react navigation */ | ||
| route: PropTypes.shape({ | ||
| /** Route specific parameters used on this screen */ | ||
| params: PropTypes.shape({ | ||
| /** The report ID which the attachment is associated with */ | ||
| reportID: PropTypes.string.isRequired, | ||
| /** The uri encoded source of the attachment */ | ||
| source: PropTypes.string.isRequired, | ||
| }).isRequired, | ||
| }).isRequired, | ||
| type File = { | ||
| name: string; | ||
| }; | ||
|
|
||
| function ReportAttachments(props) { | ||
| const reportID = _.get(props, ['route', 'params', 'reportID']); | ||
| type Attachment = { | ||
| file: File; | ||
| hasBeenFlagged: boolean; | ||
| isAuthTokenRequired: boolean; | ||
| isReceipt: boolean; | ||
| reportActionID: string; | ||
| source: string; | ||
| }; | ||
|
|
||
| type ReportAttachmentsProps = StackScreenProps<AuthScreensParamList, typeof SCREENS.REPORT_ATTACHMENTS>; | ||
|
|
||
| function ReportAttachments({route}: ReportAttachmentsProps) { | ||
| const reportID = route.params.reportID; | ||
| const report = ReportUtils.getReport(reportID); | ||
|
|
||
| // In native the imported images sources are of type number. Ref: https://reactnative.dev/docs/image#imagesource | ||
| const decodedSource = decodeURI(_.get(props, ['route', 'params', 'source'])); | ||
| const decodedSource = decodeURI(route.params.source); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actaully its not nullish , I removed optional chaining from |
||
| const source = Number(decodedSource) || decodedSource; | ||
|
|
||
| const onCarouselAttachmentChange = useCallback( | ||
| (attachment) => { | ||
| const route = ROUTES.REPORT_ATTACHMENTS.getRoute(reportID, attachment.source); | ||
| Navigation.navigate(route); | ||
| (attachment: Attachment) => { | ||
| const routeToNavigate = ROUTES.REPORT_ATTACHMENTS.getRoute(reportID, attachment.source); | ||
| Navigation.navigate(routeToNavigate); | ||
| }, | ||
| [reportID], | ||
| ); | ||
|
|
||
| return ( | ||
| <AttachmentModal | ||
| // @ts-expect-error TODO: Remove this once AttachmentModal (https://github.com/Expensify/App/issues/25130) is migrated to TypeScript. | ||
| allowDownload | ||
| defaultOpen | ||
| report={report} | ||
|
|
@@ -52,7 +56,6 @@ function ReportAttachments(props) { | |
| ); | ||
| } | ||
|
|
||
| ReportAttachments.propTypes = propTypes; | ||
| ReportAttachments.displayName = 'ReportAttachments'; | ||
|
|
||
| export default ReportAttachments; | ||
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.
I just wonder if this type shouldn't be global
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.
I think you are right , I remember that in other Attachments files we should use the same type , I will move it to other place , thanks!
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.
There is a type for File defined globally, but it has a different structure: