Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/console/core/utils/handleYamlFilename.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function handleYamlFilename(filename: string): string {
const yamlExtensions: string[] = ['.yaml', '.yml'];
const hasExtension: boolean = yamlExtensions.some((extension) => filename.toLowerCase().endsWith(extension));

if (hasExtension) {
return filename;
}

return `${filename}.yaml`;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useTranslation } from 'react-i18next';
import { stringify } from 'yaml';

import { createAccessTokenRequest } from '../../../../core/utils/createCRD';
import { handleYamlFilename } from '../../../../core/utils/handleYamlFilename';
import { AccessTokenCrdParams } from '../../../../interfaces/CRD_AccessToken';

export const DownloadGrant: FC<{
Expand All @@ -37,11 +38,12 @@ export const DownloadGrant: FC<{
});

const blob = new Blob([stringify(accessToken)], { type: 'application/json' });
const filename = handleYamlFilename(accessToken.metadata.name);

const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = `${accessToken.metadata.name}.yaml`;
link.setAttribute('download', `${accessToken.metadata.name}.yaml`);
link.download = filename;
link.setAttribute('download', filename);

document.body.appendChild(link).click();
document.body.removeChild(link);
Expand Down
5 changes: 4 additions & 1 deletion src/console/pages/tabs/Links/hooks/useLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AccessGrantCrdResponse } from '@interfaces/CRD_AccessGrant';
import { useMutation } from '@tanstack/react-query';
import { stringify } from 'yaml';

import { handleYamlFilename } from '../../../../core/utils/handleYamlFilename';
import { useWatchedSkupperResource } from '../../../../hooks/useSkupperWatchResource';

export const useLinks = () => {
Expand Down Expand Up @@ -44,9 +45,11 @@ export const useLinks = () => {
const handleDownloadGrant = (grant: AccessGrantCrdResponse) => {
if (grant?.status) {
const blob = new Blob([stringify(grant)], { type: 'application/json' });
const filename = handleYamlFilename(grant.metadata.name);

const link = document.createElement('a');
link.href = window.URL.createObjectURL(blob);
link.download = `${grant.metadata.name}.yaml`;
link.download = filename;
document.body.appendChild(link).click();
document.body.removeChild(link);
}
Expand Down
Loading