Repository navigation
change: [M3-7729] - Improve UX of Personal Access Token and Access Key drawers #10338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mjac0bs
merged 17 commits into
linode:develop
from
mjac0bs:M3-7729-improve-pat-and-obj-access-key-drawers
Apr 18, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2f22814
Update Select All from 'None' to 'No Access' and add border
97b2c3b
Disable the Create Token button until scope selection is made
b180ffa
Add test coverage
53f5470
Apply Select All row styling; fix radio state without regions
0c98fe5
Fix default bucket access selection to no selection
a370a95
Add util and logic to disable create button; add test
cee94ab
Update PAT test to account for UI updates
676c5ae
Update one more test
0e0f0fc
Fix type
4c13e9e
Added changeset: Improve the UX of access key drawers
4fbb60f
Clean up
0255704
Update packages/manager/.changeset/pr-10338-changed-1712685790473.md
mjac0bs 4ebb56b
Merge branch 'develop' into M3-7729-improve-pat-and-obj-access-key-drβ¦
5e8b3e8
Address feedback: disable button if any missing scope selections
cb831e4
Update PAT test coverage
7403ee1
Use new scope interface for displayed access key scopes
75480fc
Clean up types and exports
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10338-changed-1712685790473.md
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@linode/manager": Changed | ||
| --- | ||
|
|
||
| Improve the UX of Access Token & Access Key drawers ([#10338](https://github.com/linode/manager/pull/10338)) |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -35,7 +35,11 @@ import { confirmObjectStorage } from '../utilities'; | |
| import { AccessKeyRegions } from './AccessKeyRegions/AccessKeyRegions'; | ||
| import { LimitedAccessControls } from './LimitedAccessControls'; | ||
| import { MODE } from './types'; | ||
| import { generateUpdatePayload, hasLabelOrRegionsChanged } from './utils'; | ||
| import { | ||
| generateUpdatePayload, | ||
| hasAccessBeenSelectedForAllBuckets, | ||
| hasLabelOrRegionsChanged, | ||
| } from './utils'; | ||
|
|
||
| export interface AccessKeyDrawerProps { | ||
| isRestrictedUser: boolean; | ||
|
|
@@ -52,6 +56,11 @@ export interface AccessKeyDrawerProps { | |
| open: boolean; | ||
| } | ||
|
|
||
| // Access key scopes displayed in the drawer can have no permission or "No Access" selected, which are not valid API permissions. | ||
| export interface DisplayedAccessKeyScope extends Omit<Scope, 'permissions'> { | ||
| permissions: AccessType | null; | ||
| } | ||
|
|
||
| export interface FormState { | ||
| bucket_access: Scope[] | null; | ||
| label: string; | ||
|
|
@@ -66,8 +75,8 @@ export interface FormState { | |
| */ | ||
|
|
||
| export const sortByRegion = (regionLookup: { [key: string]: Region }) => ( | ||
| a: Scope, | ||
| b: Scope | ||
| a: DisplayedAccessKeyScope, | ||
| b: DisplayedAccessKeyScope | ||
| ) => { | ||
| if (!a.region || !b.region) { | ||
| return 0; | ||
|
|
@@ -82,12 +91,12 @@ export const sortByRegion = (regionLookup: { [key: string]: Region }) => ( | |
| export const getDefaultScopes = ( | ||
| buckets: ObjectStorageBucket[], | ||
| regionLookup: { [key: string]: Region } = {} | ||
| ): Scope[] => | ||
| ): DisplayedAccessKeyScope[] => | ||
| buckets | ||
| .map((thisBucket) => ({ | ||
| bucket_name: thisBucket.label, | ||
| cluster: thisBucket.cluster, | ||
| permissions: 'none' as AccessType, | ||
| permissions: null, | ||
| region: thisBucket.region, | ||
| })) | ||
| .sort(sortByRegion(regionLookup)); | ||
|
|
@@ -163,13 +172,15 @@ export const OMC_AccessKeyDrawer = (props: AccessKeyDrawerProps) => { | |
| // If the user hasn't toggled the Limited Access button, | ||
| // don't include any bucket_access information in the payload. | ||
|
|
||
| // If any/all values are 'none', don't include them in the response. | ||
| // If any/all permissions are 'none' or null, don't include them in the response. | ||
| const access = values.bucket_access ?? []; | ||
| const payload = limitedAccessChecked | ||
| ? { | ||
| ...values, | ||
| bucket_access: access.filter( | ||
| (thisAccess) => thisAccess.permissions !== 'none' | ||
| (thisAccess: DisplayedAccessKeyScope) => | ||
| thisAccess.permissions !== 'none' && | ||
| thisAccess.permissions !== null | ||
| ), | ||
| } | ||
| : { ...values, bucket_access: null }; | ||
|
|
@@ -195,7 +206,10 @@ export const OMC_AccessKeyDrawer = (props: AccessKeyDrawerProps) => { | |
| (mode !== 'creating' && | ||
| objectStorageKey && | ||
| objectStorageKey?.regions?.length > 0 && | ||
| !hasLabelOrRegionsChanged(formik.values, objectStorageKey)); | ||
| !hasLabelOrRegionsChanged(formik.values, objectStorageKey)) || | ||
| (mode === 'creating' && | ||
| limitedAccessChecked && | ||
| !hasAccessBeenSelectedForAllBuckets(formik.values.bucket_access)); | ||
|
Comment on lines
+209
to
+212
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Disables the Create button if some buckets have limited access and their scope selections have not been made. |
||
|
|
||
| const beforeSubmit = () => { | ||
| confirmObjectStorage<FormState>( | ||
|
|
||
This file contains hidden or 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 hidden or 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 |
|---|---|---|
| @@ -1,13 +1,12 @@ | ||
| import { ObjectStorageKey } from '@linode/api-v4/lib/object-storage'; | ||
|
|
||
| import { areArraysEqual } from 'src/utilities/areArraysEqual'; | ||
| import { sortByString } from 'src/utilities/sort-by'; | ||
|
|
||
| import { FormState } from './OMC_AccessKeyDrawer'; | ||
| import type { DisplayedAccessKeyScope, FormState } from './OMC_AccessKeyDrawer'; | ||
| import type { ObjectStorageKey } from '@linode/api-v4/lib/object-storage'; | ||
|
|
||
| type UpdatePayload = | ||
| | { label: FormState['label']; regions: FormState['regions'] } | ||
| | { label: FormState['label'] } | ||
| | { label: FormState['label']; regions: FormState['regions'] } | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Linter. |
||
| | { regions: FormState['regions'] } | ||
| | {}; | ||
|
|
||
|
|
@@ -71,3 +70,19 @@ export const hasLabelOrRegionsChanged = ( | |
|
|
||
| return labelChanged || regionsChanged; | ||
| }; | ||
|
|
||
| /** | ||
| * Determines whether the selection of access key scopes has been made for every bucket, | ||
| * since by default, the displayed permissions are set to null. | ||
| * | ||
| * @param bucketAccess - The array of bucket objects. | ||
| * @returns {boolean} True if all buckets have permissions set to none/read_only/read_write or if there are no buckets, false otherwise. | ||
| */ | ||
| export const hasAccessBeenSelectedForAllBuckets = ( | ||
| bucketAccess: DisplayedAccessKeyScope[] | null | ||
| ): boolean => { | ||
| if (!bucketAccess) { | ||
| return true; | ||
| } | ||
| return bucketAccess.every((bucket) => bucket.permissions !== null); | ||
| }; | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cpathipa I looked into also removing
'none'from the AccessType, but it required more clean up in the original AccessKeyDrawer files, which I wanted to avoid touching since they will be soon deprecated. I did create the new interface here for thenullvalue displayed scopes in the OMC drawer and can create a follow up ticket (edit: M3-8003) for correcting the AccessType to only the API's values once we switch to fully OMC components.