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

fix: [M3-6254] - Show warning message for only Linode clone and backups #8888

Merged
merged 4 commits into from
Mar 22, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { DefaultProps as ImagesProps } from 'src/containers/images.container';
import { AppsDocs } from 'src/documentation';
import EUAgreementCheckbox from 'src/features/Account/Agreements/EUAgreementCheckbox';
import SMTPRestrictionText from 'src/features/linodes/SMTPRestrictionText';
import UserDataAccordion from 'src/features/linodes/LinodesCreate/UserDataAccordion/UserDataAccordion';
import {
getCommunityStackscripts,
getMineAndAccountStackScripts,
Expand All @@ -60,6 +59,7 @@ import FromBackupsContent from './TabbedContent/FromBackupsContent';
import FromImageContent from './TabbedContent/FromImageContent';
import FromLinodeContent from './TabbedContent/FromLinodeContent';
import FromStackScriptContent from './TabbedContent/FromStackScriptContent';
import UserDataAccordion from './UserDataAccordion/UserDataAccordion';
import { renderBackupsDisplaySection } from './TabbedContent/utils';
import {
AllFormStateAndHandlers,
Expand Down Expand Up @@ -551,11 +551,6 @@ export class LinodeCreate extends React.PureComponent<
const showUserData =
imageIsCloudInitCompatible || linodeIsCloudInitCompatible;

const userDataHeaderWarningMessage =
this.props.createType === 'fromBackup'
? 'Existing user data is not available when creating a Linode from a backup.'
: 'User data is not cloned.';

return (
<form className={classes.form}>
<Grid item className="py0">
Expand Down Expand Up @@ -760,11 +755,7 @@ export class LinodeCreate extends React.PureComponent<
<UserDataAccordion
userData={this.props.userData}
onChange={updateUserData}
renderHeaderWarningMessage={
<Notice warning spacingTop={16} spacingBottom={16}>
{userDataHeaderWarningMessage}
</Notice>
}
createType={this.props.createType}
/>
) : null}
<AddonsPanel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
import * as React from 'react';
import Link from 'src/components/Link';
import Notice from 'src/components/Notice';
import { StyledHelpIcon } from './UserDataAccordion.styles';

export const LINODE_CREATE_FROM = {
BACKUPS: 'fromBackup',
CLONE: 'fromLinode',
};

cpathipa marked this conversation as resolved.
Show resolved Hide resolved
interface Props {
warningNotice?: JSX.Element;
createType?: string | undefined;
}

const AccordionHeading = (props: Props) => {
const { warningNotice } = props;
const AccordionHeading = ({ createType }: Props) => {
cpathipa marked this conversation as resolved.
Show resolved Hide resolved
const userDataHeaderWarningMessage =
createType === LINODE_CREATE_FROM.BACKUPS
? 'Existing user data is not available when creating a Linode from a backup.'
: 'User data is not cloned.';
const showWarningMessage =
createType &&
[LINODE_CREATE_FROM.BACKUPS, LINODE_CREATE_FROM.CLONE].includes(createType);

return (
<>
Expand All @@ -22,7 +34,11 @@ const AccordionHeading = (props: Props) => {
}
interactive
/>
{warningNotice ?? warningNotice}
{showWarningMessage ? (
<Notice warning spacingTop={16} spacingBottom={16}>
{userDataHeaderWarningMessage}
</Notice>
) : null}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import * as React from 'react';
import { fireEvent, screen } from '@testing-library/react';
import { renderWithTheme } from 'src/utilities/testHelpers';
import UserDataAccordion from './UserDataAccordion';
import { LINODE_CREATE_FROM } from './AccordionHeading';

describe('UserDataAccordion', () => {
const onChange = jest.fn();
const props = {
userData: 'test data',
onChange,
createType: '',
};
it('should render without errors', () => {
const { container } = renderWithTheme(<UserDataAccordion {...props} />);
Expand Down Expand Up @@ -42,13 +44,12 @@ describe('UserDataAccordion', () => {

it('should display a custom header warning message', () => {
renderWithTheme(
<UserDataAccordion
{...props}
renderHeaderWarningMessage={<div>Custom warning message</div>}
/>
<UserDataAccordion {...props} createType={LINODE_CREATE_FROM.BACKUPS} />
);

const headerWarningMessage = screen.getByText('Custom warning message');
const headerWarningMessage = screen.getByText(
'Existing user data is not available when creating a Linode from a backup.'
);

expect(headerWarningMessage).toBeInTheDocument();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ import AccordionHeading from './AccordionHeading';
import UserDataExplanatory from './UserDataExplanatory';

interface Props {
createType?: string;
userData: string | undefined;
onChange: (userData: string) => void;
disabled?: boolean;
renderHeaderWarningMessage?: JSX.Element;
renderNotice?: JSX.Element;
renderCheckbox?: JSX.Element;
}

const UserDataAccordion = (props: Props) => {
const {
createType,
disabled,
userData,
onChange,
renderHeaderWarningMessage,
renderNotice,
renderCheckbox,
} = props;
Expand Down Expand Up @@ -51,7 +51,7 @@ const UserDataAccordion = (props: Props) => {

return (
<Accordion
heading={<AccordionHeading warningNotice={renderHeaderWarningMessage} />}
heading={<AccordionHeading createType={createType} />}
style={{ marginTop: renderNotice && renderCheckbox ? 0 : 24 }} // for now, these props can be taken as an indicator we're in the Rebuild flow.
headingProps={{
variant: 'h2',
Expand Down