@@ -14,6 +14,7 @@ import workspacesSelectors from 'app/store/slices/workspaces/workspaces.selector
1414import { uploadFoldersWithManager } from 'app/network/UploadFolderManager' ;
1515import replaceFileService from 'views/Drive/services/replaceFile.service' ;
1616import { Network , getEnvironmentConfig } from 'app/drive/services/network.service' ;
17+ import { useVersioningLimits } from 'views/Drive/components/VersionHistory/context/VersioningLimitsContext' ;
1718
1819type NameCollisionContainerProps = {
1920 currentFolderId : string ;
@@ -45,6 +46,8 @@ const NameCollisionContainer: FC<NameCollisionContainerProps> = ({
4546 ( ) => moveDestinationFolderId ?? currentFolderId ,
4647 [ moveDestinationFolderId , currentFolderId ] ,
4748 ) ;
49+ const { limits } = useVersioningLimits ( ) ;
50+ const isVersioningEnabled = limits ?. versioning ?. enabled ?? false ;
4851
4952 const handleNewItems = ( files : ( File | DriveItemData ) [ ] , folders : ( IRoot | DriveItemData ) [ ] ) => [
5053 ...files ,
@@ -143,6 +146,27 @@ const NameCollisionContainer: FC<NameCollisionContainerProps> = ({
143146 return await uploadPromise ;
144147 } ;
145148
149+ const replaceFileVersion = async ( file : File , itemToReplace : DriveItemData ) => {
150+ const newFileId = await uploadFileAndGetFileId ( file , itemToReplace ) ;
151+ await replaceFileService . replaceFile ( itemToReplace . uuid , {
152+ fileId : newFileId ,
153+ size : file . size ,
154+ } ) ;
155+ } ;
156+
157+ const trashAndUpload = async ( file : File , itemToReplace : DriveItemData ) => {
158+ await moveItemsToTrash ( [ itemToReplace ] ) ;
159+ await dispatch (
160+ storageThunks . uploadItemsThunk ( {
161+ files : [ file ] ,
162+ parentFolderId : folderId ,
163+ options : {
164+ disableDuplicatedNamesCheck : true ,
165+ } ,
166+ } ) ,
167+ ) ;
168+ } ;
169+
146170 const replaceAndUploadItem = async ( {
147171 itemsToReplace,
148172 itemsToUpload,
@@ -156,7 +180,7 @@ const NameCollisionContainer: FC<NameCollisionContainerProps> = ({
156180
157181 if ( ( itemToUpload as IRoot ) . fullPathEdited ) {
158182 await moveItemsToTrash ( [ itemToReplace ] ) ;
159- uploadFoldersWithManager ( {
183+ await uploadFoldersWithManager ( {
160184 payload : [
161185 {
162186 root : { ...( itemToUpload as IRoot ) } ,
@@ -165,20 +189,13 @@ const NameCollisionContainer: FC<NameCollisionContainerProps> = ({
165189 ] ,
166190 selectedWorkspace,
167191 dispatch,
168- } ) . then ( ( ) => {
169- dispatch ( fetchSortedFolderContentThunk ( folderId ) ) ;
170192 } ) ;
171193 } else {
172194 const file = itemToUpload as File ;
173- const newFileId = await uploadFileAndGetFileId ( file , itemToReplace ) ;
174-
175- await replaceFileService . replaceFile ( itemToReplace . uuid , {
176- fileId : newFileId ,
177- size : file . size ,
178- } ) ;
179-
180- dispatch ( fetchSortedFolderContentThunk ( folderId ) ) ;
195+ isVersioningEnabled ? await replaceFileVersion ( file , itemToReplace ) : await trashAndUpload ( file , itemToReplace ) ;
181196 }
197+
198+ dispatch ( fetchSortedFolderContentThunk ( folderId ) ) ;
182199 }
183200 } ;
184201
0 commit comments