-
Notifications
You must be signed in to change notification settings - Fork 367
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
feat: [M3-6146] - Add User Data to Linode Rebuild flow #8850
Changes from 11 commits
b8ac515
469b85c
51dd803
bbd9559
3f68347
9a31e23
7f71d34
ea7ebde
84edcbf
21566c6
383ff00
254f5db
a729635
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Notice from 'src/components/Notice'; | ||
import { styled } from '@mui/material/styles'; | ||
|
||
export const StyledNotice = styled(Notice)({ | ||
// @TODO: Remove the !important's once Notice.tsx has been refactored to use MUI's styled() | ||
padding: '8px !important', | ||
marginBottom: '0px !important', | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { styled } from '@mui/material/styles'; | ||
import HelpIcon from 'src/components/HelpIcon'; | ||
|
||
export const StyledHelpIcon = styled(HelpIcon)({ | ||
padding: '0px 0px 4px 8px', | ||
'& svg': { | ||
fill: 'currentColor', | ||
stroke: 'none', | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import * as React from 'react'; | ||
import { renderWithTheme } from 'src/utilities/testHelpers'; | ||
import UserDataAccordion from 'src/features/linodes/UserDataAccordion'; | ||
|
||
describe('UserDataAccordion', () => { | ||
it('should NOT have a notice when a renderNotice prop is not passed in', () => { | ||
const { queryByTestId } = renderWithTheme( | ||
<UserDataAccordion userData={''} onChange={() => null} /> | ||
); | ||
|
||
expect(queryByTestId('render-notice')).toBeNull(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,23 @@ | ||
import * as React from 'react'; | ||
import Accordion from 'src/components/Accordion'; | ||
import { makeStyles } from 'src/components/core/styles'; | ||
import Typography from 'src/components/core/Typography'; | ||
import HelpIcon from 'src/components/HelpIcon'; | ||
import Notice from 'src/components/Notice'; | ||
import Link from 'src/components/Link'; | ||
import Notice from 'src/components/Notice'; | ||
import TextField from 'src/components/TextField'; | ||
import { StyledHelpIcon } from './UserDataAccordion.styles'; | ||
|
||
interface Props { | ||
userData: string | undefined; | ||
onChange: (userData: string) => void; | ||
disabled?: boolean; | ||
renderNotice?: () => JSX.Element; | ||
renderCheckbox?: () => JSX.Element; | ||
} | ||
|
||
const useStyles = makeStyles(() => ({ | ||
helpIcon: { | ||
padding: '0px 0px 4px 8px', | ||
'& svg': { | ||
fill: 'currentColor', | ||
stroke: 'none', | ||
}, | ||
}, | ||
accordionSummary: { | ||
padding: '5px 24px 0px 24px', | ||
}, | ||
accordionDetail: { | ||
padding: '0px 24px 24px 24px', | ||
}, | ||
})); | ||
|
||
const UserDataAccordion = (props: Props) => { | ||
const { disabled, userData, onChange } = props; | ||
const { disabled, userData, onChange, renderNotice, renderCheckbox } = props; | ||
const [formatWarning, setFormatWarning] = React.useState(false); | ||
|
||
const classes = useStyles(); | ||
|
||
const checkFormat = ({ | ||
userData, | ||
hasInputValueChanged, | ||
|
@@ -56,50 +39,33 @@ const UserDataAccordion = (props: Props) => { | |
} | ||
}; | ||
|
||
const accordionHeading = ( | ||
<> | ||
Add User Data{' '} | ||
<HelpIcon | ||
text={ | ||
<> | ||
User data is part of a virtual machine’s cloud-init metadata | ||
containing information related to a user’s local account.{' '} | ||
<Link to="/">Learn more.</Link> | ||
</> | ||
} | ||
className={classes.helpIcon} | ||
interactive | ||
/> | ||
</> | ||
); | ||
const sxDetails = { | ||
padding: `0px 24px 24px ${renderNotice ? 0 : 24}px`, | ||
}; | ||
|
||
return ( | ||
<Accordion | ||
heading={accordionHeading} | ||
style={{ marginTop: 24 }} | ||
style={{ marginTop: renderNotice && renderCheckbox ? 0 : 24 }} // for now, these props can be taken as an indicator we're in the Rebuild flow. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also access props within Styled components to conditionally apply styles.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you do down that route, for code readability I recommend using only one top-level function, especially if in the future we need to add to this:
|
||
headingProps={{ | ||
variant: 'h2', | ||
}} | ||
summaryProps={{ | ||
classes: { | ||
root: classes.accordionSummary, | ||
}, | ||
sx: { padding: '5px 24px 0px 24px' }, | ||
}} | ||
detailProps={{ | ||
classes: { | ||
root: classes.accordionDetail, | ||
detailProps={{ sx: sxDetails }} | ||
sx={{ | ||
'&:before': { | ||
display: 'none', | ||
}, | ||
}} | ||
> | ||
<Typography> | ||
<Link to="https://cloudinit.readthedocs.io/en/latest/reference/examples.html"> | ||
User Data | ||
</Link>{' '} | ||
is part of a virtual machine’s cloud-init metadata that contains | ||
anything related to a user’s local account, including username and | ||
user group(s). <br /> Accepted formats are YAML and bash.{' '} | ||
<Link to="https://www.linode.com/docs">Learn more.</Link> | ||
</Typography> | ||
{renderNotice ? ( | ||
<div data-testid="render-notice">{renderNotice()}</div> | ||
cpathipa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) : ( | ||
userDataExplanatoryCopy | ||
dwiley-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
)} | ||
{acceptedFormatsCopy} | ||
dwiley-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{formatWarning ? ( | ||
<Notice warning spacingTop={16} spacingBottom={16}> | ||
This user data may not be in a format accepted by cloud-init. | ||
|
@@ -121,8 +87,43 @@ const UserDataAccordion = (props: Props) => { | |
} | ||
data-qa-user-data-input | ||
/> | ||
{renderCheckbox ? renderCheckbox() : null} | ||
</Accordion> | ||
); | ||
}; | ||
|
||
export default UserDataAccordion; | ||
|
||
const accordionHeading = ( | ||
dwiley-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<> | ||
Add User Data{' '} | ||
<StyledHelpIcon | ||
text={ | ||
<> | ||
User data is part of a virtual machine’s cloud-init metadata | ||
containing information related to a user’s local account.{' '} | ||
<Link to="/">Learn more.</Link> | ||
</> | ||
} | ||
interactive | ||
/> | ||
</> | ||
); | ||
|
||
const userDataExplanatoryCopy = ( | ||
dwiley-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Typography> | ||
<Link to="https://cloudinit.readthedocs.io/en/latest/reference/examples.html"> | ||
User Data | ||
</Link>{' '} | ||
is part of a virtual machine’s cloud-init metadata that contains | ||
anything related to a user’s local account, including username and | ||
user group(s). | ||
</Typography> | ||
); | ||
dwiley-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
const acceptedFormatsCopy = ( | ||
dwiley-akamai marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<Typography> | ||
<br /> Accepted formats are YAML and bash.{' '} | ||
<Link to="https://www.linode.com/docs">Learn more.</Link> | ||
</Typography> | ||
); | ||
cpathipa marked this conversation as resolved.
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.
Sorry, looks like I misunderstood the rebuild endpoint 😅
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.
This should be good to go now 🚀