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

[GEN-1670]: kill redux, use new toasts #1699

Merged
merged 25 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f97a5a1
Merge pull request #4 from odigos-io/new-ui
BenElferink Oct 27, 2024
afa1268
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 27, 2024
536f32f
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
fa352be
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
a4f03d8
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 28, 2024
b3fa682
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
f0a397f
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
2c13a75
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
3ab5c0c
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 29, 2024
977c57b
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 30, 2024
d95b6fe
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 30, 2024
cde9bdd
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 31, 2024
7ca44f7
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Oct 31, 2024
29d2e0d
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
5647431
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
8d22beb
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
e53746d
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 3, 2024
6fa1955
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 4, 2024
a6b6ec2
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 5, 2024
746f560
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 5, 2024
5c55719
Merge branch 'new-ui' of https://github.com/odigos-io/odigos
BenElferink Nov 5, 2024
c104fbc
feat: refactor existing components in preparation for notifications
BenElferink Nov 5, 2024
a256c22
feat: replace redux with zustand, use new toasts
BenElferink Nov 6, 2024
c0d0132
Merge branch 'new-ui' of https://github.com/odigos-io/odigos into gen…
BenElferink Nov 6, 2024
8e0134b
fix: key name
BenElferink Nov 6, 2024
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
44 changes: 19 additions & 25 deletions frontend/webapp/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ import React from 'react';
import { useSSE } from '@/hooks';
import theme from '@/styles/theme';
import { ApolloWrapper } from '@/lib';
import { ToastList } from '@/components';
import { ThemeProvider } from 'styled-components';
import { NotificationManager } from '@/components';
import ReduxProvider from '@/store/redux-provider';
import { QueryClient, QueryClientProvider } from 'react-query';
// import { ThemeProviderWrapper } from '@keyval-dev/design-system';

const LAYOUT_STYLE: React.CSSProperties = {
margin: 0,
Expand All @@ -18,34 +16,30 @@ const LAYOUT_STYLE: React.CSSProperties = {
height: '100vh',
};

export default function RootLayout({ children }: { children: React.ReactNode }) {
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 10000,
refetchOnWindowFocus: false,
},
const queryClient = new QueryClient({
defaultOptions: {
queries: {
staleTime: 10000,
refetchOnWindowFocus: false,
},
});
},
});

export default function RootLayout({ children }: { children: React.ReactNode }) {
useSSE();

return (
<html lang='en'>
<ReduxProvider>
<ApolloWrapper>
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={theme}>
{/* <ThemeProviderWrapper> */}
<body suppressHydrationWarning={true} style={LAYOUT_STYLE}>
{children}
<NotificationManager />
</body>
{/* </ThemeProviderWrapper> */}
</ThemeProvider>
</QueryClientProvider>
</ApolloWrapper>
</ReduxProvider>
<ApolloWrapper>
<QueryClientProvider client={queryClient}>
<ThemeProvider theme={theme}>
<body suppressHydrationWarning={true} style={LAYOUT_STYLE}>
{children}
<ToastList />
</body>
</ThemeProvider>
</QueryClientProvider>
</ApolloWrapper>
</html>
);
}
4 changes: 2 additions & 2 deletions frontend/webapp/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ export * from './setup';
export * from './lists';
export * from './overview';
export * from './common';
export * from './notification/notification-manager';
export * from './notification/notification-list';
export * from './destinations';
export * from './main';
export * from './modals';
export * from './notification/notification-list'; // old
export * from './notification/toast-list'; // new
35 changes: 5 additions & 30 deletions frontend/webapp/components/notification/notification-list-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,8 @@ import { ROUTES, timeAgo } from '@/utils';
import { useRouter } from 'next/navigation';
import { getIcon } from './notification-icon';
import { KeyvalLink, KeyvalText } from '@/design.system';
import {
NotificationButtonContainer,
NotificationDetailsWrapper,
} from './notification-container';
interface NotificationListItemProps {
id: string;
message: string;
type: 'success' | 'error' | 'info';
seen: boolean;
title?: string;
crdType?: string;
time?: string;
target?: string;
}
import { NotificationButtonContainer, NotificationDetailsWrapper } from './notification-container';
import { Notification } from '@/types';

const NotificationItemContainer = styled.div<{ seen: boolean }>`
border-bottom: 1px solid ${theme.colors.blue_grey};
Expand All @@ -27,8 +15,7 @@ const NotificationItemContainer = styled.div<{ seen: boolean }>`
display: flex;
justify-content: space-between;
align-items: center;
background-color: ${({ seen }) =>
seen ? theme.colors.light_dark : theme.colors.dark};
background-color: ${({ seen }) => (seen ? theme.colors.light_dark : theme.colors.dark)};

&:hover {
background-color: ${theme.colors.dark};
Expand All @@ -41,15 +28,7 @@ const NotificationContent = styled.div`
gap: 8px;
`;

const NotificationListItem: React.FC<NotificationListItemProps> = ({
message,
type,
seen,
title,
crdType,
target,
time,
}) => {
const NotificationListItem: React.FC<Notification> = ({ message, type, seen, title, crdType, target, time }) => {
const router = useRouter();

function onDetailsClick() {
Expand Down Expand Up @@ -83,11 +62,7 @@ const NotificationListItem: React.FC<NotificationListItemProps> = ({
)}
</NotificationDetailsWrapper>
</NotificationContent>
<NotificationButtonContainer>
{!!target && (
<KeyvalLink fontSize={12} value="Details" onClick={onDetailsClick} />
)}
</NotificationButtonContainer>
<NotificationButtonContainer>{!!target && <KeyvalLink fontSize={12} value='Details' onClick={onDetailsClick} />}</NotificationButtonContainer>
</NotificationItemContainer>
);
};
Expand Down
22 changes: 5 additions & 17 deletions frontend/webapp/components/notification/notification-list.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import React, { useEffect, useRef, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { RootState, markAsSeen } from '@/store';

import styled from 'styled-components';
import theme from '@/styles/palette';
import { BellIcon } from '@keyval-dev/design-system';
import { KeyvalText } from '@/design.system';
import { useOnClickOutside } from '@/hooks';
import NotificationListItem from './notification-list-item';
import { useNotificationStore } from '@/store';

const NotificationListContainer = styled.div`
position: absolute;
Expand Down Expand Up @@ -58,18 +56,12 @@ const NotificationHeader = styled.div`

export const NotificationList: React.FC = () => {
const [showNotifications, setShowNotifications] = useState(false);
const { notifications, markAsSeen } = useNotificationStore();

const notifications = useSelector(
(state: RootState) => state.notification.notifications
);

const dispatch = useDispatch();
const containerRef = useRef(null);
const isInitialRender = useRef(true);
useOnClickOutside(containerRef, () => setShowNotifications(false));
const unseenCount = notifications.filter(
(notification) => !notification.seen
).length;
const unseenCount = notifications.filter((notification) => !notification.seen).length;

useEffect(() => {
if (isInitialRender.current) {
Expand All @@ -85,19 +77,15 @@ export const NotificationList: React.FC = () => {
function markAllAsSeen() {
notifications.forEach((notification) => {
if (!notification.seen) {
dispatch(markAsSeen(notification.id));
markAsSeen(notification.id);
}
});
}

return notifications.length > 0 ? (
<div ref={containerRef}>
<BellIconWrapper>
<BellIcon
style={{ cursor: 'pointer' }}
size={20}
onClick={() => setShowNotifications(!showNotifications)}
/>
<BellIcon style={{ cursor: 'pointer' }} size={20} onClick={() => setShowNotifications(!showNotifications)} />
{unseenCount > 0 && (
<NotificationBadge>
<KeyvalText size={10}>{unseenCount}</KeyvalText>
Expand Down
34 changes: 0 additions & 34 deletions frontend/webapp/components/notification/notification-manager.tsx

This file was deleted.

86 changes: 0 additions & 86 deletions frontend/webapp/components/notification/notification.tsx

This file was deleted.

29 changes: 29 additions & 0 deletions frontend/webapp/components/notification/toast-list.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from 'react';
import Toast from './toast';
import styled from 'styled-components';
import { useNotificationStore } from '@/store';

const Container = styled.div`
position: fixed;
bottom: 20px;
left: 50%;
transform: translateX(-50%);
z-index: 10000;
display: flex;
flex-direction: column;
gap: 6px;
`;

export const ToastList: React.FC = () => {
const { notifications } = useNotificationStore();

return (
<Container>
{notifications
.filter(({ dismissed }) => !dismissed)
.map((notif) => (
<Toast key={`toast-${notif.id}`} {...notif} />
))}
</Container>
);
};
Loading
Loading