feat: [v6] Retire deprecated api for upload

This commit is contained in:
kiner-tang(文辉) 2025-01-19 10:39:44 +08:00
parent c4ea4db073
commit 0f5ce7fff9
3 changed files with 1 additions and 44 deletions

View File

@ -94,8 +94,6 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
'usage',
'`value` is not a valid prop, do you mean `fileList`?',
);
warning.deprecated(!('transformFile' in props), 'transformFile', 'beforeUpload');
}
// Control mode will auto fill file uid if not provided
@ -154,7 +152,7 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
};
const mergedBeforeUpload = async (file: RcFile, fileListArgs: RcFile[]) => {
const { beforeUpload, transformFile } = props;
const { beforeUpload } = props;
let parsedFile: File | Blob | string = file;
if (beforeUpload) {
@ -179,10 +177,6 @@ const InternalUpload: React.ForwardRefRenderFunction<UploadRef, UploadProps> = (
}
}
if (transformFile) {
parsedFile = await transformFile(parsedFile as any);
}
return parsedFile as RcFile;
};

View File

@ -1285,38 +1285,6 @@ describe('Upload List', () => {
});
});
it('[deprecated] should support transformFile', (done) => {
jest.useRealTimers();
// biome-ignore lint/style/useConst: test only
let wrapper: ReturnType<typeof render>;
let lastFile: UploadFile;
const handleTransformFile = jest.fn();
const onChange: UploadProps['onChange'] = ({ file }) => {
if (file.status === 'done') {
expect(file).not.toBe(lastFile);
expect(handleTransformFile).toHaveBeenCalled();
wrapper.unmount();
done();
}
lastFile = file;
};
wrapper = render(
<Upload
action="http://jsonplaceholder.typicode.com/posts/"
transformFile={handleTransformFile}
onChange={onChange}
customRequest={successRequest}
>
<button type="button">upload</button>
</Upload>,
);
fireEvent.change(wrapper.container.querySelector('input')!, {
target: { files: [{ name: 'foo.png' }] },
});
});
it('should render button inside UploadList when listStyle is picture-card', () => {
const {
container: wrapper,

View File

@ -83,9 +83,6 @@ export type ItemRender<T = any> = (
) => React.ReactNode;
type PreviewFileHandler = (file: File | Blob) => PromiseLike<string>;
type TransformFileHandler = (
file: RcFile,
) => string | Blob | File | PromiseLike<string | Blob | File>;
type BeforeUploadValueType = void | boolean | string | Blob | File;
export interface UploadProps<T = any> extends Pick<RcUploadProps, 'capture' | 'hasControlInside'> {
@ -125,8 +122,6 @@ export interface UploadProps<T = any> extends Pick<RcUploadProps, 'capture' | 'h
locale?: UploadLocale;
id?: string;
previewFile?: PreviewFileHandler;
/** @deprecated Please use `beforeUpload` directly */
transformFile?: TransformFileHandler;
iconRender?: (file: UploadFile<T>, listType?: UploadListType) => React.ReactNode;
isImageUrl?: (file: UploadFile<T>) => boolean;
progress?: UploadListProgressProps;