-
Notifications
You must be signed in to change notification settings - Fork 364
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-7872] - Linode Create Refactor - StackScripts #10367
Merged
bnussman-akamai
merged 24 commits into
linode:develop
from
bnussman-akamai:M3-7872-linode-create-refactor-stackscripts
Apr 18, 2024
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
fcf7827
initial work
bnussman 0b82b26
filter options based on stackscript compatibility
bnussman e02f1c0
implement complex preselection logic
bnussman c656c1a
clean up a bit
bnussman 9a5b510
implement details dialog
bnussman 1b93698
fix some query param logic
bnussman 325ef5f
lots of behavior changes to match production
bnussman 8f1d6d6
fix image select clear behavior and fix table waypoint console error
bnussman c694197
improve validation for when image is `null`
bnussman 5148d52
first unit tests
bnussman 94fa5f4
add lots of unit testing
bnussman e4e71f6
add stackscript event handler
bnussman f56e4ad
hook up validation packages for realtime validation
bnussman 26a5e44
Merge branch 'develop' into M3-7872-linode-create-refactor-stackscripts
bnussman c464078
use default validation behavior
bnussman de158af
Revert "hook up validation packages for realtime validation"
bnussman e7f668b
handle resets when switching tabs
bnussman 5ed5f57
add changesets
bnussman 658e7ec
add some comments
bnussman fe974cb
bold label and pre-select if only one option
bnussman d53719a
improve ux
bnussman 884b4b4
fix unit tests
bnussman 09188d4
add comment
bnussman 3a8cf7a
Merge branch 'develop' into M3-7872-linode-create-refactor-stackscripts
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 | ||
--- | ||
|
||
Allow `stackscript_id` to be `null` in `CreateLinodeRequest` ([#10367](https://github.com/linode/manager/pull/10367)) |
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-10367-upcoming-features-1712868443784.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 - StackScripts ([#10367](https://github.com/linode/manager/pull/10367)) |
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
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
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
33 changes: 33 additions & 0 deletions
33
...r/src/features/Linodes/LinodeCreatev2/Tabs/StackScripts/StackScriptDetailsDialog.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,33 @@ | ||
import React from 'react'; | ||
|
||
import { stackScriptFactory } from 'src/factories'; | ||
import { HttpResponse, http, server } from 'src/mocks/testServer'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
|
||
import { StackScriptDetailsDialog } from './StackScriptDetailsDialog'; | ||
|
||
describe('StackScriptDetailsDialog', () => { | ||
it('should render StackScript data from the API', async () => { | ||
const stackscript = stackScriptFactory.build(); | ||
|
||
server.use( | ||
http.get('*/v4/linode/stackscripts/:id', () => { | ||
return HttpResponse.json(stackscript); | ||
}) | ||
); | ||
|
||
const { findByText } = renderWithTheme( | ||
<StackScriptDetailsDialog | ||
id={stackscript.id} | ||
onClose={vi.fn()} | ||
open={true} | ||
/> | ||
); | ||
|
||
await findByText(stackscript.id); | ||
await findByText(stackscript.label); | ||
await findByText(stackscript.username); | ||
await findByText(stackscript.description); | ||
await findByText(stackscript.script); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
...anager/src/features/Linodes/LinodeCreatev2/Tabs/StackScripts/StackScriptDetailsDialog.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,50 @@ | ||
import React from 'react'; | ||
|
||
import { CircleProgress } from 'src/components/CircleProgress'; | ||
import { Dialog } from 'src/components/Dialog/Dialog'; | ||
import { ErrorState } from 'src/components/ErrorState/ErrorState'; | ||
import { StackScript } from 'src/components/StackScript/StackScript'; | ||
import { useStackScriptQuery } from 'src/queries/stackscripts'; | ||
|
||
interface Props { | ||
/** | ||
* The id of the StackScript | ||
*/ | ||
id: number | undefined; | ||
/** | ||
* Function called when when the dialog is closed | ||
*/ | ||
onClose: () => void; | ||
/** | ||
* Controls the open/close state of the dialog | ||
*/ | ||
open: boolean; | ||
} | ||
|
||
export const StackScriptDetailsDialog = (props: Props) => { | ||
const { id, onClose, open } = props; | ||
|
||
const { data: stackscript, error, isLoading } = useStackScriptQuery( | ||
id ?? -1, | ||
id !== undefined | ||
); | ||
|
||
const title = stackscript | ||
? `${stackscript.username} / ${stackscript.label}` | ||
: 'StackScript'; | ||
|
||
return ( | ||
<Dialog | ||
fullHeight | ||
fullWidth | ||
maxWidth="md" | ||
onClose={onClose} | ||
open={open} | ||
title={title} | ||
> | ||
{isLoading && <CircleProgress />} | ||
{error && <ErrorState errorText={error[0].reason} />} | ||
{stackscript && <StackScript data={stackscript} userCanModify={false} />} | ||
</Dialog> | ||
); | ||
}; |
73 changes: 73 additions & 0 deletions
73
.../manager/src/features/Linodes/LinodeCreatev2/Tabs/StackScripts/StackScriptImages.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,73 @@ | ||
import userEvent from '@testing-library/user-event'; | ||
import React from 'react'; | ||
|
||
import { imageFactory, stackScriptFactory } from 'src/factories'; | ||
import { makeResourcePage } from 'src/mocks/serverHandlers'; | ||
import { HttpResponse, http, server } from 'src/mocks/testServer'; | ||
import { renderWithThemeAndHookFormContext } from 'src/utilities/testHelpers'; | ||
|
||
import { StackScriptImages } from './StackScriptImages'; | ||
|
||
describe('Images', () => { | ||
it('should render a heading', () => { | ||
const { getByText } = renderWithThemeAndHookFormContext({ | ||
component: <StackScriptImages />, | ||
}); | ||
|
||
expect(getByText('Select an Image')).toBeVisible(); | ||
}); | ||
|
||
it('should render an Image Select', () => { | ||
const { getByLabelText } = renderWithThemeAndHookFormContext({ | ||
component: <StackScriptImages />, | ||
}); | ||
|
||
expect(getByLabelText('Images')).toBeVisible(); | ||
}); | ||
|
||
it('should only render images that are compatible with the selected StackScript', async () => { | ||
const images = imageFactory.buildList(5); | ||
|
||
// For the sake of this test, we pretend this image is the only compatible image. | ||
const compatibleImage = images[2]; | ||
|
||
const stackscript = stackScriptFactory.build({ | ||
images: [compatibleImage.id], | ||
}); | ||
|
||
server.use( | ||
http.get('*/v4/images', () => { | ||
return HttpResponse.json(makeResourcePage(images)); | ||
}), | ||
http.get('*/v4/linode/stackscripts/:id', () => { | ||
return HttpResponse.json(stackscript); | ||
}) | ||
); | ||
|
||
const { | ||
findByText, | ||
getByLabelText, | ||
queryByText, | ||
} = renderWithThemeAndHookFormContext({ | ||
component: <StackScriptImages />, | ||
useFormOptions: { | ||
defaultValues: { stackscript_id: stackscript.id }, | ||
}, | ||
}); | ||
|
||
const imageSelect = getByLabelText('Images'); | ||
|
||
await userEvent.click(imageSelect); | ||
|
||
// Verify that the compabile image is show in the dropdown. | ||
await findByText(compatibleImage.label); | ||
|
||
// Verify that the images returned by the API that are NOT compatible | ||
// with this StackScript are *not* shown in the dropdown. | ||
for (const image of images) { | ||
if (image !== compatibleImage) { | ||
expect(queryByText(image.label)).toBeNull(); | ||
} | ||
} | ||
}); | ||
}); |
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.
Aren't
filteredOptions?.length === 1
&selectIfOnlyOneOption
doing the same thing?Do we need the
selectIfOnlyOneOption
optional prop?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 added the
selectIfOnlyOneOption
prop so that the functionality is op-in. I don't think it should be the default behavior