-
Notifications
You must be signed in to change notification settings - Fork 357
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-7927] - Linode Create Refactor - Part 6 - Add-ons #10319
Merged
bnussman-akamai
merged 7 commits into
linode:develop
from
bnussman-akamai:M3-7927-linode-create-v2-addons
Mar 27, 2024
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
606df38
initial work
bnussman 6a98104
add changesets and other fixes
bnussman d6c9ee8
handle permissions in more places
bnussman bdaa95d
diable create button if user does not have permission
bnussman 881bf58
add more unit testing
bnussman 7b86f37
Apply suggestions from code review
bnussman-akamai 8a453e6
memoize selected region
bnussman 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@linode/api-v4": Changed | ||
--- | ||
|
||
Added jsdoc style comments to `CreateLinodeRequest` based on API documentation ([#10319](https://github.com/linode/manager/pull/10319)) |
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/api-v4": Changed | ||
--- | ||
|
||
Allows `firewall_id` to be `null` in `CreateLinodeRequest` ([#10319](https://github.com/linode/manager/pull/10319)) |
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-10319-upcoming-features-1711487110394.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 | ||
--- | ||
|
||
Linode Create Refactor - Part 6 - Add-ons ([#10319](https://github.com/linode/manager/pull/10319)) |
40 changes: 40 additions & 0 deletions
40
packages/manager/src/features/Linodes/LinodeCreatev2/Addons/Addons.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,40 @@ | ||
import React from 'react'; | ||
|
||
import { regionFactory } from 'src/factories'; | ||
import { makeResourcePage } from 'src/mocks/serverHandlers'; | ||
import { HttpResponse, http, server } from 'src/mocks/testServer'; | ||
import { renderWithThemeAndHookFormContext } from 'src/utilities/testHelpers'; | ||
|
||
import { Addons } from './Addons'; | ||
|
||
describe('Linode Create v2 Addons', () => { | ||
it('should render an "Add-ons" heading', () => { | ||
const { getByText } = renderWithThemeAndHookFormContext({ | ||
component: <Addons />, | ||
}); | ||
|
||
const heading = getByText('Add-ons'); | ||
|
||
expect(heading).toBeVisible(); | ||
expect(heading.tagName).toBe('H2'); | ||
}); | ||
|
||
it('renders a warning if an edge region is selected', async () => { | ||
const region = regionFactory.build({ site_type: 'edge' }); | ||
|
||
server.use( | ||
http.get('*/v4/regions', () => { | ||
return HttpResponse.json(makeResourcePage([region])); | ||
}) | ||
); | ||
|
||
const { findByText } = renderWithThemeAndHookFormContext({ | ||
component: <Addons />, | ||
useFormOptions: { defaultValues: { region: region.id } }, | ||
}); | ||
|
||
await findByText( | ||
'Backups and Private IP are currently not available for Edge regions.' | ||
); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/manager/src/features/Linodes/LinodeCreatev2/Addons/Addons.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,45 @@ | ||
import React, { useMemo } from 'react'; | ||
import { useWatch } from 'react-hook-form'; | ||
|
||
import { Divider } from 'src/components/Divider'; | ||
import { Notice } from 'src/components/Notice/Notice'; | ||
import { Paper } from 'src/components/Paper'; | ||
import { Stack } from 'src/components/Stack'; | ||
import { Typography } from 'src/components/Typography'; | ||
import { useRegionsQuery } from 'src/queries/regions/regions'; | ||
|
||
import { Backups } from './Backups'; | ||
import { PrivateIP } from './PrivateIP'; | ||
|
||
import type { CreateLinodeRequest } from '@linode/api-v4'; | ||
|
||
export const Addons = () => { | ||
const regionId = useWatch<CreateLinodeRequest, 'region'>({ name: 'region' }); | ||
|
||
const { data: regions } = useRegionsQuery(); | ||
|
||
const selectedRegion = useMemo( | ||
() => regions?.find((r) => r.id === regionId), | ||
[regions, regionId] | ||
); | ||
|
||
const isEdgeRegionSelected = selectedRegion?.site_type === 'edge'; | ||
|
||
return ( | ||
<Paper> | ||
<Stack spacing={2}> | ||
<Typography variant="h2">Add-ons</Typography> | ||
{isEdgeRegionSelected && ( | ||
<Notice | ||
text="Backups and Private IP are currently not available for Edge regions." | ||
variant="warning" | ||
/> | ||
)} | ||
<Stack divider={<Divider />} spacing={2}> | ||
<Backups /> | ||
<PrivateIP /> | ||
</Stack> | ||
</Stack> | ||
</Paper> | ||
); | ||
}; |
114 changes: 114 additions & 0 deletions
114
packages/manager/src/features/Linodes/LinodeCreatev2/Addons/Backups.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,114 @@ | ||
import { waitFor } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { | ||
accountSettingsFactory, | ||
profileFactory, | ||
regionFactory, | ||
} from 'src/factories'; | ||
import { grantsFactory } from 'src/factories/grants'; | ||
import { makeResourcePage } from 'src/mocks/serverHandlers'; | ||
import { HttpResponse, http, server } from 'src/mocks/testServer'; | ||
import { renderWithThemeAndHookFormContext } from 'src/utilities/testHelpers'; | ||
|
||
import { Backups } from './Backups'; | ||
|
||
import type { CreateLinodeRequest } from '@linode/api-v4'; | ||
|
||
describe('Linode Create V2 Backups Addon', () => { | ||
it('should render a label and checkbox', () => { | ||
const { getByLabelText } = renderWithThemeAndHookFormContext({ | ||
component: <Backups />, | ||
}); | ||
|
||
const checkbox = getByLabelText('Backups', { exact: false }); | ||
|
||
expect(checkbox).toBeEnabled(); | ||
expect(checkbox).not.toBeChecked(); | ||
}); | ||
|
||
it('should get its value from the form context', () => { | ||
const { | ||
getByRole, | ||
} = renderWithThemeAndHookFormContext<CreateLinodeRequest>({ | ||
component: <Backups />, | ||
useFormOptions: { defaultValues: { backups_enabled: true } }, | ||
}); | ||
|
||
const checkbox = getByRole('checkbox'); | ||
|
||
expect(checkbox).toBeEnabled(); | ||
expect(checkbox).toBeChecked(); | ||
}); | ||
|
||
it('should render special copy, be checked, and be disabled if account backups are enabled', async () => { | ||
server.use( | ||
http.get('*/v4/account/settings', () => { | ||
return HttpResponse.json( | ||
accountSettingsFactory.build({ backups_enabled: true }) | ||
); | ||
}) | ||
); | ||
|
||
const { findByText, getByRole } = renderWithThemeAndHookFormContext({ | ||
component: <Backups />, | ||
}); | ||
|
||
const checkbox = getByRole('checkbox'); | ||
|
||
await findByText('You have enabled automatic backups for your account.', { | ||
exact: false, | ||
}); | ||
|
||
expect(checkbox).toBeDisabled(); | ||
expect(checkbox).toBeChecked(); | ||
}); | ||
|
||
it('should be disabled if an edge region is selected', async () => { | ||
const region = regionFactory.build({ site_type: 'edge' }); | ||
|
||
server.use( | ||
http.get('*/v4/regions', () => { | ||
return HttpResponse.json(makeResourcePage([region])); | ||
}) | ||
); | ||
|
||
const { | ||
getByRole, | ||
} = renderWithThemeAndHookFormContext<CreateLinodeRequest>({ | ||
component: <Backups />, | ||
useFormOptions: { defaultValues: { region: region.id } }, | ||
}); | ||
|
||
const checkbox = getByRole('checkbox'); | ||
|
||
await waitFor(() => { | ||
expect(checkbox).toBeDisabled(); | ||
}); | ||
}); | ||
|
||
it('should be disabled if the user does not have permission to create a linode', async () => { | ||
server.use( | ||
http.get('*/v4/profile', () => { | ||
return HttpResponse.json(profileFactory.build({ restricted: true })); | ||
}), | ||
http.get('*/v4/profile/grants', () => { | ||
return HttpResponse.json( | ||
grantsFactory.build({ global: { add_linodes: false } }) | ||
); | ||
}) | ||
); | ||
|
||
const { | ||
getByRole, | ||
} = renderWithThemeAndHookFormContext<CreateLinodeRequest>({ | ||
component: <Backups />, | ||
}); | ||
|
||
const checkbox = getByRole('checkbox'); | ||
|
||
await waitFor(() => { | ||
expect(checkbox).toBeDisabled(); | ||
}); | ||
}); | ||
}); |
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.
There are other notices that will need to be added here related to cloning. I will add those when I add cloning support down the road.