-
Notifications
You must be signed in to change notification settings - Fork 367
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-7614] - Placement Groups Create/Rename Drawers #10106
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
088fe5a
Initial commit: setting up the pieces
abailly-akamai 1a20f85
Form conditionals
abailly-akamai eab376b
Finalize create drawer
abailly-akamai 0d6375a
Save work
abailly-akamai d754e57
Cleanup after rebase
abailly-akamai 811a76f
Cleanup after rebase
abailly-akamai 2579796
Save progress
abailly-akamai 1652b5e
Cleanup and invalidation
abailly-akamai 67204ff
cleanup issue with deps
abailly-akamai 1fb4815
Tests
abailly-akamai 75f0fa2
moar covering
abailly-akamai 0b89e22
cleanup
abailly-akamai c0580da
cleanup 2
abailly-akamai 23ce347
Add drawer to empty state
abailly-akamai e9c132e
Added changeset: Placement Groups Create/Rename Drawers
abailly-akamai c2f9233
Replace enum
abailly-akamai a95dceb
Feedback
abailly-akamai 0f69156
implement hook for reusability
abailly-akamai 2289927
Feedback
abailly-akamai 56235f1
Moar Feedback
abailly-akamai 4d94acf
Moooaaaar Feedback
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-10106-upcoming-features-1706544198124.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 | ||
--- | ||
|
||
Placement Groups Create/Rename Drawers ([#10106](https://github.com/linode/manager/pull/10106)) |
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
68 changes: 68 additions & 0 deletions
68
packages/manager/src/features/PlacementGroups/PlacementGroupsCreateDrawer.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,68 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import * as React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { PlacementGroupsCreateDrawer } from './PlacementGroupsCreateDrawer'; | ||
|
||
const commonProps = { | ||
onClose: vi.fn(), | ||
onPlacementGroupCreated: vi.fn(), | ||
open: true, | ||
}; | ||
|
||
describe('PlacementGroupsCreateDrawer', () => { | ||
it('should render and have its fields enabled', () => { | ||
const { getByLabelText } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={0} | ||
{...commonProps} | ||
/> | ||
); | ||
|
||
expect(getByLabelText('Label')).toBeEnabled(); | ||
expect(getByLabelText('Region')).toBeEnabled(); | ||
expect(getByLabelText('Affinity Type')).toBeEnabled(); | ||
}); | ||
|
||
it('Affinity Type select should have the correct options', async () => { | ||
const { getByPlaceholderText, getByText } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={0} | ||
{...commonProps} | ||
/> | ||
); | ||
|
||
const inputElement = getByPlaceholderText('Select an Affinity Type'); | ||
fireEvent.focus(inputElement); | ||
|
||
fireEvent.change(inputElement, { target: { value: 'Affinity' } }); | ||
expect(getByText('Affinity')).toBeInTheDocument(); | ||
|
||
fireEvent.change(inputElement, { target: { value: 'Anti-affinity' } }); | ||
expect(getByText('Anti-affinity')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should disable the submit button when the number of placement groups created is >= to the max', () => { | ||
const { getByTestId } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={5} | ||
{...commonProps} | ||
/> | ||
); | ||
|
||
expect(getByTestId('submit')).toHaveAttribute('aria-disabled', 'true'); | ||
}); | ||
|
||
it('should populate the region select with the selected region prop', () => { | ||
const { getByLabelText } = renderWithTheme( | ||
<PlacementGroupsCreateDrawer | ||
numberOfPlacementGroupsCreated={0} | ||
selectedRegionId="us-east" | ||
{...commonProps} | ||
/> | ||
); | ||
|
||
expect(getByLabelText('Region')).toHaveValue('Newark, NJ (us-east)'); | ||
}); | ||
}); |
133 changes: 133 additions & 0 deletions
133
packages/manager/src/features/PlacementGroups/PlacementGroupsCreateDrawer.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,133 @@ | ||
import { createPlacementGroupSchema } from '@linode/validation'; | ||
import { useFormik } from 'formik'; | ||
import { useSnackbar } from 'notistack'; | ||
import * as React from 'react'; | ||
import { useQueryClient } from 'react-query'; | ||
|
||
import { Drawer } from 'src/components/Drawer'; | ||
import { useFormValidateOnChange } from 'src/hooks/useFormValidateOnChange'; | ||
import { queryKey as placementGroupQueryKey } from 'src/queries/placementGroups'; | ||
import { useCreatePlacementGroup } from 'src/queries/placementGroups'; | ||
import { useRegionsQuery } from 'src/queries/regions'; | ||
import { getErrorMap } from 'src/utilities/errorUtils'; | ||
import { | ||
handleFieldErrors, | ||
handleGeneralErrors, | ||
} from 'src/utilities/formikErrorUtils'; | ||
|
||
import { PlacementGroupsDrawerContent } from './PlacementGroupsDrawerContent'; | ||
import { MAX_NUMBER_OF_PLACEMENT_GROUPS } from './constants'; | ||
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. this is eventually going to be returned by the API |
||
|
||
import type { | ||
PlacementGroupDrawerFormikProps, | ||
PlacementGroupsCreateDrawerProps, | ||
} from './types'; | ||
|
||
export const PlacementGroupsCreateDrawer = ( | ||
props: PlacementGroupsCreateDrawerProps | ||
) => { | ||
const { | ||
numberOfPlacementGroupsCreated, | ||
onClose, | ||
onPlacementGroupCreated, | ||
open, | ||
selectedRegionId, | ||
} = props; | ||
const queryClient = useQueryClient(); | ||
const { data: regions } = useRegionsQuery(); | ||
const { mutateAsync } = useCreatePlacementGroup(); | ||
const { enqueueSnackbar } = useSnackbar(); | ||
const { | ||
hasFormBeenSubmitted, | ||
setHasFormBeenSubmitted, | ||
} = useFormValidateOnChange(); | ||
|
||
const { | ||
errors, | ||
handleBlur, | ||
handleChange, | ||
handleSubmit, | ||
isSubmitting, | ||
resetForm, | ||
setFieldValue, | ||
status, | ||
values, | ||
...rest | ||
} = useFormik({ | ||
enableReinitialize: true, | ||
initialValues: { | ||
affinity_type: '' as PlacementGroupDrawerFormikProps['affinity_type'], | ||
label: '', | ||
region: selectedRegionId ?? '', | ||
}, | ||
onSubmit( | ||
values: PlacementGroupDrawerFormikProps, | ||
{ setErrors, setStatus, setSubmitting } | ||
) { | ||
setHasFormBeenSubmitted(false); | ||
setStatus(undefined); | ||
setErrors({}); | ||
const payload = { ...values }; | ||
|
||
mutateAsync(payload) | ||
.then((response) => { | ||
setSubmitting(false); | ||
queryClient.invalidateQueries([placementGroupQueryKey]); | ||
|
||
enqueueSnackbar( | ||
`Placement Group ${payload.label} successfully created`, | ||
{ | ||
variant: 'success', | ||
} | ||
); | ||
|
||
if (onPlacementGroupCreated) { | ||
onPlacementGroupCreated(response); | ||
} | ||
onClose(); | ||
}) | ||
.catch((err) => { | ||
const mapErrorToStatus = () => | ||
setStatus({ generalError: getErrorMap([], err).none }); | ||
|
||
setSubmitting(false); | ||
handleFieldErrors(setErrors, err); | ||
handleGeneralErrors( | ||
mapErrorToStatus, | ||
err, | ||
'Error creating Placement Group.' | ||
); | ||
}); | ||
}, | ||
validateOnBlur: false, | ||
validateOnChange: hasFormBeenSubmitted, | ||
validationSchema: createPlacementGroupSchema, | ||
}); | ||
|
||
return ( | ||
<Drawer onClose={onClose} open={open} title="Create Placement Group"> | ||
<PlacementGroupsDrawerContent | ||
formik={{ | ||
errors, | ||
handleBlur, | ||
handleChange, | ||
handleSubmit, | ||
isSubmitting, | ||
resetForm, | ||
setFieldValue, | ||
status, | ||
values, | ||
...rest, | ||
}} | ||
maxNumberOfPlacementGroups={MAX_NUMBER_OF_PLACEMENT_GROUPS} | ||
mode="create" | ||
numberOfPlacementGroupsCreated={numberOfPlacementGroupsCreated} | ||
onClose={onClose} | ||
open={open} | ||
regions={regions ?? []} | ||
selectedRegionId={selectedRegionId} | ||
setHasFormBeenSubmitted={setHasFormBeenSubmitted} | ||
/> | ||
</Drawer> | ||
); | ||
}; |
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,3 +1,4 @@ | ||
import { AFFINITY_TYPES } from '@linode/api-v4'; | ||
import * as React from 'react'; | ||
import { useHistory, useParams } from 'react-router-dom'; | ||
|
||
|
@@ -17,7 +18,7 @@ import { | |
} from 'src/queries/placementGroups'; | ||
import { getErrorStringOrDefault } from 'src/utilities/errorUtils'; | ||
|
||
import { getAffinityLabel, getPlacementGroupLinodeCount } from '../utils'; | ||
import { getPlacementGroupLinodeCount } from '../utils'; | ||
|
||
export const PlacementGroupsDetail = () => { | ||
const flags = useFlags(); | ||
|
@@ -36,6 +37,10 @@ export const PlacementGroupsDetail = () => { | |
} = useMutatePlacementGroup(placementGroupId); | ||
const errorText = getErrorStringOrDefault(updatePlacementGroupError ?? ''); | ||
|
||
if (isLoading) { | ||
return <CircleProgress />; | ||
} | ||
|
||
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. otherwise "Not Found" was showing instead of our loading state |
||
if (!placementGroup) { | ||
return <NotFound />; | ||
} | ||
|
@@ -46,10 +51,6 @@ export const PlacementGroupsDetail = () => { | |
); | ||
} | ||
|
||
if (isLoading) { | ||
return <CircleProgress />; | ||
} | ||
|
||
const linodeCount = getPlacementGroupLinodeCount(placementGroup); | ||
const tabs = [ | ||
{ | ||
|
@@ -62,11 +63,10 @@ export const PlacementGroupsDetail = () => { | |
}, | ||
]; | ||
const { affinity_type, label } = placementGroup; | ||
const affinityLabel = getAffinityLabel(affinity_type); | ||
const tabIndex = tab ? tabs.findIndex((t) => t.routeName.endsWith(tab)) : -1; | ||
|
||
const resetEditableLabel = () => { | ||
return `${label} (${affinityLabel})`; | ||
return `${label} (${AFFINITY_TYPES[affinity_type]})`; | ||
}; | ||
|
||
const handleLabelEdit = (newLabel: string) => { | ||
|
@@ -90,7 +90,7 @@ export const PlacementGroupsDetail = () => { | |
], | ||
onEditHandlers: { | ||
editableTextTitle: label, | ||
editableTextTitleSuffix: ` (${affinityLabel})`, | ||
editableTextTitleSuffix: ` (${AFFINITY_TYPES[affinity_type]})`, | ||
errorText, | ||
onCancel: resetEditableLabel, | ||
onEdit: handleLabelEdit, | ||
|
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.
from updated API specs