-
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 user policy json
ref: DTCORE-2880 Signed-off-by: LIDRISSI Hamid <[email protected]>
- Loading branch information
1 parent
f486ebe
commit a52511a
Showing
6 changed files
with
129 additions
and
40 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
37 changes: 0 additions & 37 deletions
37
packages/manager/apps/pci-object-storage/src/components/Actions.component.tsx
This file was deleted.
Oops, something went wrong.
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
94 changes: 94 additions & 0 deletions
94
packages/manager/apps/pci-object-storage/src/pages/objects/container/users/Actions.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,94 @@ | ||
import { Translation, useTranslation } from 'react-i18next'; | ||
import { ActionMenu, useNotifications } from '@ovh-ux/manager-react-components'; | ||
import { useParams } from 'react-router-dom'; | ||
import { ApiError } from '@ovh-ux/manager-core-api'; | ||
import { useContext } from 'react'; | ||
import { ShellContext } from '@ovh-ux/manager-react-shell-client'; | ||
import { getUserStoragePolicy, TUser } from '@/api/data/user'; | ||
import { DOWNLOAD_FILENAME, DOWNLOAD_TYPE } from '@/constants'; | ||
import { downloadContent } from '@/utils'; | ||
|
||
export default function ActionsComponent({ user }: { user: TUser }) { | ||
const { t } = useTranslation('objects/users'); | ||
const { t: tPciStoragesContainers } = useTranslation( | ||
'pci-storages-containers', | ||
); | ||
|
||
const { projectId } = useParams(); | ||
const { addSuccess, addError } = useNotifications(); | ||
const { tracking } = useContext(ShellContext).shell; | ||
|
||
const downloadUserPolicyJson = () => { | ||
tracking?.trackClick({ | ||
name: 's3-policies-users::download-json', | ||
type: 'action', | ||
}); | ||
|
||
getUserStoragePolicy(projectId, user?.id) | ||
.then(({ policy }) => { | ||
downloadContent({ | ||
fileContent: policy, | ||
fileName: DOWNLOAD_FILENAME, | ||
downloadType: DOWNLOAD_TYPE, | ||
}); | ||
|
||
addSuccess( | ||
<Translation ns="objects/users"> | ||
{(_t) => | ||
_t( | ||
'pci_projects_project_storages_containers_users_import_success_message', | ||
{ user: user.username }, | ||
) | ||
} | ||
</Translation>, | ||
true, | ||
); | ||
}) | ||
.catch((error: ApiError) => | ||
addError( | ||
<Translation ns="objects/users"> | ||
{(_t) => | ||
_t( | ||
'pci_projects_project_storages_containers_users_import_error_message', | ||
{ | ||
message: | ||
error?.response?.data?.message || error?.message || null, | ||
}, | ||
) | ||
} | ||
</Translation>, | ||
true, | ||
), | ||
); | ||
}; | ||
|
||
const items = [ | ||
{ | ||
id: 0, | ||
label: t('pci_projects_project_storages_containers_users_import_json'), | ||
}, | ||
{ | ||
id: 1, | ||
label: t('pci_projects_project_storages_containers_users_download_json'), | ||
onclick: downloadUserPolicyJson, | ||
}, | ||
{ | ||
id: 2, | ||
label: t( | ||
'pci_projects_project_storages_containers_users_download_rclone_file', | ||
), | ||
}, | ||
{ | ||
id: 3, | ||
label: t('pci_projects_project_storages_containers_users_see_secret_key'), | ||
}, | ||
{ | ||
id: 4, | ||
label: tPciStoragesContainers( | ||
'pci_projects_project_storages_containers_delete_label', | ||
), | ||
}, | ||
]; | ||
|
||
return <ActionMenu items={items} isCompact />; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const downloadContent = ({ | ||
fileContent, | ||
fileName, | ||
downloadType, | ||
}: { | ||
fileContent: string; | ||
fileName: string; | ||
downloadType: string; | ||
}) => { | ||
const blob = new Blob([fileContent], { type: downloadType }); | ||
const link = document.createElement('a'); | ||
link.href = URL.createObjectURL(blob); | ||
link.download = fileName; | ||
|
||
document.body.appendChild(link); | ||
link.click(); | ||
|
||
document.body.removeChild(link); | ||
}; |