Compare commits
5 Commits
@portaljs/
...
@portaljs/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af11f0cfd5 | ||
|
|
9ae2b31113 | ||
|
|
2bffd130c8 | ||
|
|
058d23678a | ||
|
|
540a08934c |
@@ -1,5 +1,11 @@
|
|||||||
# @portaljs/components
|
# @portaljs/components
|
||||||
|
|
||||||
|
## 0.5.8
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- [#1079](https://github.com/datopian/portaljs/pull/1079) [`058d2367`](https://github.com/datopian/portaljs/commit/058d23678a024890f8a6d909ded9fc8fc11cf145) Thanks [@Gutts-n](https://github.com/Gutts-n)! - Changed the download behaviour of the bucket viewer component and removed loading component while downloading
|
||||||
|
|
||||||
## 0.5.7
|
## 0.5.7
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@portaljs/components",
|
"name": "@portaljs/components",
|
||||||
"version": "0.5.7",
|
"version": "0.5.8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"description": "https://portaljs.org",
|
"description": "https://portaljs.org",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ export interface BucketViewerProps {
|
|||||||
onLoadTotalNumberOfItems?: (total: number) => void;
|
onLoadTotalNumberOfItems?: (total: number) => void;
|
||||||
domain: string;
|
domain: string;
|
||||||
downloadConfig?: {
|
downloadConfig?: {
|
||||||
downloadingMessageComponent?: ReactNode;
|
|
||||||
hoverOfTheFileComponent?: ReactNode;
|
hoverOfTheFileComponent?: ReactNode;
|
||||||
};
|
};
|
||||||
suffix?: string;
|
suffix?: string;
|
||||||
@@ -47,14 +46,10 @@ export function BucketViewer({
|
|||||||
}: BucketViewerProps) {
|
}: BucketViewerProps) {
|
||||||
suffix = suffix ?? '/';
|
suffix = suffix ?? '/';
|
||||||
|
|
||||||
const { downloadingMessageComponent, hoverOfTheFileComponent } =
|
const { hoverOfTheFileComponent } = downloadConfig ?? {};
|
||||||
downloadConfig ?? {};
|
|
||||||
const [isLoading, setIsLoading] = useState<boolean>(false);
|
const [isLoading, setIsLoading] = useState<boolean>(false);
|
||||||
const [showDownloadComponentOnLine, setShowDownloadComponentOnLine] =
|
const [showDownloadComponentOnLine, setShowDownloadComponentOnLine] =
|
||||||
useState(-1);
|
useState(-1);
|
||||||
const [showDownloadLoadingOnFile, setShowDownloadLoadingOnFile] = useState(
|
|
||||||
new Map<string, boolean>()
|
|
||||||
);
|
|
||||||
const [currentPage, setCurrentPage] = useState<number>(0);
|
const [currentPage, setCurrentPage] = useState<number>(0);
|
||||||
const [lastPage, setLastPage] = useState<number>(0);
|
const [lastPage, setLastPage] = useState<number>(0);
|
||||||
const [bucketFiles, setBucketFiles] = useState<BucketViewerData[]>([]);
|
const [bucketFiles, setBucketFiles] = useState<BucketViewerData[]>([]);
|
||||||
@@ -136,31 +131,13 @@ export function BucketViewer({
|
|||||||
(data, i) => (
|
(data, i) => (
|
||||||
<ul
|
<ul
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
const anchorId = `download_anchor_${data.fileName} `;
|
const a: HTMLAnchorElement = document.createElement('a');
|
||||||
const a: HTMLAnchorElement =
|
a.href = data.downloadFileUri;
|
||||||
(document.getElementById(
|
a.target = `_blank`;
|
||||||
anchorId
|
a.download = data.fileName;
|
||||||
) as HTMLAnchorElement | null) ?? document.createElement('a');
|
document.body.appendChild(a);
|
||||||
a.id = anchorId;
|
a.click();
|
||||||
if (a.download) a.click();
|
document.removeChild(a);
|
||||||
else {
|
|
||||||
setShowDownloadLoadingOnFile((lastState) => {
|
|
||||||
lastState.set(data.fileName, true);
|
|
||||||
return new Map(lastState);
|
|
||||||
});
|
|
||||||
fetch(data.downloadFileUri)
|
|
||||||
.then((res) => res.blob())
|
|
||||||
.then((res) => {
|
|
||||||
setShowDownloadLoadingOnFile((lastState) => {
|
|
||||||
lastState.set(data.fileName, false);
|
|
||||||
return new Map(lastState);
|
|
||||||
});
|
|
||||||
a.href = URL.createObjectURL(res);
|
|
||||||
a.download = res.name ?? data.fileName;
|
|
||||||
document.body.appendChild(a);
|
|
||||||
a.click();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
key={i}
|
key={i}
|
||||||
onMouseEnter={() => setShowDownloadComponentOnLine(i)}
|
onMouseEnter={() => setShowDownloadComponentOnLine(i)}
|
||||||
@@ -184,13 +161,6 @@ export function BucketViewer({
|
|||||||
<></>
|
<></>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
{showDownloadLoadingOnFile.get(data.fileName) ? (
|
|
||||||
downloadingMessageComponent ?? (
|
|
||||||
<label>Downloading file...</label>
|
|
||||||
)
|
|
||||||
) : (
|
|
||||||
<></>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</ul>
|
</ul>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -95,23 +95,3 @@ export const WithComponentOnHoverOfEachBucketFile: Story = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
export const WithLoadingComponentWhileDownloadTheBucketFile: Story = {
|
|
||||||
name: 'With loading component while download the bucket file',
|
|
||||||
args: {
|
|
||||||
domain: 'https://ssen-smart-meter.datopian.workers.dev',
|
|
||||||
suffix: '/',
|
|
||||||
downloadConfig: { downloadingMessageComponent: 'COMPONENT....' },
|
|
||||||
dataMapperFn: async (rawData: Response) => {
|
|
||||||
const result = await rawData.json();
|
|
||||||
return result.objects.map((e) => ({
|
|
||||||
downloadFileUri: e.downloadLink,
|
|
||||||
fileName: e.key.replace(/^(\w+\/)/g, ''),
|
|
||||||
dateProps: {
|
|
||||||
date: new Date(e.uploaded),
|
|
||||||
dateFormatter: (date) => date.toLocaleDateString(),
|
|
||||||
},
|
|
||||||
}));
|
|
||||||
},
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|||||||
Reference in New Issue
Block a user