|
@@ -16,6 +16,9 @@ import {
|
|
|
syncDelete,
|
|
syncDelete,
|
|
|
syncMove,
|
|
syncMove,
|
|
|
syncCreateEntity,
|
|
syncCreateEntity,
|
|
|
|
|
+ NewDocEntity,
|
|
|
|
|
+ NewLinkedFileEntity,
|
|
|
|
|
+ NewEntity,
|
|
|
} from '../util/sync-mutation'
|
|
} from '../util/sync-mutation'
|
|
|
import { findInTree, findInTreeOrThrow } from '../util/find-in-tree'
|
|
import { findInTree, findInTreeOrThrow } from '../util/find-in-tree'
|
|
|
import { isNameUniqueInFolder } from '../util/is-name-unique-in-folder'
|
|
import { isNameUniqueInFolder } from '../util/is-name-unique-in-folder'
|
|
@@ -35,6 +38,7 @@ import { Folder } from '../../../../../types/folder'
|
|
|
import { useReferencesContext } from '@/features/ide-react/context/references-context'
|
|
import { useReferencesContext } from '@/features/ide-react/context/references-context'
|
|
|
import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
|
|
import { usePermissionsContext } from '@/features/ide-react/context/permissions-context'
|
|
|
import { FileTreeEntity } from '@ol-types/file-tree-entity'
|
|
import { FileTreeEntity } from '@ol-types/file-tree-entity'
|
|
|
|
|
+import { Doc } from '@ol-types/doc'
|
|
|
|
|
|
|
|
type DroppedFile = File & {
|
|
type DroppedFile = File & {
|
|
|
relativePath?: string
|
|
relativePath?: string
|
|
@@ -73,8 +77,12 @@ const FileTreeActionableContext = createContext<
|
|
|
finishCreatingFolder: any
|
|
finishCreatingFolder: any
|
|
|
startCreatingDocOrFile: any
|
|
startCreatingDocOrFile: any
|
|
|
startUploadingDocOrFile: any
|
|
startUploadingDocOrFile: any
|
|
|
- finishCreatingDoc: any
|
|
|
|
|
- finishCreatingLinkedFile: any
|
|
|
|
|
|
|
+ finishCreatingDoc: (
|
|
|
|
|
+ entity: Omit<NewDocEntity, 'endpoint'>
|
|
|
|
|
+ ) => Promise<Doc | undefined>
|
|
|
|
|
+ finishCreatingLinkedFile: (
|
|
|
|
|
+ entity: Omit<NewLinkedFileEntity, 'endpoint'>
|
|
|
|
|
+ ) => Promise<{ new_file_id: string } | undefined>
|
|
|
cancel: () => void
|
|
cancel: () => void
|
|
|
droppedFiles: { files: File[]; targetFolderId: string } | null
|
|
droppedFiles: { files: File[]; targetFolderId: string } | null
|
|
|
setDroppedFiles: (value: DroppedFiles | null) => void
|
|
setDroppedFiles: (value: DroppedFiles | null) => void
|
|
@@ -403,7 +411,7 @@ export const FileTreeActionableProvider: FC<React.PropsWithChildren> = ({
|
|
|
}, [fileTreeData, selectedEntityIds])
|
|
}, [fileTreeData, selectedEntityIds])
|
|
|
|
|
|
|
|
const finishCreatingEntity = useCallback(
|
|
const finishCreatingEntity = useCallback(
|
|
|
- (entity: any) => {
|
|
|
|
|
|
|
+ (entity: NewEntity) => {
|
|
|
const error = validateCreate(fileTreeData, parentFolderId, entity)
|
|
const error = validateCreate(fileTreeData, parentFolderId, entity)
|
|
|
if (error) {
|
|
if (error) {
|
|
|
return Promise.reject(error)
|
|
return Promise.reject(error)
|
|
@@ -415,7 +423,7 @@ export const FileTreeActionableProvider: FC<React.PropsWithChildren> = ({
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const finishCreatingFolder = useCallback(
|
|
const finishCreatingFolder = useCallback(
|
|
|
- (name: any) => {
|
|
|
|
|
|
|
+ (name: string) => {
|
|
|
dispatch({ type: ACTION_TYPES.CREATING_FOLDER })
|
|
dispatch({ type: ACTION_TYPES.CREATING_FOLDER })
|
|
|
return finishCreatingEntity({ endpoint: 'folder', name })
|
|
return finishCreatingEntity({ endpoint: 'folder', name })
|
|
|
.then(() => {
|
|
.then(() => {
|
|
@@ -440,8 +448,16 @@ export const FileTreeActionableProvider: FC<React.PropsWithChildren> = ({
|
|
|
startCreatingFile('upload')
|
|
startCreatingFile('upload')
|
|
|
}, [startCreatingFile])
|
|
}, [startCreatingFile])
|
|
|
|
|
|
|
|
|
|
+ type FinishCreatingDocOrFileReturn<T> = T extends NewDocEntity
|
|
|
|
|
+ ? Promise<Doc | undefined>
|
|
|
|
|
+ : T extends NewLinkedFileEntity
|
|
|
|
|
+ ? Promise<{ new_file_id: string } | undefined>
|
|
|
|
|
+ : never
|
|
|
|
|
+
|
|
|
const finishCreatingDocOrFile = useCallback(
|
|
const finishCreatingDocOrFile = useCallback(
|
|
|
- (entity: any) => {
|
|
|
|
|
|
|
+ <T extends NewDocEntity | NewLinkedFileEntity>(
|
|
|
|
|
+ entity: T
|
|
|
|
|
+ ): FinishCreatingDocOrFileReturn<T> => {
|
|
|
dispatch({ type: ACTION_TYPES.CREATING_FILE })
|
|
dispatch({ type: ACTION_TYPES.CREATING_FILE })
|
|
|
|
|
|
|
|
return finishCreatingEntity(entity)
|
|
return finishCreatingEntity(entity)
|
|
@@ -451,23 +467,21 @@ export const FileTreeActionableProvider: FC<React.PropsWithChildren> = ({
|
|
|
})
|
|
})
|
|
|
.catch(error => {
|
|
.catch(error => {
|
|
|
dispatch({ type: ACTION_TYPES.ERROR, error })
|
|
dispatch({ type: ACTION_TYPES.ERROR, error })
|
|
|
- })
|
|
|
|
|
|
|
+ }) as FinishCreatingDocOrFileReturn<T>
|
|
|
},
|
|
},
|
|
|
[finishCreatingEntity]
|
|
[finishCreatingEntity]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const finishCreatingDoc = useCallback(
|
|
const finishCreatingDoc = useCallback(
|
|
|
- (entity: any) => {
|
|
|
|
|
- entity.endpoint = 'doc'
|
|
|
|
|
- return finishCreatingDocOrFile(entity)
|
|
|
|
|
|
|
+ (entity: Omit<NewDocEntity, 'endpoint'>) => {
|
|
|
|
|
+ return finishCreatingDocOrFile({ ...entity, endpoint: 'doc' })
|
|
|
},
|
|
},
|
|
|
[finishCreatingDocOrFile]
|
|
[finishCreatingDocOrFile]
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
const finishCreatingLinkedFile = useCallback(
|
|
const finishCreatingLinkedFile = useCallback(
|
|
|
- (entity: any) => {
|
|
|
|
|
- entity.endpoint = 'linked_file'
|
|
|
|
|
- return finishCreatingDocOrFile(entity)
|
|
|
|
|
|
|
+ (entity: Omit<NewLinkedFileEntity, 'endpoint'>) => {
|
|
|
|
|
+ return finishCreatingDocOrFile({ ...entity, endpoint: 'linked_file' })
|
|
|
},
|
|
},
|
|
|
[finishCreatingDocOrFile]
|
|
[finishCreatingDocOrFile]
|
|
|
)
|
|
)
|