Skip to content

Commit f7ff73e

Browse files
authored
Merge pull request #4180 from czwe-01/thulasizwe/fix/4098
Thulasizwe/fix/4098
2 parents abfb3e7 + 9defe95 commit f7ff73e

File tree

3 files changed

+174
-176
lines changed

3 files changed

+174
-176
lines changed

shesha-reactjs/src/components/customFile/index.tsx

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,28 +45,26 @@ export const CustomFile: FC<ICustomFileProps> = (props) => {
4545
const { backendUrl } = useSheshaApplication();
4646

4747
return (
48-
<div className="stored-files-renderer-wrapper">
49-
<StoredFilesRendererBase
50-
{...props}
51-
isStub={props.isStub}
52-
disabled={props.disabled || !props.allowAdd}
53-
isDragger={props?.isDragger}
54-
fileList={fileList?.map(({ url, ...rest }) => ({ url: `${backendUrl}${url}`, ...rest }))}
55-
allowUpload={false}
56-
allowDelete={props.allowDelete}
57-
deleteFile={deleteFile}
58-
uploadFile={props.uploadFile ?? uploadFile}
59-
downloadZipFile={downloadZipFile}
60-
downloadZip={props.downloadZip}
61-
downloadFile={downloadFile}
62-
isDownloadingFileListZip={downloadZip}
63-
isDownloadZipSucceeded={downloadZipSuccess}
64-
allowedFileTypes={props?.allowedFileTypes}
65-
maxHeight={props?.maxHeight}
66-
layout={props?.filesLayout}
67-
listType={props?.listType}
68-
/>
69-
</div>
48+
<StoredFilesRendererBase
49+
{...props}
50+
isStub={props.isStub}
51+
disabled={props.disabled || !props.allowAdd}
52+
isDragger={props?.isDragger}
53+
fileList={fileList?.map(({ url, ...rest }) => ({ url: `${backendUrl}${url}`, ...rest }))}
54+
allowUpload={false}
55+
allowDelete={props.allowDelete}
56+
deleteFile={deleteFile}
57+
uploadFile={props.uploadFile ?? uploadFile}
58+
downloadZipFile={downloadZipFile}
59+
downloadZip={props.downloadZip}
60+
downloadFile={downloadFile}
61+
isDownloadingFileListZip={downloadZip}
62+
isDownloadZipSucceeded={downloadZipSuccess}
63+
allowedFileTypes={props?.allowedFileTypes}
64+
maxHeight={props?.maxHeight}
65+
layout={props?.filesLayout}
66+
listType={props?.listType}
67+
/>
7068
);
7169
};
7270

shesha-reactjs/src/components/storedFilesRendererBase/index.tsx

Lines changed: 64 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ export const StoredFilesRendererBase: FC<IStoredFilesRendererBaseProps> = ({
122122
hideFileName: rest.hideFileName && listType === 'thumbnail',
123123
isDragger,
124124
isStub,
125+
downloadZip,
125126
},
126127
});
127128

@@ -284,71 +285,69 @@ export const StoredFilesRendererBase: FC<IStoredFilesRendererBaseProps> = ({
284285
};
285286

286287
return (
287-
<div className={`${styles.shaStoredFilesRenderer} ${layout === 'horizontal' && listTypeAndLayout !== 'text' ? styles.shaStoredFilesRendererHorizontal
288-
: layout === 'vertical' && listTypeAndLayout !== 'text' ? styles.shaStoredFilesRendererVertical
289-
: layout === 'grid' && listTypeAndLayout !== 'text' ? styles.shaStoredFilesRendererGrid : ''}`}
290-
>
291-
{isStub
292-
? (isDragger
293-
? <Dragger disabled><DraggerStub styles={styles} /></Dragger>
294-
: (
295-
<div
296-
className={listType === 'thumbnail' ? 'ant-upload-list-item-thumbnail ant-upload-list-item thumbnail-stub' : ''}
297-
>
298-
{renderUploadContent()}
299-
{listType !== 'text' && !rest.hideFileName && (
300-
<span className="ant-upload-list-item-name ant-upload-list-item-name-stub">
301-
file name
302-
</span>
303-
)}
304-
</div>
305-
))
306-
: (props.disabled && fileList.length === 0
307-
? (
308-
<div className={listType === 'thumbnail' ? styles.thumbnailReadOnly : ''}>
309-
{renderUploadContent()}
310-
</div>
311-
)
312-
: props.disabled
313-
? <Upload {...props} style={model?.allStyles?.fullStyle} listType={listTypeAndLayout} />
314-
: isDragger
315-
? (
316-
<Dragger {...props}>
317-
<DraggerStub styles={styles} />
318-
</Dragger>
319-
)
320-
: <Upload {...props} listType={listTypeAndLayout}>{renderUploadContent()}</Upload>)}
321-
{previewImage && (
322-
<Image
323-
wrapperStyle={{ display: 'none' }}
324-
preview={{
325-
visible: previewOpen,
326-
onVisibleChange: (visible) => setPreviewOpen(visible),
327-
afterOpenChange: (visible) => !visible && setPreviewImage(null),
328-
toolbarRender: (original) => {
329-
return <div style={{ display: 'flex', flexDirection: 'row-reverse' }}><DownloadOutlined className={styles.antPreviewDownloadIcon} onClick={() => downloadFile({ fileId: previewImage.uid, fileName: previewImage.name })} />{original}</div>;
330-
},
331-
}}
332-
src={previewImage.url}
333-
/>
334-
)}
335-
336-
{fetchFilesError && (
337-
<Alert message="Error" description="Sorry, an error occurred while trying to fetch file list." type="error" />
338-
)}
339-
340-
{downloadZipFileError && (
341-
<Alert message="Error" description="Sorry, an error occurred while trying to download zip file." type="error" />
342-
)}
343-
344-
{downloadZip && hasFiles && !!downloadZipFile && (
345-
<div className={styles.storedFilesRendererBtnContainer}>
346-
<Button size="small" type="link" icon onClick={() => downloadZipFile()} loading={isDownloadingFileListZip}>
347-
{!isDownloadingFileListZip && <FileZipOutlined />} Download Zip
348-
</Button>
349-
</div>
350-
)}
351-
288+
<div className={styles.storedFilesRendererWrapper}>
289+
<div className={`${styles.shaStoredFilesRenderer} ${layout === 'horizontal' && listTypeAndLayout !== 'text' ? styles.shaStoredFilesRendererHorizontal
290+
: layout === 'vertical' && listTypeAndLayout !== 'text' ? styles.shaStoredFilesRendererVertical
291+
: layout === 'grid' && listTypeAndLayout !== 'text' ? styles.shaStoredFilesRendererGrid : ''}`}
292+
>
293+
{isStub
294+
? (isDragger
295+
? <Dragger disabled><DraggerStub styles={styles} /></Dragger>
296+
: (
297+
<div
298+
className={listType === 'thumbnail' ? 'ant-upload-list-item-thumbnail ant-upload-list-item thumbnail-stub' : ''}
299+
>
300+
{renderUploadContent()}
301+
{listType !== 'text' && !rest.hideFileName && (
302+
<span className="ant-upload-list-item-name ant-upload-list-item-name-stub">
303+
file name
304+
</span>
305+
)}
306+
</div>
307+
))
308+
: (props.disabled && fileList.length === 0
309+
? null
310+
: props.disabled
311+
? <Upload {...props} style={model?.allStyles?.fullStyle} listType={listTypeAndLayout} />
312+
: isDragger
313+
? (
314+
<Dragger {...props}>
315+
<DraggerStub styles={styles} />
316+
</Dragger>
317+
)
318+
: <Upload {...props} listType={listTypeAndLayout}>{renderUploadContent()}</Upload>)}
319+
{previewImage && (
320+
<Image
321+
wrapperStyle={{ display: 'none' }}
322+
preview={{
323+
visible: previewOpen,
324+
onVisibleChange: (visible) => setPreviewOpen(visible),
325+
afterOpenChange: (visible) => !visible && setPreviewImage(null),
326+
toolbarRender: (original) => {
327+
return <div style={{ display: 'flex', flexDirection: 'row-reverse' }}><DownloadOutlined className={styles.antPreviewDownloadIcon} onClick={() => downloadFile({ fileId: previewImage.uid, fileName: previewImage.name })} />{original}</div>;
328+
},
329+
}}
330+
src={previewImage.url}
331+
/>
332+
)}
333+
334+
{fetchFilesError && (
335+
<Alert message="Error" description="Sorry, an error occurred while trying to fetch file list." type="error" />
336+
)}
337+
338+
{downloadZipFileError && (
339+
<Alert message="Error" description="Sorry, an error occurred while trying to download zip file." type="error" />
340+
)}
341+
342+
{downloadZip && hasFiles && !!downloadZipFile && (
343+
<div className={styles.storedFilesRendererBtnContainer}>
344+
<Button size="small" type="link" icon onClick={() => downloadZipFile()} loading={isDownloadingFileListZip}>
345+
{!isDownloadingFileListZip && <FileZipOutlined />} Download Zip
346+
</Button>
347+
</div>
348+
)}
349+
350+
</div>
352351
</div>
353352
);
354353
};

0 commit comments

Comments
 (0)