Skip to content

Commit e042ebc

Browse files
committed
fix: wrong access token export from table
1 parent 6947113 commit e042ebc

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

__tests__/useLinks.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe('useLinks', () => {
4040
accessGrants: [
4141
{
4242
metadata: { name: 'test-grant' },
43-
status: { message: 'OK' }
43+
status: { status: 'Ready', url: 'u', code: 'c', ca: 'ca', message: 'OK' }
4444
}
4545
],
4646
accessTokens: [

src/console/pages/tabs/Links/GrantsTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const AccessGrantTable: FC<AccessGrantTableProps> = function ({ grants, onDelete
4242
onClick={() => onDownloadGrant(grantData.rawData)}
4343
variant="link"
4444
isDisabled={
45-
!grantData.status ||
45+
grantData.rawData?.status?.status !== 'Ready' ||
4646
grantData.hasError ||
4747
new Date() > new Date(grantData.expirationTime as ISO8601Timestamp) ||
4848
(grantData.redemptions || 0) >= (grantData.redemptionsAllowed || 0)

src/console/pages/tabs/Links/hooks/useLinks.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useMutation } from '@tanstack/react-query';
44
import { stringify } from 'yaml';
55

66
import { handleYamlFilename } from '../../../../core/utils/handleYamlFilename';
7+
import { createAccessTokenRequest } from '../../../../core/utils/createCRD';
78
import { useWatchedSkupperResource } from '../../../../hooks/useSkupperWatchResource';
89

910
export const useLinks = () => {
@@ -43,9 +44,20 @@ export const useLinks = () => {
4344
};
4445

4546
const handleDownloadGrant = (grant: AccessGrantCrdResponse) => {
46-
if (grant?.status) {
47-
const blob = new Blob([stringify(grant)], { type: 'application/json' });
48-
const filename = handleYamlFilename(grant.metadata.name);
47+
const isReady = grant?.status?.status === 'Ready';
48+
if (isReady) {
49+
const accessToken = createAccessTokenRequest({
50+
metadata: { name: grant.metadata.name },
51+
spec: {
52+
linkCost: 1,
53+
ca: grant.status!.ca,
54+
code: grant.status!.code,
55+
url: grant.status!.url
56+
}
57+
});
58+
59+
const blob = new Blob([stringify(accessToken)], { type: 'application/json' });
60+
const filename = handleYamlFilename(accessToken.metadata.name);
4961

5062
const link = document.createElement('a');
5163
link.href = window.URL.createObjectURL(blob);

0 commit comments

Comments
 (0)