Skip to content
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

Conversation

bnussman-akamai
Copy link
Contributor

@bnussman-akamai bnussman-akamai commented Mar 29, 2024

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 πŸ“·

Screenshot 2024-03-29 at 11 38 08β€―AM

How to test πŸ§ͺ

  • Turn on the Linode Create v2 feature flag using load dev tools
  • Verify you see the Metadata section if you select a cloud-init capable image and a Region that supports metadata
  • Verify you can specify metadata
  • Observe that the base64 encoded user data is in the payload

As an Author I have considered πŸ€”

  • πŸ‘€ Doing a self review
  • ❔ Our contribution guidelines
  • 🀏 Splitting feature into small PRs
  • βž• Adding a changeset
  • πŸ§ͺ Providing/Improving test coverage
  • πŸ” Removing all sensitive information from the code and PR description
  • 🚩 Using a feature flag to protect the release
  • πŸ‘£ Providing comprehensive reproduction steps
  • πŸ“‘ Providing or updating our documentation
  • πŸ•› Scheduling a pair reviewing session
  • πŸ“± Providing mobile support
  • β™Ώ Providing accessibility support

Copy link

github-actions bot commented Mar 29, 2024

Coverage Report: βœ…
Base Coverage: 81.72%
Current Coverage: 81.72%

@bnussman-akamai bnussman-akamai changed the title refactor: [M3-7944] - Linode Create Refactor v2 - User Data - Part 7 upcoming: [M3-7944] - Linode Create Refactor v2 - User Data - Part 7 Mar 29, 2024
Copy link
Contributor

@mjac0bs mjac0bs left a 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

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could add test coverage to check that the help icon displays as expected.

(One of them would actually be in UserDataHeading, I know.)
Screenshot 2024-03-29 at 10 32 20β€―AM

Copy link
Contributor

@hkhalil-akamai hkhalil-akamai left a 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));
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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 βœ…

Copy link
Contributor Author

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 () => {
Copy link
Contributor

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)?

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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 πŸ™

Comment on lines 30 to 36
/**
* ASCII to Unicode (decode Base64 to original data)
*/
export function atou(b64: string) {
return decodeURIComponent(escape(atob(b64)));
}

Copy link
Contributor

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).

bnussman-akamai and others added 2 commits March 29, 2024 16:49
…UserData.tsx

Co-authored-by: Hussain Khalil <122488130+hkhalil-akamai@users.noreply.github.com>
Copy link
Contributor

@abailly-akamai abailly-akamai left a 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));
Copy link
Contributor

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>
Copy link
Contributor

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

Copy link
Contributor Author

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';
Copy link
Contributor

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

Copy link
Contributor Author

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

@bnussman-akamai
Copy link
Contributor Author

bnussman-akamai commented Apr 1, 2024

we should prevent event propagation on the accordion header tooltip

Good point @abailly-akamai . Do you think this should be a global change to the TooltipIcon component?

@abailly-akamai
Copy link
Contributor

@bnussman-akamai i can't really think of a time we'd want the click to propagate so I'd say yes?

@bnussman-akamai
Copy link
Contributor Author

Sounds good, I agree! I also can't think of any instances where we'd want the click to propagate. Thanks @abailly-akamai

@bnussman-akamai bnussman-akamai changed the title upcoming: [M3-7944] - Linode Create Refactor v2 - User Data - Part 7 upcoming: [M3-7944] - Linode Create Refactor - User Data - Part 7 Apr 1, 2024
Copy link
Contributor

@abailly-akamai abailly-akamai left a 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!

@bnussman-akamai bnussman-akamai merged commit 0e0e5a5 into linode:develop Apr 1, 2024
17 of 18 checks passed
bnussman-akamai added a commit to bnussman-akamai/manager that referenced this pull request Apr 4, 2024
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants