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-6285] - SRC > Features > ToastNotifications #9555

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

SRC > Features > ToastNotifications MUI v5 migration ([#9555](https://github.com/linode/manager/pull/9555))
2 changes: 1 addition & 1 deletion packages/manager/src/MainContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
notificationContext,
useNotificationContext,
} from 'src/features/NotificationCenter/NotificationContext';
import ToastNotifications from 'src/features/ToastNotifications';
import { ToastNotifications } from 'src/features/ToastNotifications/ToastNotifications';
import { TopMenu } from 'src/features/TopMenu/TopMenu';
import VolumeDrawer from 'src/features/Volumes/VolumeDrawer';
import { useAccountManagement } from 'src/hooks/useAccountManagement';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Event, EventStatus } from '@linode/api-v4/lib/account/types';
import { WithSnackbarProps, withSnackbar } from 'notistack';
import { WithSnackbarProps, useSnackbar } from 'notistack';
import * as React from 'react';
import { Subscription } from 'rxjs/Subscription';
import 'rxjs/add/operator/bufferTime';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/map';
Expand Down Expand Up @@ -70,12 +69,12 @@ export const getLabel = (event: Event) => event.entity?.label ?? '';
export const getSecondaryLabel = (event: Event) =>
event.secondary_entity?.label ?? '';

class ToastNotifications extends React.PureComponent<WithSnackbarProps, {}> {
componentDidMount() {
this.subscription = events$
export const ToastNotifications = () => {
const { enqueueSnackbar } = useSnackbar();
React.useEffect(() => {
const subscription = events$
.filter(({ event }) => !event._initial)
.map(({ event }) => {
const { enqueueSnackbar } = this.props;
const label = getLabel(event);
const secondaryLabel = getSecondaryLabel(event);
switch (event.action) {
Expand Down Expand Up @@ -282,19 +281,14 @@ class ToastNotifications extends React.PureComponent<WithSnackbarProps, {}> {
return;
}
});
}

componentWillUnmount() {
this.subscription.unsubscribe();
}
render() {
return null;
}

subscription: Subscription;
}
return () => {
subscription.unsubscribe();
};
}, []);

export default withSnackbar(ToastNotifications);
return null;
};

const formatLink = (text: string, link: string, handleClick?: any) => {
return (
Expand Down
2 changes: 0 additions & 2 deletions packages/manager/src/features/ToastNotifications/index.ts

This file was deleted.