-
Notifications
You must be signed in to change notification settings - Fork 332
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-7944] - Linode Create Refactor - User Data - Part 7 #10331
upcoming: [M3-7944] - Linode Create Refactor - User Data - Part 7 #10331
Conversation
Coverage Report: β
|
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.
Looks good from my review and testing! I didn't see test coverage for our help icons/tooltips in any e2es, so that could be something worth adding to these component unit tests. And we need a changeset, please.
β
I see the Metadata section if I select a cloud-init capable image and a Region that supports metadata -- though I'm with you on the poor visibility of this feature. I had to google our Metadata availability because I never remember.
β
I can specify metadata and if it's not in the intended formats, I see the warning
β
Observed that the base64 encoded user data is in the payload
β
Observed the warnings for backups and cloning
packages/manager/src/features/Linodes/LinodeCreatev2/UserData/UserDataHeading.tsx
Outdated
Show resolved
Hide resolved
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.
Great test, thank you!
We could add test coverage to check that the help icon displays as expected.
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 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.
Noticed no regressions after manual testing. Left a few suggestions. Nice work, really appreciate the bite-sized PRs! ππ½
hasInputValueChanged: true, | ||
userData: e.target.value, | ||
}); | ||
field.onChange(utoa(e.target.value)); |
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.
Instead of performing the utoa
conversion on change, could we store the original value and only do the conversion on submit? This would also save us from having to convert back on line 106.
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'm considering both options. At first, when building this new create flow, I wanted to try to keep the form data in the format the API expects, but now I'm realizing it might make more sense to perform some transformation on submit.
I might merge as-is, but might come back and change this.
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.
FWIW, i agree with a submit data transformation. This looks a bit expensive especially without debouncing - you also transform the value
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.
Fair enough. I will change this β
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.
Added a transform step in 1803a36
import { UserData } from './UserData'; | ||
|
||
describe('Linode Create v2 UserData', () => { | ||
it('should render if the selected image supports cloud-init and the region supports metadata', async () => { |
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.
Should we have a test for the opposite (i.e., doesn't appear when the image or regions doesn't support metadata)?
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.
Yes, but I don't really know how to reliably do this because the unit test waits for API data to load
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.
@bnussman-akamai This is a good candidate to mock the useImages
and useRegions
hooks so you can ignore the HTTP stuff and test directly against the state you want, but you can also do this kind of hacky thing to wait for the requests before testing the state of the component:
const image = imageFactory.build({ capabilities: [] });
const region = regionFactory.build({ capabilities: ['Metadata'] });
let [hasLoadedImages, hasLoadedRegions] = [false, false];
server.use(
http.get('*/v4/images/*', () => {
hasLoadedImages = true;
return HttpResponse.json(image);
}),
http.get('*/v4/regions', () => {
hasLoadedRegions = true;
return HttpResponse.json(makeResourcePage([region]));
})
);
const { queryByText } = renderWithThemeAndHookFormContext({
component: <UserData />,
useFormOptions: { defaultValues: { image: image.id, region: region.id } },
});
// Wait for requests...
await waitFor(() => {
expect(hasLoadedImages && hasLoadedRegions).toBe(true);
});
// Assert that user data is hidden here.
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.
yeah good call. Mocking useImages
and useRegions
would probably be best. Thank you for the tip π
/** | ||
* ASCII to Unicode (decode Base64 to original data) | ||
*/ | ||
export function atou(b64: string) { | ||
return decodeURIComponent(escape(atob(b64))); | ||
} | ||
|
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.
It might be worth adding a test for this utility (and its counterpart) with some common examples and edge cases (like hex escape codes).
packages/manager/src/features/Linodes/LinodeCreatev2/UserData/UserData.tsx
Outdated
Show resolved
Hide resolved
β¦UserData.tsx Co-authored-by: Hussain Khalil <122488130+hkhalil-akamai@users.noreply.github.com>
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.
Looks great and appreciate the small, well tested PR
Prob an existing behavior - we should prevent event propagation on the accordion header tooltip so it does not collapses it onclick. This is prob very annoying on mobile
Screen.Recording.2024-04-01.at.10.08.20.mov
hasInputValueChanged: true, | ||
userData: e.target.value, | ||
}); | ||
field.onChange(utoa(e.target.value)); |
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.
FWIW, i agree with a submit data transformation. This looks a bit expensive especially without debouncing - you also transform the value
{warningMessage} | ||
</Notice> | ||
)} | ||
</Stack> |
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.
nit, let's not add another div if not needed and use a fragment instead
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.
Kind of addressed in cf72f9f
import { useImageQuery } from 'src/queries/images'; | ||
import { useRegionsQuery } from 'src/queries/regions/regions'; | ||
|
||
import { atou, utoa } from '../../LinodesCreate/utilities'; |
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 assume you're planning to move utils eventually? wondering about duplicating them but then we'd miss potential updates
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'll do all of the moving when we start deleting the old create flow code. It will be a pain, but TS should help me identify the utils that need to be kept and moved when I delete a file and see an error
Good point @abailly-akamai . Do you think this should be a global change to the |
@bnussman-akamai i can't really think of a time we'd want the click to propagate so I'd say yes? |
Sounds good, I agree! I also can't think of any instances where we'd want the click to propagate. Thanks @abailly-akamai |
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.
Thanks for the changes!
β¦node#10331) * initial work * unit testing * clean up * fix placement of `.` * Added changeset: Linode Create Refactor v2 - User Data - Part 7 * Update packages/manager/src/features/Linodes/LinodeCreatev2/UserData/UserData.tsx Co-authored-by: Hussain Khalil <122488130+hkhalil-akamai@users.noreply.github.com> * add some bais testing to encode and decode * improve spacing * use flex spacing insted of margin * stop propogation of tooltip icon button click * add a transform step in the onSubmit --------- Co-authored-by: Banks Nussman <banks@nussman.us> Co-authored-by: Hussain Khalil <122488130+hkhalil-akamai@users.noreply.github.com>
Description π
Adds User Data section to the new Linode Create page π€π π
Note
The User Data section will only show up if you select an Image that is cloud-init capable and a region that supports Metadata. I don't necessarily agree with this UX, but this matches the existing behavior.
Preview π·
How to test π§ͺ
Linode Create v2
feature flag using load dev toolscloud-init
capable image and a Region that supports metadataAs an Author I have considered π€