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-1624]: refactor existing components in preparation for notifications #1697

Merged
merged 22 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 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
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
41 changes: 17 additions & 24 deletions frontend/webapp/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
'use client';
import { useEffect } from 'react';
import { useConfig } from '@/hooks';
import { ROUTES, CONFIG } from '@/utils';
import { useRouter } from 'next/navigation';
import { addNotification, store } from '@/store';
import { useConfig, useNotify } from '@/hooks';
import { Loader } from '@keyval-dev/design-system';

export default function App() {
const router = useRouter();
const notify = useNotify();
const { data, error } = useConfig();

useEffect(() => {
data && renderCurrentPage();
}, [data, error]);

useEffect(() => {
if (!error) return;
store.dispatch(
addNotification({
id: '1',
if (error) {
notify({
message: 'An error occurred',
title: 'Error',
type: 'error',
target: 'notification',
crdType: 'notification',
})
);
router.push(ROUTES.OVERVIEW);
}, [error]);
});

function renderCurrentPage() {
const { installation } = data;
router.push(ROUTES.OVERVIEW);
} else if (data) {
const { installation } = data;

switch (installation) {
case CONFIG.NEW:
case CONFIG.APPS_SELECTED:
router.push(ROUTES.CHOOSE_SOURCES);
break;
case CONFIG.FINISHED:
router.push(ROUTES.OVERVIEW);
switch (installation) {
case CONFIG.NEW:
case CONFIG.APPS_SELECTED:
router.push(ROUTES.CHOOSE_SOURCES);
break;
case CONFIG.FINISHED:
router.push(ROUTES.OVERVIEW);
}
}
}
}, [data, error]);

return <Loader />;
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { NotificationNote } from '@/reuseable-components';
import styled from 'styled-components';

export const ConnectionNotification = ({
showConnectionError,
destination,
}) => (
export const ConnectionNotification = ({ showConnectionError, destination }) => (
<>
{showConnectionError && (
<NotificationNoteWrapper>
<NotificationNote
type="error"
text="Connection failed. Please check your input and try again."
/>
<NotificationNote type='error' message='Connection failed. Please check your input and try again.' />
</NotificationNoteWrapper>
)}
{destination?.fields && !showConnectionError && (
<NotificationNoteWrapper>
<NotificationNote
type="default"
text={`Odigos autocompleted ${destination.displayName} connection details.`}
/>
<NotificationNote type='default' message={`Odigos autocompleted ${destination.displayName} connection details.`} />
</NotificationNoteWrapper>
)}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function ChooseDestinationContainer() {
<NotificationNoteWrapper>
<NotificationNote
type={'warning'}
text={'No sources selected.'}
message={'No sources selected.'}
action={{
label: 'Select sources',
onClick: () => router.push('/choose-sources'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const AddRuleModal: React.FC<Props> = ({ isOpen, onClose }) => {
/>
<NotificationNote
type='info'
text='We currently support one rule. We’ll be adding new rule types in the near future.'
message='We currently support one rule. We’ll be adding new rule types in the near future.'
style={{ marginTop: '24px' }}
/>
<AutocompleteInput
Expand Down
54 changes: 21 additions & 33 deletions frontend/webapp/hooks/useSSE.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { useEffect, useRef, useState } from 'react';
import { API } from '@/utils';
import { addNotification, store } from '@/store';
import { useNotify } from './useNotify';

export function useSSE() {
const notify = useNotify();
const eventBuffer = useRef({});
const [retryCount, setRetryCount] = useState(0);
const maxRetries = 10;
Expand All @@ -25,10 +26,7 @@ export function useSSE() {
};

// Check if the event is already in the buffer
if (
eventBuffer.current[key] &&
eventBuffer.current[key].id > Date.now() - 2000
) {
if (eventBuffer.current[key] && eventBuffer.current[key].id > Date.now() - 2000) {
eventBuffer.current[key] = notification;
return;
} else {
Expand All @@ -37,16 +35,13 @@ export function useSSE() {
}

// Dispatch the notification to the store
store.dispatch(
addNotification({
id: eventBuffer.current[key].id,
message: eventBuffer.current[key].message,
title: eventBuffer.current[key].title,
type: eventBuffer.current[key].type,
target: eventBuffer.current[key].target,
crdType: eventBuffer.current[key].crdType,
})
);
notify({
message: eventBuffer.current[key].message,
title: eventBuffer.current[key].title,
type: eventBuffer.current[key].type,
target: eventBuffer.current[key].target,
crdType: eventBuffer.current[key].crdType,
});

// Reset retry count on successful connection
setRetryCount(0);
Expand All @@ -60,31 +55,24 @@ export function useSSE() {
setRetryCount((prevRetryCount) => {
if (prevRetryCount < maxRetries) {
const newRetryCount = prevRetryCount + 1;
const retryTimeout = Math.min(
10000,
1000 * Math.pow(2, newRetryCount)
);
const retryTimeout = Math.min(10000, 1000 * Math.pow(2, newRetryCount));

setTimeout(() => {
connect();
}, retryTimeout);

return newRetryCount;
} else {
console.error(
'Max retries reached. Could not reconnect to EventSource.'
);
store.dispatch(
addNotification({
id: Date.now().toString(),
message:
'Connection to the server failed. Please reboot the application.',
title: 'Connection Error',
type: 'error',
target: 'system',
crdType: 'connection',
})
);
console.error('Max retries reached. Could not reconnect to EventSource.');

notify({
message: 'Connection to the server failed. Please reboot the application.',
title: 'Connection Error',
type: 'error',
target: 'system',
crdType: 'connection',
});

return prevRetryCount;
}
});
Expand Down
24 changes: 5 additions & 19 deletions frontend/webapp/reuseable-components/divider/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,14 @@ interface DividerProps {
}

const StyledDivider = styled.div<DividerProps>`
width: ${({ orientation, thickness }) =>
orientation === 'vertical' ? `${thickness}px` : '100%'};
height: ${({ orientation, thickness }) =>
orientation === 'horizontal' ? `${thickness}px` : '100%'};
width: ${({ orientation, thickness }) => (orientation === 'vertical' ? `${thickness}px` : '100%')};
height: ${({ orientation, thickness }) => (orientation === 'horizontal' ? `${thickness}px` : '100%')};
background-color: ${({ color, theme }) => color || theme.colors.border};
margin: ${({ margin }) => margin || '8px 0'};
margin: ${({ orientation, margin }) => margin || (orientation === 'horizontal' ? '8px 0' : '0 8px')};
`;

const Divider: React.FC<DividerProps> = ({
thickness = 1,
color,
margin,
orientation = 'horizontal',
}) => {
return (
<StyledDivider
thickness={thickness}
color={color}
margin={margin}
orientation={orientation}
/>
);
const Divider: React.FC<DividerProps> = ({ thickness = 1, color, margin, orientation = 'horizontal' }) => {
return <StyledDivider thickness={thickness} color={color} margin={margin} orientation={orientation} />;
};

export { Divider };
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const BaseNode = ({ nodeWidth, isConnectable, data }: BaseNodeProps) => {
{renderStatus()}
</FooterWrapper>
</BodyWrapper>
{isError ? <Image src={getStatusIcon(false)} alt='' width={20} height={20} /> : null}
{isError ? <Image src={getStatusIcon('error')} alt='' width={20} height={20} /> : null}
{renderHandles()}
</BaseNodeContainer>
);
Expand Down
Loading
Loading