-
Notifications
You must be signed in to change notification settings - Fork 407
feat: [UIE-8672, UIE-8702, UIE-8703] - IAM RBAC: fix bugs #12062
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
cpathipa
merged 5 commits into
linode:develop
from
aaleksee-akamai:UIE-8672-fix-empty-state
Apr 22, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
cd679a3
feat: [UIE-8672, UIE-8702, UIE-8703] - IAM RBAC: bugs with entities cβ¦
aaleksee-akamai f4e0939
Added changeset: fix bugs with entities component and loading state fβ¦
aaleksee-akamai 63150ae
clean up Entities component and add tests
aaleksee-akamai 26b8f7a
resolve conflicts
aaleksee-akamai 799f0d6
typo
aaleksee-akamai 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-12062-upcoming-features-1744990576571.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": Upcoming Features | ||
| --- | ||
|
|
||
| IAM RBAC: Fix bugs in the Entities component and the loading state for tabs ([#12062](https://github.com/linode/manager/pull/12062)) |
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
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
68 changes: 68 additions & 0 deletions
68
packages/manager/src/features/IAM/Shared/Entities/utils.test.ts
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,68 @@ | ||
| import { accountEntityFactory } from 'src/factories/accountEntities'; | ||
|
Contributor
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. Thank you for the test coverage! |
||
|
|
||
| import { | ||
| getCreateLinkForEntityType, | ||
| getEntitiesByType, | ||
| getPlaceholder, | ||
| placeholderMap, | ||
| } from './utils'; | ||
|
|
||
| describe('getCreateLinkForEntityType', () => { | ||
| it('should return the correct create link for a given entity type', () => { | ||
| expect(getCreateLinkForEntityType('linode')).toBe('/linodes/create'); | ||
| expect(getCreateLinkForEntityType('volume')).toBe('/volumes/create'); | ||
| expect(getCreateLinkForEntityType('firewall')).toBe('/firewalls/create'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getPlaceholder', () => { | ||
| it('should return a space if currentValueLength is greater than 0', () => { | ||
| expect(getPlaceholder('linode', 1, 10)).toBe(' '); | ||
| }); | ||
|
|
||
| it('should return "None" if possibleEntitiesLength is 0', () => { | ||
| expect(getPlaceholder('linode', 0, 0)).toBe('None'); | ||
| }); | ||
|
|
||
| it('should return the placeholder from placeholderMap if type exists', () => { | ||
| expect(getPlaceholder('linode', 0, 10)).toBe(placeholderMap['linode']); | ||
| }); | ||
| }); | ||
|
|
||
| describe('getEntitiesByType', () => { | ||
| it('should return entities of the type "linode', () => { | ||
| const mockEntities = [ | ||
| ...accountEntityFactory.buildList(3, { | ||
| type: 'linode', | ||
| }), | ||
| accountEntityFactory.build({ | ||
| type: 'firewall', | ||
| }), | ||
| ]; | ||
|
|
||
| const result = getEntitiesByType('linode', mockEntities); | ||
|
|
||
| expect(result).toEqual([ | ||
| { id: 1, label: 'test-1' }, | ||
| { id: 2, label: 'test-2' }, | ||
| { id: 3, label: 'test-3' }, | ||
| ]); | ||
| }); | ||
|
|
||
| it('should return entities of the type "linode', () => { | ||
| const mockEntities = [ | ||
| ...accountEntityFactory.buildList(3, { | ||
| type: 'linode', | ||
| }), | ||
| accountEntityFactory.build({ | ||
| id: 1, | ||
| label: 'firewall-1', | ||
| type: 'firewall', | ||
| }), | ||
| ]; | ||
|
|
||
| const result = getEntitiesByType('firewall', mockEntities); | ||
|
|
||
| expect(result).toEqual([{ id: 1, label: 'firewall-1' }]); | ||
| }); | ||
| }); | ||
66 changes: 66 additions & 0 deletions
66
packages/manager/src/features/IAM/Shared/Entities/utils.ts
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,66 @@ | ||
| import { groupAccountEntitiesByType } from '../utilities'; | ||
|
|
||
| import type { EntitiesOption } from '../types'; | ||
| import type { | ||
| AccountEntity, | ||
| EntityType, | ||
| EntityTypePermissions, | ||
| } from '@linode/api-v4'; | ||
|
|
||
| export const placeholderMap: Record<string, string> = { | ||
| account: 'Select Account', | ||
| database: 'Select Databases', | ||
| domain: 'Select Domains', | ||
| firewall: 'Select Firewalls', | ||
| image: 'Select Images', | ||
| linode: 'Select Linodes', | ||
| longview: 'Select Longviews', | ||
| nodebalancer: 'Select Nodebalancers', | ||
| stackscript: 'Select Stackscripts', | ||
| volume: 'Select Volumes', | ||
| vpc: 'Select VPCs', | ||
| }; | ||
|
|
||
| export const getCreateLinkForEntityType = ( | ||
| entityType: EntityType | EntityTypePermissions | ||
| ): string => { | ||
| // TODO - find the exceptions to this rule - most use the route of /{entityType}s/create (note the "s") | ||
| return `/${entityType}s/create`; | ||
| }; | ||
|
|
||
| export const getPlaceholder = ( | ||
| type: EntityType | EntityTypePermissions, | ||
| currentValueLength: number, | ||
| possibleEntitiesLength: number | ||
| ): string => { | ||
| let placeholder: string; | ||
|
|
||
| if (currentValueLength > 0) { | ||
| placeholder = ' '; | ||
| } else if (possibleEntitiesLength === 0) { | ||
| placeholder = 'None'; | ||
| } else { | ||
| placeholder = placeholderMap[type] || 'Select'; | ||
| } | ||
|
|
||
| return placeholder; | ||
| }; | ||
|
|
||
| export const mapEntitiesToOptions = ( | ||
| entities: { id: number; label: string }[] | ||
| ): EntitiesOption[] => { | ||
| return entities.map((entity) => ({ | ||
| label: entity.label, | ||
| value: entity.id, | ||
| })); | ||
| }; | ||
|
|
||
| export const getEntitiesByType = ( | ||
| roleEntityType: EntityType | EntityTypePermissions, | ||
| entities: AccountEntity[] | ||
| ): Pick<AccountEntity, 'id' | 'label'>[] | undefined => { | ||
| const entitiesMap = groupAccountEntitiesByType(entities); | ||
|
|
||
| // Find the first matching entity by type | ||
| return entitiesMap.get(roleEntityType as EntityType); | ||
| }; |
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,4 @@ | ||
| export interface EntitiesOption { | ||
| label: string; | ||
| value: number; | ||
| } |
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.
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.
since, I've added renderInput with textField, that
errorTextstops working