-
Notifications
You must be signed in to change notification settings - Fork 301
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
feat(react-storage): refactor useView action related hooks #5998
Changes from all commits
14d6400
78db8a5
c72df9f
69ba65c
23bf486
00565b4
13296f8
22759c5
49dfe0c
4bb6ca7
e0a03ce
4165171
aad8844
731f099
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,17 +1,15 @@ | ||
import { copy } from '../../storage-internal'; | ||
import { getFilenameWithoutPrefix } from '../../views/LocationActionView/utils'; | ||
import { | ||
FileDataItem, | ||
TaskHandler, | ||
TaskHandlerInput, | ||
TaskData, | ||
TaskHandlerOptions, | ||
TaskHandlerOutput, | ||
} from '../types'; | ||
import { FileData } from './listLocationItems'; | ||
} from './types'; | ||
|
||
import { constructBucket } from './utils'; | ||
|
||
export interface CopyHandlerData extends TaskData, FileData {} | ||
export interface CopyHandlerData extends FileDataItem {} | ||
|
||
export interface CopyHandlerInput | ||
extends TaskHandlerInput<CopyHandlerData, TaskHandlerOptions> { | ||
|
@@ -29,11 +27,11 @@ export const copyHandler: CopyHandler = (input) => { | |
credentials, | ||
customEndpoint, | ||
} = config; | ||
const { key: sourcePath } = data; | ||
const { key: sourcePath, fileKey } = data; | ||
|
||
const bucket = constructBucket(config); | ||
|
||
const destinationPath = `${path}${getFilenameWithoutPrefix(sourcePath)}`; | ||
const destinationPath = `${path}${fileKey}`; | ||
Comment on lines
-36
to
+34
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. Updated the approach here to allow to improve consumer ergonomics by providing just the parsed |
||
const source = { bucket, expectedBucketOwner, path: sourcePath }; | ||
const destination = { bucket, expectedBucketOwner, path: destinationPath }; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,28 +9,13 @@ import { | |
ListHandlerInput, | ||
ListHandlerOptions, | ||
ListHandlerOutput, | ||
} from '../types'; | ||
LocationItemData, | ||
} from './types'; | ||
|
||
const DEFAULT_PAGE_SIZE = 1000; | ||
|
||
export interface FolderData { | ||
key: string; | ||
id: string; | ||
type: 'FOLDER'; | ||
} | ||
|
||
export interface FileData { | ||
key: string; | ||
lastModified: Date; | ||
id: string; | ||
size: number; | ||
type: 'FILE'; | ||
} | ||
Comment on lines
-16
to
-28
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. Moved to sibling types.ts |
||
|
||
type ListOutputItem = ListOutput['items'][number]; | ||
|
||
export type LocationItemData = FileData | FolderData; | ||
|
||
export type LocationItemType = LocationItemData['type']; | ||
|
||
export interface ListLocationItemsHandlerOptions | ||
|
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. Interfaces in this file were migrated from ../types.ts to avoid potential circular references |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { Permission } from '../../storage-internal'; | ||
import { | ||
LocationCredentialsProvider, | ||
Permission, | ||
} from '../../storage-internal'; | ||
|
||
export type LocationType = 'OBJECT' | 'PREFIX' | 'BUCKET'; | ||
|
||
|
@@ -33,3 +36,87 @@ export interface LocationData { | |
*/ | ||
type: LocationType; | ||
} | ||
|
||
export interface FolderData { | ||
key: string; | ||
id: string; | ||
type: 'FOLDER'; | ||
} | ||
|
||
export interface FileData { | ||
key: string; | ||
lastModified: Date; | ||
id: string; | ||
size: number; | ||
type: 'FILE'; | ||
} | ||
|
||
export type LocationItemData = FileData | FolderData; | ||
|
||
export interface FileDataItem extends FileData, TaskData { | ||
fileKey: string; | ||
} | ||
|
||
export interface FileItem extends TaskData { | ||
file: File; | ||
} | ||
|
||
export interface ActionInputConfig { | ||
accountId?: string; | ||
bucket: string; | ||
credentials: LocationCredentialsProvider; | ||
customEndpoint?: string; | ||
region: string; | ||
} | ||
|
||
interface ActionInput<T = any> { | ||
config: ActionInputConfig; | ||
prefix: string; | ||
options?: T; | ||
} | ||
|
||
export interface TaskData { | ||
key: string; | ||
id: string; | ||
} | ||
|
||
export interface TaskHandlerOptions { | ||
onProgress?: ( | ||
data: { key: string; id: string }, | ||
progress: number | undefined | ||
) => void; | ||
} | ||
|
||
export interface TaskHandlerInput< | ||
T extends TaskData = TaskData, | ||
K extends TaskHandlerOptions = TaskHandlerOptions, | ||
> { | ||
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. Nit: Isn't 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. Generally we have treated usage of 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. We should maybe rethink this later. K is definitely a convention but we seem to be misusing it a bit |
||
config: ActionInputConfig; | ||
data: T; | ||
options?: K; | ||
} | ||
|
||
export interface TaskHandlerOutput { | ||
cancel?: () => void; | ||
result: Promise<{ | ||
message?: string; | ||
status: 'CANCELED' | 'COMPLETE' | 'FAILED' | 'OVERWRITE_PREVENTED'; | ||
}>; | ||
} | ||
|
||
export type TaskHandler<T = any, K = any> = (input: T) => K; | ||
|
||
export interface ListHandlerOptions<T = never> { | ||
exclude?: T; | ||
nextToken?: string; | ||
pageSize?: number; | ||
} | ||
|
||
export interface ListHandlerInput<T = any> extends ActionInput<T> {} | ||
|
||
export interface ListHandlerOutput<T = any> { | ||
nextToken: string | undefined; | ||
items: T[]; | ||
} | ||
|
||
export type ListHandler<T = any, K = any> = (input: T) => Promise<K>; |
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.
Removed to fix a circular dependency