Skip to content

Commit 1514c40

Browse files
refactro: STORIF-335 AccessKeysDrawerOutlet component created.
1 parent 3043445 commit 1514c40

18 files changed

Lines changed: 281 additions & 282 deletions

packages/manager/src/features/ObjectStorage/AccessKeyLanding/AccessKeyDrawer.tsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useAccountSettings } from '@linode/queries';
1+
import { useAccountSettings, useProfile } from '@linode/queries';
22
import {
33
ActionsPanel,
44
CircleProgress,
@@ -12,6 +12,7 @@ import {
1212
createObjectStorageKeysSchema,
1313
updateObjectStorageKeysSchema,
1414
} from '@linode/validation';
15+
import { useParams } from '@tanstack/react-router';
1516
import { useFormik } from 'formik';
1617
import React, { useEffect, useState } from 'react';
1718

@@ -20,6 +21,7 @@ import { useObjectStorageRegions } from 'src/features/ObjectStorage/hooks/useObj
2021
import { SecretTokenDialog } from 'src/features/Profile/SecretTokenDialog/SecretTokenDialog';
2122
import {
2223
useCreateAccessKeyMutation,
24+
useObjectStorageAccessKey,
2325
useObjectStorageBuckets,
2426
useUpdateAccessKeyMutation,
2527
} from 'src/queries/object-storage/queries';
@@ -48,12 +50,11 @@ import type {
4850
import type { FormikHelpers } from 'formik';
4951

5052
export interface AccessKeyDrawerProps {
51-
isRestrictedUser: boolean;
53+
isOpen: boolean;
5254
mode: MODE;
5355
// If the mode is 'editing', we should have an ObjectStorageKey to edit
5456
objectStorageKey?: ObjectStorageKey;
5557
onClose: () => void;
56-
open: boolean;
5758
}
5859

5960
// Access key scopes displayed in the drawer can have no permission or "No Access" selected, which are not valid API permissions.
@@ -103,7 +104,11 @@ export const getDefaultScopes = (
103104
.sort(sortByRegion(regionLookup));
104105

105106
export const AccessKeyDrawer = (props: AccessKeyDrawerProps) => {
106-
const { isRestrictedUser, mode, objectStorageKey, onClose, open } = props;
107+
const { mode, onClose, isOpen } = props;
108+
const { accessKeyId } = useParams({ strict: false });
109+
110+
const { data: profile } = useProfile();
111+
const isRestrictedUser = profile?.restricted ?? false;
107112

108113
const displayKeysDialog = useOpenClose();
109114
// Key to display in Confirmation Modal upon creation
@@ -119,6 +124,7 @@ export const AccessKeyDrawer = (props: AccessKeyDrawerProps) => {
119124
} = useObjectStorageBuckets();
120125

121126
const { data: accountSettings } = useAccountSettings();
127+
const { data: objectStorageKey } = useObjectStorageAccessKey(accessKeyId);
122128
const { mutateAsync: createAccessKey } = useCreateAccessKeyMutation();
123129
const { mutateAsync: updateAccessKey } = useUpdateAccessKeyMutation();
124130

@@ -307,13 +313,13 @@ export const AccessKeyDrawer = (props: AccessKeyDrawerProps) => {
307313
useEffect(() => {
308314
setLimitedAccessChecked(false);
309315
formik.resetForm({ values: initialValues });
310-
}, [open]);
316+
}, [isOpen]);
311317

312318
return (
313319
<>
314320
<Drawer
315321
onClose={onClose}
316-
open={open}
322+
open={isOpen}
317323
title={title}
318324
wide={createMode && hasBuckets}
319325
>
@@ -361,7 +367,7 @@ export const AccessKeyDrawer = (props: AccessKeyDrawerProps) => {
361367

362368
<TextField
363369
data-qa-add-label
364-
disabled={isRestrictedUser || mode === 'viewing'}
370+
disabled={isRestrictedUser}
365371
error={formik.touched.label ? !!formik.errors.label : false}
366372
errorText={formik.touched.label ? formik.errors.label : undefined}
367373
label="Label"

packages/manager/src/features/ObjectStorage/AccessKeyLanding/AccessKeyLanding.test.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import { renderWithTheme } from 'src/utilities/testHelpers';
55
import { AccessKeyLanding } from './AccessKeyLanding';
66

77
const props = {
8-
accessDrawerOpen: false,
9-
closeAccessDrawer: vi.fn(),
108
isRestrictedUser: false,
11-
mode: 'creating' as any,
12-
openAccessDrawer: vi.fn(),
139
};
1410

1511
describe('AccessKeyLanding', () => {

packages/manager/src/features/ObjectStorage/AccessKeyLanding/AccessKeyLanding.tsx

Lines changed: 5 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,24 @@ import {
1111
} from 'src/queries/object-storage/queries';
1212
import { getAPIErrorOrDefault } from 'src/utilities/errorUtils';
1313

14-
import { AccessKeyDrawer } from './AccessKeyDrawer';
1514
import { AccessKeyTable } from './AccessKeyTable/AccessKeyTable';
15+
import { useAccessKeyDrawers } from './hooks/useAccessKeyDrawers';
1616
import { RevokeAccessKeyDialog } from './RevokeAccessKeyDialog';
17-
import { ViewPermissionsDrawer } from './ViewPermissionsDrawer';
1817

19-
import type { MODE, OpenAccessDrawer } from './types';
2018
import type {
2119
CreateObjectStorageKeyPayload,
2220
ObjectStorageKey,
2321
} from '@linode/api-v4/lib/object-storage';
2422
import type { FormikBag } from 'formik';
2523

2624
interface Props {
27-
accessDrawerOpen: boolean;
28-
closeAccessDrawer: () => void;
2925
isRestrictedUser: boolean;
30-
mode: MODE;
31-
openAccessDrawer: (mode: MODE) => void;
3226
}
3327

3428
export type FormikProps = FormikBag<Props, CreateObjectStorageKeyPayload>;
3529

3630
export const AccessKeyLanding = (props: Props) => {
37-
const {
38-
accessDrawerOpen,
39-
closeAccessDrawer,
40-
isRestrictedUser,
41-
mode,
42-
openAccessDrawer,
43-
} = props;
31+
const { isRestrictedUser } = props;
4432

4533
const navigate = useNavigate();
4634
const pagination = usePaginationV2({
@@ -55,10 +43,8 @@ export const AccessKeyLanding = (props: Props) => {
5543
});
5644
const { mutateAsync: deleteAccessKey } = useDeleteAccessKeyMutation();
5745

58-
// Key to rename (by clicking on a key's kebab menu )
59-
const [keyToEdit, setKeyToEdit] = React.useState<null | ObjectStorageKey>(
60-
null
61-
);
46+
const { drawer } = useAccessKeyDrawers();
47+
const isCreateAccessDrawerOpen = drawer === 'create-access-key';
6248

6349
// Key to revoke (by clicking on a key's kebab menu )
6450
const [keyToRevoke, setKeyToRevoke] = React.useState<null | ObjectStorageKey>(
@@ -114,16 +100,6 @@ export const AccessKeyLanding = (props: Props) => {
114100
});
115101
};
116102

117-
const openDrawer: OpenAccessDrawer = (
118-
mode: MODE,
119-
objectStorageKey: null | ObjectStorageKey = null
120-
) => {
121-
setKeyToEdit(objectStorageKey);
122-
if (mode !== 'creating') {
123-
openAccessDrawer(mode);
124-
}
125-
};
126-
127103
const openRevokeDialog = (objectStorageKey: ObjectStorageKey) => {
128104
setKeyToRevoke(objectStorageKey);
129105
revokeKeysDialog.open();
@@ -137,15 +113,14 @@ export const AccessKeyLanding = (props: Props) => {
137113
return (
138114
<div>
139115
<DocumentTitleSegment
140-
segment={`${accessDrawerOpen ? `Create an Access Key` : `Access Keys`}`}
116+
segment={`${isCreateAccessDrawerOpen ? `Create an Access Key` : `Access Keys`}`}
141117
/>
142118
<AccessKeyTable
143119
data={data?.data}
144120
data-qa-access-key-table
145121
error={error}
146122
isLoading={isLoading}
147123
isRestrictedUser={isRestrictedUser}
148-
openDrawer={openDrawer}
149124
openRevokeDialog={openRevokeDialog}
150125
/>
151126
<PaginationFooter
@@ -157,20 +132,6 @@ export const AccessKeyLanding = (props: Props) => {
157132
pageSize={pagination.pageSize}
158133
/>
159134

160-
<AccessKeyDrawer
161-
isRestrictedUser={props.isRestrictedUser}
162-
mode={mode}
163-
objectStorageKey={keyToEdit ? keyToEdit : undefined}
164-
onClose={closeAccessDrawer}
165-
open={accessDrawerOpen}
166-
/>
167-
168-
<ViewPermissionsDrawer
169-
objectStorageKey={keyToEdit}
170-
onClose={closeAccessDrawer}
171-
open={mode === 'viewing' && accessDrawerOpen}
172-
/>
173-
174135
<RevokeAccessKeyDialog
175136
errors={revokeErrors}
176137
handleClose={closeRevokeDialog}

packages/manager/src/features/ObjectStorage/AccessKeyLanding/AccessKeyTable/AccessKeyActionMenu.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,21 @@ import { ActionMenu } from 'src/components/ActionMenu/ActionMenu';
66
import { InlineMenuAction } from 'src/components/InlineMenuAction/InlineMenuAction';
77

88
import { useIsObjMultiClusterEnabled } from '../../hooks/useIsObjectStorageGen2Enabled';
9+
import { useAccessKeyDrawers } from '../hooks/useAccessKeyDrawers';
910

10-
import type { OpenAccessDrawer } from '../types';
1111
import type { ObjectStorageKey } from '@linode/api-v4';
1212
import type { Theme } from '@mui/material';
1313

1414
interface Props {
1515
label: string;
1616
objectStorageKey: ObjectStorageKey;
17-
openDrawer: OpenAccessDrawer;
18-
openHostnamesDrawer: () => void;
1917
openRevokeDialog: (key: ObjectStorageKey) => void;
2018
}
2119

2220
export const AccessKeyActionMenu = (props: Props) => {
23-
const {
24-
label,
25-
objectStorageKey,
26-
openDrawer,
27-
openHostnamesDrawer,
28-
openRevokeDialog,
29-
} = props;
21+
const { label, objectStorageKey, openRevokeDialog } = props;
22+
23+
const { openDrawer } = useAccessKeyDrawers();
3024

3125
const { isObjMultiClusterEnabled } = useIsObjMultiClusterEnabled();
3226

@@ -37,20 +31,22 @@ export const AccessKeyActionMenu = (props: Props) => {
3731
const actions = [
3832
{
3933
onClick: () => {
40-
openDrawer('editing', objectStorageKey);
34+
openDrawer('edit-access-key', objectStorageKey.id);
4135
},
4236
title: isObjMultiClusterEnabled ? 'Edit' : 'Edit Label',
4337
},
4438
{
4539
onClick: () => {
46-
openDrawer('viewing', objectStorageKey);
40+
openDrawer('access-key-permissions', objectStorageKey.id);
4741
},
4842
title: 'Permissions',
4943
},
5044
...(isObjMultiClusterEnabled
5145
? [
5246
{
53-
onClick: openHostnamesDrawer,
47+
onClick: () => {
48+
openDrawer('access-key-hostnames', objectStorageKey.id);
49+
},
5450
title: 'View Regions/S3 Hostnames',
5551
},
5652
]

packages/manager/src/features/ObjectStorage/AccessKeyLanding/AccessKeyTable/AccessKeyTable.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ describe('ObjectStorageKeyTable', () => {
1212
error: undefined,
1313
isLoading: false,
1414
isRestrictedUser: false,
15-
openDrawer: vi.fn(),
1615
openRevokeDialog: vi.fn(),
1716
};
1817

0 commit comments

Comments
 (0)