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

refactor: [M3-6300] - MUI v5 Migration - Components > CheckoutBar #9051

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- MUIv5 Migration - `Components > DateTimeDisplay, DebouncedSearchTextField` #9007
- MUIv5 Migration - `SRC > Components > ConfirmationDialog` #9016
- MUIv5 Migration - `SRC > Components > CopyTooltip` #9040
- - MUIv5 Migration - `SRC > Components > CopyTooltip` #9040
- MUIv5 Migration - `SRC > Components > CopyTooltip` #9040
- MUIv5 Migration - `SRC > Components > CheckoutBar` #9051
- Add basic Adobe Analytics tracking #8989

## [2023-04-18] - v1.91.1
Expand Down
56 changes: 35 additions & 21 deletions packages/manager/src/components/CheckoutBar/CheckoutBar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import { useTheme } from '@mui/material/styles';
import * as React from 'react';
import Button from 'src/components/Button';
import Typography from 'src/components/core/Typography';
import { DisplayPrice } from 'src/components/DisplayPrice';
import useStyles from './styles';
import {
StyledButton,
StyledCheckoutSection,
StyledRoot,
SxTypography,
} from './styles';

interface Props {
interface CheckoutBarProps {
onDeploy: () => void;
heading: string;
calculatedPrice?: number;
Expand All @@ -17,11 +22,7 @@ interface Props {
agreement?: JSX.Element;
}

type CombinedProps = Props;

const CheckoutBar: React.FC<CombinedProps> = (props) => {
const classes = useStyles();

const CheckoutBar = (props: CheckoutBarProps) => {
const {
onDeploy,
heading,
Expand All @@ -32,44 +33,57 @@ const CheckoutBar: React.FC<CombinedProps> = (props) => {
submitText,
footer,
agreement,
children,
} = props;

const theme = useTheme();

const price = calculatedPrice ?? 0;

return (
<div className={classes.root}>
<StyledRoot>
<Typography
variant="h2"
className={classes.sidebarTitle}
sx={{
color: theme.color.headline,
fontSize: '1.125rem',
wordBreak: 'break-word',
}}
data-qa-order-summary
>
{heading}
</Typography>
{props.children}
{children}
{
<div className={classes.checkoutSection} data-qa-total-price>
<StyledCheckoutSection data-qa-total-price>
<DisplayPrice price={price} interval="mo" />
{priceHelperText && price > 0 && (
<Typography className={classes.price}>{priceHelperText}</Typography>
<Typography
sx={{
...SxTypography,
marginTop: theme.spacing(),
}}
>
{priceHelperText}
</Typography>
)}
</div>
</StyledCheckoutSection>
}
{agreement ? agreement : null}
<div className={classes.checkoutSection}>
<Button
<StyledCheckoutSection>
<StyledButton
buttonType="primary"
className={classes.createButton}
disabled={disabled}
onClick={onDeploy}
data-qa-deploy-linode
loading={isMakingRequest}
>
{submitText ?? 'Create'}
</Button>
</div>
</StyledButton>
</StyledCheckoutSection>
{footer ? footer : null}
</div>
</StyledRoot>
);
};

export default CheckoutBar;
export { CheckoutBar };
22 changes: 11 additions & 11 deletions packages/manager/src/components/CheckoutBar/DisplaySection.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import * as React from 'react';
import Typography from 'src/components/core/Typography';
import useStyles from './styles';
import { StyledCheckoutSection, SxTypography } from './styles';

export interface Props {
export interface DisplaySectionProps {
title: string;
details?: string | number;
}

export const DisplaySection: React.FC<Props> = (props) => {
const DisplaySection = React.memo((props: DisplaySectionProps) => {
const { title, details } = props;
const classes = useStyles();

return (
<div className={classes.checkoutSection}>
<StyledCheckoutSection>
{title && (
<Typography variant="h3" data-qa-subheading={title}>
{title}
</Typography>
)}
{details && (
{details ? (
<Typography
component="span"
data-qa-details={details}
className={classes.detail}
sx={SxTypography}
>
{details}
</Typography>
)}
</div>
) : null}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

details is typed as a string or number, so I went with the ternary here.

</StyledCheckoutSection>
);
};
});

export default React.memo(DisplaySection);
export { DisplaySection };
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import * as React from 'react';
import Divider from '../core/Divider';
import DisplaySection from './DisplaySection';
import { DisplaySection } from './DisplaySection';

interface Props {
interface DisplaySectionListProps {
displaySections?: { title: string; details?: string | number }[];
}

export const DisplaySectionList: React.FC<Props> = ({ displaySections }) => {
const DisplaySectionList = ({ displaySections }: DisplaySectionListProps) => {
if (!displaySections) {
return null;
}
Expand All @@ -27,4 +27,4 @@ export const DisplaySectionList: React.FC<Props> = ({ displaySections }) => {
);
};

export default DisplaySectionList;
export { DisplaySectionList };
4 changes: 0 additions & 4 deletions packages/manager/src/components/CheckoutBar/index.ts

This file was deleted.

75 changes: 32 additions & 43 deletions packages/manager/src/components/CheckoutBar/styles.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { makeStyles } from '@mui/styles';
import { Theme } from '@mui/material/styles';
import { useTheme } from '@mui/material/styles';
import { styled } from '@mui/system';
import Button from 'src/components/Button';

export const useStyles = makeStyles((theme: Theme) => ({
'@keyframes fadeIn': {
from: {
opacity: 0,
},
to: {
opacity: 1,
},
const StyledButton = styled(Button)(({ theme }) => ({
marginTop: 18,
[theme.breakpoints.up('lg')]: {
width: '100%',
},
root: {
}));

const StyledRoot = styled('div')(() => {
const theme = useTheme();

return {
minHeight: '24px',
minWidth: '24px',
[theme.breakpoints.down('md')]: {
Expand All @@ -20,42 +22,29 @@ export const useStyles = makeStyles((theme: Theme) => ({
left: '0 !important' as '0',
bottom: '0 !important' as '0',
},
},
sidebarTitle: {
color: theme.color.headline,
fontSize: '1.125rem',
wordBreak: 'break-word',
},
checkoutSection: {
animation: '$fadeIn 225ms linear forwards',
opacity: 0,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't clear to me if animation and opacity were actually doing anything here, or what the benefit of keeping them would be, so I removed those properties.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not totally sure either, but it seems like the "Create Cluster" button does a slight fade in when the component first loads in prod. I don't think this is necessary and initial rendering + interacting with the CheckoutBar looks smooth to me without any animation

padding: '12px 0',
[theme.breakpoints.down('md')]: {
'& button': {
marginLeft: 0,
},
},
[theme.breakpoints.down('lg')]: {
paddingBottom: `0px !important`,
};
});

const StyledCheckoutSection = styled('div')(({ theme }) => ({
padding: '12px 0',
[theme.breakpoints.down('md')]: {
'& button': {
marginLeft: 0,
},
},
price: {
color: theme.color.headline,
fontSize: '.8rem',
lineHeight: '1.5em',
marginTop: theme.spacing(),
[theme.breakpoints.down('lg')]: {
paddingBottom: `0px !important`,
},
detail: {
}));

const SxTypography = () => {
const theme = useTheme();

return {
color: theme.color.headline,
fontSize: '.8rem',
lineHeight: '1.5em',
},
createButton: {
marginTop: 18,
[theme.breakpoints.up('lg')]: {
width: '100%',
},
},
}));
};
};

export default useStyles;
export { StyledButton, StyledRoot, StyledCheckoutSection, SxTypography };
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { KubeNodePoolResponse } from '@linode/api-v4';
import * as React from 'react';
import CheckoutBar from 'src/components/CheckoutBar';
import { CheckoutBar } from 'src/components/CheckoutBar/CheckoutBar';
import { CircleProgress } from 'src/components/CircleProgress';
import Divider from 'src/components/core/Divider';
import Notice from 'src/components/Notice';
Expand All @@ -14,11 +14,11 @@ import { useAccount } from 'src/queries/account';
import { useAccountAgreements } from 'src/queries/accountAgreements';
import { useProfile } from 'src/queries/profile';
import { useSpecificTypes } from 'src/queries/types';
import { extendTypesQueryResult } from 'src/utilities/extendType';
import { isEURegion } from 'src/utilities/formatRegion';
import { getTotalClusterPrice, nodeWarning } from '../kubeUtils';
import HACheckbox from './HACheckbox';
import NodePoolSummary from './NodePoolSummary';
import { extendTypesQueryResult } from 'src/utilities/extendType';

export interface Props {
pools: KubeNodePoolResponse[];
Expand Down