-
Notifications
You must be signed in to change notification settings - Fork 370
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
feat: [M3-7311] - Create Load Balancer flow - manage state #9848
Merged
Merged
Changes from 11 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f7bcbb9
feat: [M3-7311] - Create Load Balancer flow - Mange state.
cpathipa 3f38d91
Code cleanup
cpathipa 775bb86
Added changeset: Create Load Balancer flow - Mange state.
cpathipa af5fd8a
Update pr-9848-upcoming-features-1698675578462.md
cpathipa 69488c2
Merge remote-tracking branch 'origin/develop' into M3-7311
cpathipa 266d259
Update update-database.spec.ts
cpathipa 44027c9
Update packages/manager/.changeset/pr-9848-upcoming-features-16986755β¦
cpathipa e0ea1ba
Fix typos
cpathipa 28df367
use useFormikContext instead of custom state management hook
cpathipa 59b3534
PR feedback
cpathipa 994a104
Merge remote-tracking branch 'origin/develop' into M3-7311
cpathipa f92709a
Update loadbalancers.schema.ts
cpathipa 2d1a7e0
Update packages/validation/src/loadbalancers.schema.ts
cpathipa 2791bc3
Update packages/validation/src/loadbalancers.schema.ts
cpathipa a4dcb76
Update loadbalancers.schema.ts
cpathipa 5a547bf
Merge branch 'M3-7311' of github.com:cpathipa/manager into M3-7311
cpathipa 106f4d1
Update CreateLoadBalancerSchema and Endpoint Schema
cpathipa e5109b5
Revert "Update CreateLoadBalancerSchema and Endpoint Schema"
cpathipa 69c3038
Code cleanup and update Endpoint schema.
cpathipa 1468860
Update the field names
cpathipa d08dfb9
Added changeset: Create Load Balancer flow - manage state
cpathipa 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-9848-upcoming-features-1698675578462.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 | ||
--- | ||
|
||
Create Load Balancer flow - manage state ([#9848](https://github.com/linode/manager/pull/9848)) |
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
27 changes: 27 additions & 0 deletions
27
packages/manager/src/features/LoadBalancers/LoadBalancerCreate/LoadBalancerActionPanel.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,27 @@ | ||
import { useFormikContext } from 'formik'; | ||
import * as React from 'react'; | ||
|
||
import { Box } from 'src/components/Box'; | ||
import { Button } from 'src/components/Button/Button'; | ||
|
||
export const LoadBalancerActionPanel = () => { | ||
const { submitForm } = useFormikContext(); | ||
cpathipa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<Box | ||
columnGap={1} | ||
display="flex" | ||
flexWrap="wrap" | ||
justifyContent="space-between" | ||
rowGap={3} | ||
> | ||
<Button buttonType="outlined">Add Another Configuration</Button> | ||
<Button | ||
buttonType="primary" | ||
onClick={submitForm} | ||
sx={{ marginLeft: 'auto' }} | ||
> | ||
Review Load Balancer | ||
</Button> | ||
</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
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,15 +1,23 @@ | ||
import { createLoadBalancerSchema } from '@linode/validation'; | ||
cpathipa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import Stack from '@mui/material/Stack'; | ||
import { Form, Formik } from 'formik'; | ||
import * as React from 'react'; | ||
|
||
import { Box } from 'src/components/Box'; | ||
import { Button } from 'src/components/Button/Button'; | ||
import { DocumentTitleSegment } from 'src/components/DocumentTitle/DocumentTitle'; | ||
import { LandingHeader } from 'src/components/LandingHeader'; | ||
|
||
import { LoadBalancerActionPanel } from './LoadBalancerActionPanel'; | ||
import { LoadBalancerConfiguration } from './LoadBalancerConfiguration'; | ||
import { LoadBalancerLabel } from './LoadBalancerLabel'; | ||
import { LoadBalancerRegions } from './LoadBalancerRegions'; | ||
|
||
import type { CreateLoadbalancerPayload } from '@linode/api-v4'; | ||
|
||
const initialValues = { | ||
label: '', | ||
regions: [], | ||
}; | ||
|
||
const LoadBalancerCreate = () => { | ||
return ( | ||
<> | ||
|
@@ -26,35 +34,23 @@ const LoadBalancerCreate = () => { | |
}} | ||
title="Create" | ||
/> | ||
<Stack spacing={3}> | ||
<LoadBalancerLabel | ||
labelFieldProps={{ | ||
disabled: false, | ||
errorText: '', | ||
label: 'Linode Label', | ||
onChange: () => null, | ||
value: '', | ||
}} | ||
Comment on lines
-30
to
-37
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. Prop drilling is not required since we use a |
||
/> | ||
<LoadBalancerRegions /> | ||
<LoadBalancerConfiguration /> | ||
{/* TODO: AGLB - | ||
* Implement Review Load Balancer Action Behavior | ||
* Implement Add Another Configuration Behavior | ||
*/} | ||
<Box | ||
columnGap={1} | ||
display="flex" | ||
flexWrap="wrap" | ||
justifyContent="space-between" | ||
rowGap={3} | ||
> | ||
<Button buttonType="outlined">Add Another Configuration</Button> | ||
<Button buttonType="primary" sx={{ marginLeft: 'auto' }}> | ||
Review Load Balancer | ||
</Button> | ||
</Box> | ||
</Stack> | ||
<Formik<CreateLoadbalancerPayload> | ||
onSubmit={(values, actions) => { | ||
// TODO: AGLB - Implement form submit | ||
// console.log('Values ', values); | ||
}} | ||
initialValues={initialValues} | ||
validationSchema={createLoadBalancerSchema} | ||
cpathipa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
> | ||
<Form> | ||
<Stack spacing={3}> | ||
<LoadBalancerLabel /> | ||
<LoadBalancerRegions /> | ||
<LoadBalancerConfiguration /> | ||
<LoadBalancerActionPanel /> | ||
</Stack> | ||
</Form> | ||
cpathipa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
</Formik> | ||
</> | ||
); | ||
}; | ||
|
79 changes: 52 additions & 27 deletions
79
packages/manager/src/features/LoadBalancers/LoadBalancerCreate/LoadBalancerLabel.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 |
---|---|---|
@@ -1,49 +1,74 @@ | ||
import { fireEvent } from '@testing-library/react'; | ||
import { Formik } from 'formik'; | ||
import React from 'react'; | ||
|
||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { LoadBalancerLabel } from './LoadBalancerLabel'; | ||
|
||
const loadBalancerLabelValue = 'Test Label'; | ||
const loadBalancerTestId = 'textfield-input'; | ||
|
||
import type { CreateLoadbalancerPayload } from '@linode/api-v4'; | ||
|
||
type MockFormikContext = { | ||
initialErrors?: {}; | ||
initialTouched?: {}; | ||
initialValues: CreateLoadbalancerPayload; | ||
}; | ||
|
||
const initialValues = { | ||
label: loadBalancerLabelValue, | ||
regions: [], | ||
}; | ||
|
||
const renderWithFormikWrapper = (mockFormikContext: MockFormikContext) => | ||
renderWithTheme( | ||
<Formik {...mockFormikContext} onSubmit={jest.fn()}> | ||
<LoadBalancerLabel /> | ||
</Formik> | ||
); | ||
|
||
describe('LoadBalancerLabel', () => { | ||
it('should render the component with a label and no error', () => { | ||
const labelFieldProps = { | ||
disabled: false, | ||
errorText: '', | ||
label: 'Load Balancer Label', | ||
onChange: jest.fn(), | ||
value: 'Test Label', | ||
}; | ||
|
||
const { getByTestId, queryByText } = renderWithTheme( | ||
<LoadBalancerLabel error="" labelFieldProps={labelFieldProps} /> | ||
); | ||
|
||
const labelInput = getByTestId('textfield-input'); | ||
const { getByTestId, queryByText } = renderWithFormikWrapper({ | ||
initialValues, | ||
}); | ||
|
||
const labelInput = getByTestId(loadBalancerTestId); | ||
const errorNotice = queryByText('Error Text'); | ||
|
||
expect(labelInput).toBeInTheDocument(); | ||
expect(labelInput).toHaveAttribute('placeholder', 'Enter a label'); | ||
expect(labelInput).toHaveValue('Test Label'); | ||
expect(labelInput).toHaveValue(loadBalancerLabelValue); | ||
expect(errorNotice).toBeNull(); | ||
}); | ||
|
||
it('should render the component with an error message', () => { | ||
const labelFieldProps = { | ||
disabled: false, | ||
errorText: 'This is an error', | ||
label: 'Load Balancer Label', | ||
onChange: jest.fn(), | ||
value: 'Test Label', | ||
}; | ||
|
||
const { getByTestId, getByText } = renderWithTheme( | ||
<LoadBalancerLabel error="Error Text" labelFieldProps={labelFieldProps} /> | ||
); | ||
|
||
const labelInput = getByTestId('textfield-input'); | ||
const { getByTestId, getByText } = renderWithFormikWrapper({ | ||
initialErrors: { label: 'This is an error' }, | ||
initialTouched: { label: true }, | ||
initialValues, | ||
}); | ||
|
||
const labelInput = getByTestId(loadBalancerTestId); | ||
const errorNotice = getByText('This is an error'); | ||
|
||
expect(labelInput).toBeInTheDocument(); | ||
expect(errorNotice).toBeInTheDocument(); | ||
}); | ||
|
||
it('should update formik values on input change', () => { | ||
const { getByTestId } = renderWithFormikWrapper({ | ||
initialValues, | ||
}); | ||
|
||
const labelInput = getByTestId(loadBalancerTestId); | ||
|
||
// Simulate typing 'New Label' in the input field | ||
fireEvent.change(labelInput, { target: { value: 'New Label' } }); | ||
|
||
// Expect the input to have the new value | ||
expect(labelInput).toHaveValue('New Label'); | ||
}); | ||
}); |
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
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.
Unrelated linter change that snuck in.