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-6393] - MUI v5 - Components > Snackbar #9359

Merged
merged 6 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@linode/manager": Tech Stories
---

MUI v5 - `Components > Snackbar` ([#9359](https://github.com/linode/manager/pull/9359))
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const DismissibleBannerTemplate = (args) => {

export const CallToActionBanner = () => {
return (
<DismissibleBanner preferenceKey="cluster-v1" success>
<DismissibleBanner preferenceKey="cluster-v1" info>
<Grid
container
direction="row"
Expand All @@ -67,7 +67,7 @@ export const StatusBannersTemplate = (args) => {

export const BetaBanner = () => {
return (
<DismissibleBanner preferenceKey="beta-banner" success>
<DismissibleBanner preferenceKey="beta-banner" info>
<Typography>
Managed Database for MySQL is available in a free, open beta period
until May 2nd, 2022. This is a beta environment and should not be used
Expand Down
15 changes: 14 additions & 1 deletion packages/manager/src/components/Notice/Notice.stories.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import { Notice } from './Notice';

Types of Notices:

- Success/Marketing (blue line)
- Success/Marketing (green line)
- Info (blue line)
- Error/critical (red line)
- Warning (yellow line)

Expand All @@ -25,6 +26,12 @@ Types of Notices:
</Story>
</Canvas>

<Canvas>
<Story name="Info">
<Notice info text="This is a informational notice" />
</Story>
</Canvas>

<Canvas>
<Story name="Error">
<Notice error text="This is an error notice" />
Expand All @@ -43,6 +50,12 @@ Types of Notices:
</Story>
</Canvas>

<Canvas>
<Story name="Important Info">
<Notice info important text="This is an important informational notice" />
</Story>
</Canvas>

<Canvas>
<Story name="Important Error">
<Notice error important text="This is an important error notice" />
Expand Down
36 changes: 25 additions & 11 deletions packages/manager/src/components/Notice/Notice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,16 @@ export const useStyles = makeStyles<
successList: {
borderLeft: `5px solid ${theme.palette.success.dark}`,
},
info: {
animation: '$fadeIn 225ms linear forwards',
borderLeft: `5px solid ${theme.palette.info.dark}`,
[`&.${classes.important}`]: {
borderLeftWidth: 32,
},
},
infoList: {
borderLeft: `5px solid ${theme.palette.info.dark}`,
},
marketing: {
borderLeft: `5px solid ${theme.color.green}`,
},
Expand All @@ -115,6 +125,7 @@ export interface NoticeProps extends Grid2Props {
important?: boolean;
warning?: boolean;
success?: boolean;
info?: boolean;
marketing?: boolean;
typeProps?: TypographyProps;
className?: string;
Expand All @@ -131,25 +142,26 @@ export interface NoticeProps extends Grid2Props {

export const Notice = (props: NoticeProps) => {
const {
breakWords,
children,
className,
important,
text,
dataTestId,
error,
breakWords,
errorGroup,
warning,
success,
marketing,
typeProps,
children,
flag,
important,
info,
marketing,
notificationList,
onClick,
spacingTop,
spacingBottom,
spacingLeft,
dataTestId,
spacingTop,
success,
sx,
text,
typeProps,
warning,
} = props;

const { classes, cx } = useStyles();
Expand Down Expand Up @@ -206,6 +218,8 @@ export const Notice = (props: NoticeProps) => {
[classes.errorList]: error && notificationList,
[classes.success]: success && !notificationList,
[classes.successList]: success && notificationList,
[classes.info]: info && !notificationList,
[classes.infoList]: info && notificationList,
[classes.warning]: warning && !notificationList,
[classes.marketing]: marketing,
[classes.warningList]: warning && notificationList,
Expand All @@ -228,7 +242,7 @@ export const Notice = (props: NoticeProps) => {
)}
{important &&
((success && <Check className={classes.icon} data-qa-success-img />) ||
(warning && (
((warning || info) && (
<Warning className={classes.icon} data-qa-warning-img />
)) ||
(error && <Error className={classes.icon} data-qa-error-img />))}
Expand Down
2 changes: 0 additions & 2 deletions packages/manager/src/components/SnackBar/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { SnackbarProvider, SnackbarProviderProps } from 'notistack';
import * as React from 'react';
import { makeStyles } from '@mui/styles';
import { makeStyles } from 'tss-react/mui';
import { Theme } from '@mui/material/styles';
import CloseSnackbar from './CloseSnackbar';

const useStyles = makeStyles((theme: Theme) => ({
const useStyles = makeStyles()((theme: Theme) => ({
root: {
'& div': {
backgroundColor: `${theme.bg.white} !important`,
Expand All @@ -29,7 +29,7 @@ const useStyles = makeStyles((theme: Theme) => ({
borderLeft: `6px solid ${theme.palette.primary.main}`,
},
success: {
borderLeft: `6px solid ${theme.palette.primary.main}`,
borderLeft: `6px solid ${theme.color.green}`,
jaalah-akamai marked this conversation as resolved.
Show resolved Hide resolved
},
error: {
borderLeft: `6px solid ${theme.palette.error.dark}`,
Expand All @@ -39,10 +39,8 @@ const useStyles = makeStyles((theme: Theme) => ({
},
}));

type CombinedProps = SnackbarProviderProps;

const SnackBar: React.FC<CombinedProps> = (props) => {
const classes = useStyles();
export const Snackbar = (props: SnackbarProviderProps) => {
const { classes } = useStyles();
/**
* This pattern is taken from the Notistack docs:
* https://iamhosseindhv.com/notistack/demos#action-for-all-snackbars
Expand Down Expand Up @@ -78,5 +76,3 @@ const SnackBar: React.FC<CombinedProps> = (props) => {
</SnackbarProvider>
);
};

export default SnackBar;
2 changes: 1 addition & 1 deletion packages/manager/src/features/Account/AutoBackups.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ const AutoBackups = (props: Props) => {
<Grid container direction="column" spacing={2}>
<Grid>
{!!isManagedCustomer ? (
<Notice success spacingBottom={20}>
<Notice info spacingBottom={20}>
You&rsquo;re a Managed customer, which means your Linodes are
already automatically backed up - no need to toggle this setting.
</Notice>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ const DatabaseCreate = () => {
</FormControl>
<Grid xs={12} md={8}>
{flags.databaseBeta ? (
<Notice success className={classes.notice}>
<Notice info className={classes.notice}>
<strong>
Notice: There is no charge for database clusters during beta.
</strong>{' '}
Expand Down
9 changes: 5 additions & 4 deletions packages/manager/src/features/Events/EventsLanding.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Event, getEvents } from '@linode/api-v4/lib/account';
import { ResourcePage } from '@linode/api-v4/lib/types';
import { withSnackbar, WithSnackbarProps } from 'notistack';
import { useSnackbar } from 'notistack';
import { compose as rCompose, concat, uniq } from 'ramda';
import * as React from 'react';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -61,7 +61,7 @@ interface Props {
emptyMessage?: string; // Custom message for the empty state (i.e. no events).
}

type CombinedProps = Props & StateProps & WithSnackbarProps;
type CombinedProps = Props & StateProps;

const appendToEvents = (oldEvents: Event[], newEvents: Event[]) =>
rCompose<Event[], Event[], Event[], Event[]>(
Expand Down Expand Up @@ -173,6 +173,7 @@ export const reducer: EventsReducer = (state, action) => {

export const EventsLanding: React.FC<CombinedProps> = (props) => {
const classes = useStyles();
const { enqueueSnackbar } = useSnackbar();

const [loading, setLoading] = React.useState<boolean>(false);
const [loadMoreEvents, setLoadMoreEvents] = React.useState<boolean>(false);
Expand All @@ -199,7 +200,7 @@ export const EventsLanding: React.FC<CombinedProps> = (props) => {
getEventsRequest({ page: currentPage })
.then(handleEventsRequestSuccess)
.catch(() => {
props.enqueueSnackbar('There was an error loading more events', {
enqueueSnackbar('There was an error loading more events', {
variant: 'error',
});
setLoading(false);
Expand Down Expand Up @@ -403,6 +404,6 @@ const mapStateToProps = (state: ApplicationState) => ({

const connected = connect(mapStateToProps);

const enhanced = compose<CombinedProps, Props>(connected, withSnackbar);
const enhanced = compose<CombinedProps, Props>(connected);

export default enhanced(EventsLanding);
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export const CreateImageTab: React.FC<Props> = (props) => {
{generalError ? (
<Notice error text={generalError} data-qa-notice />
) : null}
{notice ? <Notice success text={notice} data-qa-notice /> : null}
{notice ? <Notice info text={notice} data-qa-notice /> : null}

<LinodeSelectV2
value={selectedLinode?.id || null}
Expand Down
2 changes: 1 addition & 1 deletion packages/manager/src/features/Images/ImagesDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ export const ImageDrawer: React.FC<CombinedProps> = (props) => {
) : null}
{generalError && <Notice error text={generalError} data-qa-notice />}

{notice && <Notice success text={notice} data-qa-notice />}
{notice && <Notice info text={notice} data-qa-notice />}

{['create', 'restore'].includes(mode) && (
<LinodeSelect
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { getKubeConfig } from '@linode/api-v4/lib/kubernetes';
import { withSnackbar, WithSnackbarProps } from 'notistack';
import { useSnackbar } from 'notistack';
import * as React from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import { compose } from 'recompose';
import ActionMenu, { Action } from 'src/components/ActionMenu';
import { Hidden } from 'src/components/Hidden';
import { useTheme } from '@mui/styles';
Expand All @@ -19,15 +17,12 @@ interface Props {
openDialog: () => void;
}

type CombinedProps = Props & RouteComponentProps<{}> & WithSnackbarProps;

export const ClusterActionMenu: React.FunctionComponent<CombinedProps> = (
props
) => {
export const ClusterActionMenu = (props: Props) => {
const theme = useTheme<Theme>();
const { enqueueSnackbar } = useSnackbar();
const matchesSmDown = useMediaQuery(theme.breakpoints.down('md'));

const { clusterId, clusterLabel, enqueueSnackbar, openDialog } = props;
const { clusterId, clusterLabel, openDialog } = props;

const actions: Action[] = [
{
Expand Down Expand Up @@ -91,7 +86,3 @@ export const ClusterActionMenu: React.FunctionComponent<CombinedProps> = (
</>
);
};

const enhanced = compose<CombinedProps, Props>(withSnackbar, withRouter);

export default enhanced(ClusterActionMenu);
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Grid from '@mui/material/Unstable_Grid2';
import { DateTimeDisplay } from 'src/components/DateTimeDisplay';
import { TableCell } from 'src/components/TableCell';
import { TableRow } from 'src/components/TableRow';
import ActionMenu from './ClusterActionMenu';
import { ClusterActionMenu } from './ClusterActionMenu';
import { Link } from 'react-router-dom';
import { makeStyles } from '@mui/styles';
import { Theme } from '@mui/material/styles';
Expand Down Expand Up @@ -149,7 +149,7 @@ export const KubernetesClusterRow = (props: Props) => {
</TableCell>
</Hidden>
<TableCell actionCell>
<ActionMenu
<ClusterActionMenu
clusterId={cluster.id}
clusterLabel={cluster.label}
openDialog={() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const UpgradeKubernetesVersionBanner = (props: Props) => {
{nextVersion ? (
<DismissibleBanner
preferenceKey={`${clusterID}-${currentVersion}`}
success
info
actionButton={actionButton}
>
<Grid
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Config } from '@linode/api-v4/lib/linodes/types';
import { APIError } from '@linode/api-v4/lib/types';
import { withSnackbar, WithSnackbarProps } from 'notistack';
import * as React from 'react';
import { QueryClient } from 'react-query';
import { connect, MapDispatchToProps } from 'react-redux';
Expand Down Expand Up @@ -94,7 +93,6 @@ type CombinedProps = Props &
DispatchProps &
RouteProps &
StyleProps &
WithSnackbarProps &
WithProfileProps;

export class ListLinodes extends React.Component<CombinedProps, State> {
Expand Down Expand Up @@ -480,7 +478,6 @@ const connected = connect(mapStateToProps, mapDispatchToProps);

export const enhanced = compose<CombinedProps, Props>(
withRouter,
withSnackbar,
connected,
styled,
withFeatureFlagConsumer,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import {
LongviewClient,
LongviewSubscription,
} from '@linode/api-v4/lib/longview/types';
import { withSnackbar, WithSnackbarProps } from 'notistack';
import { isEmpty, pathOr } from 'ramda';
import * as React from 'react';
import { connect } from 'react-redux';
Expand Down Expand Up @@ -79,7 +78,6 @@ interface Props {
export type CombinedProps = Props &
RouteComponentProps &
LongviewProps &
WithSnackbarProps &
StateProps;

type SortKey = 'name' | 'cpu' | 'ram' | 'swap' | 'load' | 'network' | 'storage';
Expand Down Expand Up @@ -334,8 +332,7 @@ const connected = connect(mapStateToProps);
export default compose<CombinedProps, Props & RouteComponentProps>(
React.memo,
connected,
withLongviewClients(),
withSnackbar
withLongviewClients()
)(LongviewClients);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ const props: CombinedProps = {
deleteLongviewClient: jest.fn(),
getLongviewClients: jest.fn().mockResolvedValue([]),
updateLongviewClient: jest.fn(),
enqueueSnackbar: jest.fn(),
closeSnackbar: jest.fn(),
activeSubscription: longviewSubscriptionFactory.build(),
lvClientData: {},
handleAddClient: jest.fn(),
Expand Down
Loading