-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(pci-object-storage): download object implementation
ref: DTCORE-2889 Signed-off-by: LIDRISSI Hamid <[email protected]>
- Loading branch information
1 parent
e81600c
commit b3aa768
Showing
12 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
...ger/apps/pci-object-storage/src/pages/objects/container/object/download/Download.page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { ApiError } from '@ovh-ux/manager-core-api'; | ||
import { useNotifications } from '@ovh-ux/manager-react-components'; | ||
import { ShellContext } from '@ovh-ux/manager-react-shell-client'; | ||
import { useContext } from 'react'; | ||
import { Translation } from 'react-i18next'; | ||
import { useParams, useSearchParams } from 'react-router-dom'; | ||
import { PAGE_PREFIX } from '@/tracking.constants'; | ||
import { downloadObject, downloadStandardS3Object } from '@/api/data/objects'; | ||
|
||
export default function DownloadObjectPage() { | ||
const { projectId, storageId } = useParams(); | ||
const [searchParams] = useSearchParams(); | ||
const { tracking } = useContext(ShellContext).shell; | ||
const { addError } = useNotifications(); | ||
|
||
/** | ||
* TODO | ||
* Waiting for the objet type, | ||
* and this function should be implemented on action menu of object datagrid | ||
*/ | ||
const handleObjectDownload = (object) => { | ||
tracking.trackClick({ | ||
name: `${PAGE_PREFIX}object::download-file`, | ||
type: 'action', | ||
}); | ||
|
||
let downloadPromise = null; | ||
|
||
if (object.s3StorageType) { | ||
downloadPromise = downloadStandardS3Object( | ||
projectId, | ||
searchParams.get('region'), | ||
storageId, | ||
object, | ||
); | ||
} else { | ||
downloadPromise = downloadObject(projectId, storageId, object); | ||
} | ||
|
||
return downloadPromise | ||
.then((url: string) => { | ||
window.top.location = url; | ||
}) | ||
.catch((error: ApiError) => | ||
addError( | ||
<Translation ns="objects"> | ||
{(_t) => | ||
_t( | ||
`pci_projects_project_storages_containers_container_object_error_download`, | ||
{ | ||
message: | ||
error?.response?.data?.message || error?.message || null, | ||
}, | ||
) | ||
} | ||
</Translation>, | ||
true, | ||
), | ||
); | ||
}; | ||
|
||
return <></>; | ||
} |