@@ -56,7 +56,10 @@ import { RECORDS_TO_LOAD_FIRST } from "@/constants";
5656import type { FileDownloadRequestFormValues } from "@/forms/ManualFileDownloadRequestForm" ;
5757import ManualFileDownloadRequestForm from "@/forms/ManualFileDownloadRequestForm" ;
5858import ManualFileDownloadRequestFromRepositoryForm from "@/forms/ManualFileDownloadRequestFromRepositoryForm" ;
59- import type { ManualFileDownloadRequestFromRepositoryData } from "@/forms/validation" ;
59+ import type {
60+ FileDestinationType ,
61+ ManualFileDownloadRequestFromRepositoryData ,
62+ } from "@/forms/validation" ;
6063import { computeDigest , createTarGzArchive } from "@/lib/files" ;
6164
6265// We use graphql fields below in columns configuration
@@ -190,6 +193,11 @@ const FILE_DOWNLOAD_REQUEST_UPDATED_SUBSCRIPTION = graphql`
190193 }
191194` ;
192195
196+ type DestinationTypeOption = {
197+ value : FileDestinationType ;
198+ label : string ;
199+ } ;
200+
193201const formatRelayErrors = (
194202 errors : ReadonlyArray < {
195203 fields ?: ReadonlyArray < string > | null ;
@@ -206,12 +214,14 @@ type ManualFileDownloadRequestFormWrapperProps = {
206214 setErrorFeedback : ( feedback : React . ReactNode ) => void ;
207215 deviceId : string ;
208216 showAdvancedOptions : boolean ;
217+ destinationTypeOptions : DestinationTypeOption [ ] ;
209218} ;
210219
211220const ManualFileDownloadRequestFormWrapper = ( {
212221 setErrorFeedback,
213222 deviceId,
214223 showAdvancedOptions,
224+ destinationTypeOptions,
215225} : ManualFileDownloadRequestFormWrapperProps ) => {
216226 const intl = useIntl ( ) ;
217227 const [ isUploading , setIsUploading ] = useState ( false ) ;
@@ -455,6 +465,7 @@ const ManualFileDownloadRequestFormWrapper = ({
455465 isLoading = { isUploading }
456466 onFileSubmit = { handleFileUpload }
457467 showAdvancedOptions = { showAdvancedOptions }
468+ destinationTypeOptions = { destinationTypeOptions }
458469 />
459470 ) ;
460471} ;
@@ -464,13 +475,15 @@ type ManualFileDownloadRequestFromRepositoryFormWrapperProps = {
464475 repositoriesQueryRef : PreloadedQuery < FilesUploadTab_getRepositories_Query > ;
465476 deviceId : string ;
466477 showAdvancedOptions : boolean ;
478+ destinationTypeOptions : DestinationTypeOption [ ] ;
467479} ;
468480
469481const ManualFileDownloadRequestFromRepositoryFormWrapper = ( {
470482 setErrorFeedback,
471483 repositoriesQueryRef,
472484 deviceId,
473485 showAdvancedOptions,
486+ destinationTypeOptions,
474487} : ManualFileDownloadRequestFromRepositoryFormWrapperProps ) => {
475488 const intl = useIntl ( ) ;
476489 const [ isUploading , setIsUploading ] = useState ( false ) ;
@@ -588,6 +601,7 @@ const ManualFileDownloadRequestFromRepositoryFormWrapper = ({
588601 isLoading = { isUploading }
589602 onFileSubmit = { handleFileUpload }
590603 showAdvancedOptions = { showAdvancedOptions }
604+ destinationTypeOptions = { destinationTypeOptions }
591605 />
592606 ) ;
593607} ;
@@ -598,7 +612,7 @@ type FilesUploadTabProps = {
598612
599613const FilesUploadTab = ( { deviceRef } : FilesUploadTabProps ) => {
600614 const intl = useIntl ( ) ;
601- const { deviceId } = useParams ( ) ;
615+ const { deviceId = "" } = useParams ( ) ;
602616
603617 const [ updateMode , setUpdateMode ] = useState < "repository" | "file" > ( "file" ) ;
604618
@@ -624,10 +638,6 @@ const FilesUploadTab = ({ deviceRef }: FilesUploadTabProps) => {
624638 [ data . fileDownloadRequests ] ,
625639 ) ;
626640
627- const showAdvancedOptions =
628- data . capabilities . includes ( "POSIX_FILE_TRANSFER_STORAGE" ) ||
629- data . capabilities . includes ( "POSIX_FILE_TRANSFER_STREAM" ) ;
630-
631641 const [ getRepositoriesQuery , getRepositories ] =
632642 useQueryLoader < FilesUploadTab_getRepositories_Query > (
633643 GET_REPOSITORIES_QUERY ,
@@ -644,6 +654,41 @@ const FilesUploadTab = ({ deviceRef }: FilesUploadTabProps) => {
644654
645655 useEffect ( fetchRepositories , [ fetchRepositories ] ) ;
646656
657+ const { capabilities } = data ;
658+
659+ const hasStorage =
660+ capabilities . includes ( "POSIX_FILE_TRANSFER_STORAGE" ) ||
661+ capabilities . includes ( "WINDOWS_FILE_TRANSFER_STORAGE" ) ;
662+
663+ const hasStream =
664+ capabilities . includes ( "POSIX_FILE_TRANSFER_STREAM" ) ||
665+ capabilities . includes ( "WINDOWS_FILE_TRANSFER_STREAM" ) ;
666+
667+ const showAdvancedOptions =
668+ capabilities . includes ( "POSIX_FILE_TRANSFER_STORAGE" ) ||
669+ capabilities . includes ( "POSIX_FILE_TRANSFER_STREAM" ) ;
670+
671+ const destinationTypeOptions = useMemo < DestinationTypeOption [ ] > ( ( ) => {
672+ const options : DestinationTypeOption [ ] = [ ] ;
673+
674+ if ( hasStorage ) {
675+ options . push ( { value : "STORAGE" , label : "Storage" } ) ;
676+ }
677+
678+ if ( hasStream ) {
679+ options . push (
680+ { value : "STREAMING" , label : "Streaming" } ,
681+ { value : "FILESYSTEM" , label : "File System" } ,
682+ ) ;
683+ }
684+
685+ return options ;
686+ } , [ hasStorage , hasStream ] ) ;
687+
688+ if ( ! hasStorage && ! hasStream ) {
689+ return null ;
690+ }
691+
647692 return (
648693 < Tab
649694 eventKey = "device-files-upload-tab"
@@ -675,7 +720,7 @@ const FilesUploadTab = ({ deviceRef }: FilesUploadTabProps) => {
675720 type = "radio"
676721 name = "updateMode"
677722 value = { updateMode }
678- onChange = { ( mode ) => setUpdateMode ( mode ) }
723+ onChange = { setUpdateMode }
679724 size = "sm"
680725 >
681726 < ToggleButton
@@ -709,19 +754,22 @@ const FilesUploadTab = ({ deviceRef }: FilesUploadTabProps) => {
709754 </ ToggleButton >
710755 </ ToggleButtonGroup >
711756 </ div >
757+
712758 { updateMode === "file" ? (
713759 < ManualFileDownloadRequestFormWrapper
714760 setErrorFeedback = { setErrorFeedback }
715- deviceId = { deviceId || "" }
761+ deviceId = { deviceId }
716762 showAdvancedOptions = { showAdvancedOptions }
763+ destinationTypeOptions = { destinationTypeOptions }
717764 />
718765 ) : (
719766 getRepositoriesQuery && (
720767 < ManualFileDownloadRequestFromRepositoryFormWrapper
721768 repositoriesQueryRef = { getRepositoriesQuery }
722769 setErrorFeedback = { setErrorFeedback }
723- deviceId = { deviceId || "" }
770+ deviceId = { deviceId }
724771 showAdvancedOptions = { showAdvancedOptions }
772+ destinationTypeOptions = { destinationTypeOptions }
725773 />
726774 )
727775 ) }
@@ -745,4 +793,6 @@ const FilesUploadTab = ({ deviceRef }: FilesUploadTabProps) => {
745793 ) ;
746794} ;
747795
796+ export type { DestinationTypeOption } ;
797+
748798export default FilesUploadTab ;
0 commit comments