-
Notifications
You must be signed in to change notification settings - Fork 365
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upcoming: [M3-7872] - Linode Create Refactor - StackScripts (#10367)
* initial work * filter options based on stackscript compatibility * implement complex preselection logic * clean up a bit * implement details dialog * fix some query param logic * lots of behavior changes to match production * fix image select clear behavior and fix table waypoint console error * improve validation for when image is `null` * first unit tests * add lots of unit testing * add stackscript event handler * hook up validation packages for realtime validation * use default validation behavior * Revert "hook up validation packages for realtime validation" This reverts commit f56e4ad. * handle resets when switching tabs * add changesets * add some comments * bold label and pre-select if only one option * improve ux * fix unit tests * add comment --------- Co-authored-by: Banks Nussman <banks@nussman.us>
- Loading branch information
1 parent
7f2cf90
commit cffa916
Showing
29 changed files
with
1,088 additions
and
72 deletions.
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.