-
Notifications
You must be signed in to change notification settings - Fork 365
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
upcoming: [M3-7726] - Assign Linodes to Placement Group Drawer #10140
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
35dccda
Improve add IP drawer
abailly-akamai f5a1418
Initial commit - save work
abailly-akamai 78681a8
Post rebase fixes
abailly-akamai 2b28917
Cleanup and sorting improvements
abailly-akamai 7a02ee0
Cleanup and sorting improvements
abailly-akamai 0cf5b2d
Adding unit tests
abailly-akamai d48e8bd
Cleanup
abailly-akamai 5198128
Added changeset: Placement GroupLinode List
abailly-akamai ea022ed
Save progress
abailly-akamai d8567bb
Save progress
abailly-akamai a6dcd27
Save progress
abailly-akamai 65cb23f
saving work
abailly-akamai ffc027d
wrap up
abailly-akamai dfde78b
Cleanup and tests
abailly-akamai 4d60040
Post rebase diff fix
abailly-akamai 39c6bf4
Text fix and cleanup
abailly-akamai e89bbe0
Better querying
abailly-akamai d1fdc5a
Added changeset: Add AssignLinodesToPlacementGroup drawer
abailly-akamai d75f5f6
Better test
abailly-akamai 8ca63f2
Fix typo
abailly-akamai b1a1d10
Feedback
abailly-akamai e081339
Ooops await
abailly-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
This file contains 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 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
5 changes: 5 additions & 0 deletions
5
packages/manager/.changeset/pr-10140-upcoming-features-1707331683987.md
This file contains 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 | ||
--- | ||
|
||
Add AssignLinodesToPlacementGroup drawer ([#10140](https://github.com/linode/manager/pull/10140)) |
This file contains 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,6 +1,7 @@ | ||
import Close from '@mui/icons-material/Close'; | ||
import * as React from 'react'; | ||
|
||
import { Box } from 'src/components/Box'; | ||
import { IconButton } from 'src/components/IconButton'; | ||
|
||
import { | ||
|
@@ -13,6 +14,8 @@ import { | |
StyledScrollBox, | ||
} from './RemovableSelectionsList.style'; | ||
|
||
import type { SxProps, Theme } from '@mui/material'; | ||
|
||
export type RemovableItem = { | ||
id: number; | ||
label: string; | ||
|
@@ -29,7 +32,11 @@ export interface RemovableSelectionsListProps { | |
/** | ||
* The descriptive text to display above the list | ||
*/ | ||
headerText: string; | ||
headerText: JSX.Element | string; | ||
/** | ||
* The id of the list component | ||
*/ | ||
id?: string; | ||
/** | ||
* If false, hide the remove button | ||
*/ | ||
|
@@ -60,6 +67,10 @@ export interface RemovableSelectionsListProps { | |
* The data to display in the list | ||
*/ | ||
selectionData: RemovableItem[]; | ||
/** | ||
* Additional styles to apply to the component | ||
*/ | ||
sx?: SxProps<Theme>; | ||
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. Improving the |
||
} | ||
|
||
export const RemovableSelectionsList = ( | ||
|
@@ -68,13 +79,15 @@ export const RemovableSelectionsList = ( | |
const { | ||
LabelComponent, | ||
headerText, | ||
id, | ||
isRemovable = true, | ||
maxHeight = 427, | ||
maxWidth = 416, | ||
noDataText, | ||
onRemove, | ||
preferredDataLabel, | ||
selectionData, | ||
sx, | ||
} = props; | ||
|
||
// used to determine when to display a box-shadow to indicate scrollability | ||
|
@@ -92,11 +105,12 @@ export const RemovableSelectionsList = ( | |
}; | ||
|
||
return ( | ||
<> | ||
<Box data-testid={id} sx={sx}> | ||
<SelectedOptionsHeader>{headerText}</SelectedOptionsHeader> | ||
{selectionData.length > 0 ? ( | ||
<StyledBoxShadowWrapper | ||
displayShadow={listHeight > maxHeight} | ||
id={id} | ||
maxWidth={maxWidth} | ||
> | ||
<StyledScrollBox maxHeight={maxHeight} maxWidth={maxWidth}> | ||
|
@@ -132,10 +146,10 @@ export const RemovableSelectionsList = ( | |
</StyledScrollBox> | ||
</StyledBoxShadowWrapper> | ||
) : ( | ||
<StyledNoAssignedLinodesBox maxWidth={maxWidth}> | ||
<StyledNoAssignedLinodesBox id={id} maxWidth={maxWidth}> | ||
<StyledLabel>{noDataText}</StyledLabel> | ||
</StyledNoAssignedLinodesBox> | ||
)} | ||
</> | ||
</Box> | ||
); | ||
}; |
This file contains 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 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
140 changes: 140 additions & 0 deletions
140
packages/manager/src/features/PlacementGroups/PlacementGroupsAssignLinodesDrawer.test.tsx
This file contains 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,140 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { | ||
linodeFactory, | ||
placementGroupFactory, | ||
regionFactory, | ||
} from 'src/factories'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { PlacementGroupsAssignLinodesDrawer } from './PlacementGroupsAssignLinodesDrawer'; | ||
|
||
const queryMocks = vi.hoisted(() => ({ | ||
useAllLinodesQuery: vi.fn().mockReturnValue({}), | ||
useAssignLinodesToPlacementGroup: vi.fn().mockReturnValue({}), | ||
useRegionsQuery: vi.fn().mockReturnValue({}), | ||
useUnpaginatedPlacementGroupsQuery: vi.fn().mockReturnValue({}), | ||
})); | ||
|
||
vi.mock('src/queries/linodes/linodes', async () => { | ||
const actual = await vi.importActual('src/queries/linodes/linodes'); | ||
return { | ||
...actual, | ||
useAllLinodesQuery: queryMocks.useAllLinodesQuery, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/placementGroups', async () => { | ||
const actual = await vi.importActual('src/queries/placementGroups'); | ||
return { | ||
...actual, | ||
useUnpaginatedPlacementGroupsQuery: | ||
queryMocks.useUnpaginatedPlacementGroupsQuery, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/regions', async () => { | ||
const actual = await vi.importActual('src/queries/regions'); | ||
return { | ||
...actual, | ||
useRegionsQuery: queryMocks.useRegionsQuery, | ||
}; | ||
}); | ||
|
||
vi.mock('src/queries/placementGroups', async () => { | ||
const actual = await vi.importActual('src/queries/placementGroups'); | ||
return { | ||
...actual, | ||
useAssignLinodesToPlacementGroup: | ||
queryMocks.useAssignLinodesToPlacementGroup, | ||
}; | ||
}); | ||
|
||
describe('PlacementGroupsAssignLinodesDrawer', () => { | ||
it('should render the error state', () => { | ||
queryMocks.useAllLinodesQuery.mockReturnValue({ | ||
error: [{ reason: 'Not found' }], | ||
}); | ||
|
||
const { getByText } = renderWithTheme( | ||
<PlacementGroupsAssignLinodesDrawer | ||
numberOfPlacementGroupsCreated={9} | ||
onClose={vi.fn()} | ||
open={true} | ||
selectedPlacementGroup={placementGroupFactory.build()} | ||
/> | ||
); | ||
|
||
expect( | ||
getByText( | ||
'There was a problem retrieving your placement group. Please try again' | ||
) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render the drawer components', () => { | ||
queryMocks.useAllLinodesQuery.mockReturnValue({ | ||
data: [ | ||
linodeFactory.build({ id: 1, label: 'Linode-1', region: 'us-east' }), | ||
linodeFactory.build({ id: 2, label: 'Linode-2', region: 'us-east' }), | ||
linodeFactory.build({ id: 11, label: 'Linode-11', region: 'us-east' }), | ||
], | ||
}); | ||
queryMocks.useRegionsQuery.mockReturnValue(regionFactory.buildList(5)); | ||
queryMocks.useUnpaginatedPlacementGroupsQuery.mockReturnValue({ | ||
data: placementGroupFactory.build(), | ||
}); | ||
queryMocks.useAssignLinodesToPlacementGroup.mockReturnValue( | ||
placementGroupFactory.build({ | ||
linode_ids: [1, 2, 0, 1, 2, 3, 5, 6, 7, 8, 43, 11], | ||
}) | ||
); | ||
|
||
const { | ||
getByPlaceholderText, | ||
getByRole, | ||
getByTestId, | ||
getByText, | ||
} = renderWithTheme( | ||
<PlacementGroupsAssignLinodesDrawer | ||
selectedPlacementGroup={placementGroupFactory.build({ | ||
affinity_type: 'anti_affinity', | ||
label: 'PG-1', | ||
region: 'us-east', | ||
})} | ||
onClose={vi.fn()} | ||
open={true} | ||
/> | ||
); | ||
|
||
const linodesSelect = getByPlaceholderText('Select a Linode'); | ||
const addLinodeButton = getByRole('button', { name: 'Add Linode' }); | ||
const removableLinodesList = getByTestId('pg-linode-removable-list'); | ||
|
||
expect(linodesSelect).toBeInTheDocument(); | ||
expect(addLinodeButton).toHaveAttribute('aria-disabled', 'true'); | ||
expect(removableLinodesList).toHaveTextContent( | ||
'No Linodes have been assigned.' | ||
); | ||
|
||
fireEvent.focus(linodesSelect); | ||
fireEvent.change(linodesSelect, { target: { value: 'Linode-11' } }); | ||
const optionElement = getByText('Linode-11'); | ||
fireEvent.click(optionElement); | ||
|
||
expect(addLinodeButton).not.toHaveAttribute('aria-disabled', 'true'); | ||
|
||
fireEvent.click(getByRole('button', { name: 'Add Linode' })); | ||
|
||
expect(addLinodeButton).toHaveAttribute('aria-disabled', 'true'); | ||
expect(removableLinodesList).toHaveTextContent('Linode-11'); | ||
|
||
const removeButton = getByRole('button', { name: 'remove Linode-11' }); | ||
fireEvent.click(removeButton); | ||
|
||
expect(removableLinodesList).toHaveTextContent( | ||
'No Linodes have been assigned.' | ||
); | ||
}); | ||
}); |
Oops, something went wrong.
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.
I've updated utils to read "linode(s)" instead of "VM(s)" for consistency since VM is more of of product name and linode is more clear in code