Skip to content

Commit

Permalink
[TASK-844] chore(frontend): bugs party (#1129)
Browse files Browse the repository at this point in the history
this pr contains bug fixes and UX improvements
  • Loading branch information
alonkeyval committed Apr 24, 2024
1 parent e73578b commit a7576c3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 16 deletions.
3 changes: 1 addition & 2 deletions frontend/webapp/components/lists/empty.list/empty.list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const EmptyListWrapper = styled.div`
width: 100%;
margin-top: 130px;
display: flex;
gap: 6px;
flex-direction: column;
justify-content: center;
align-items: center;
Expand All @@ -26,9 +27,7 @@ export function EmptyList({ title, btnTitle, btnAction }: EmptyListProps) {
<Empty />
{title && (
<>
<br />
<KeyvalText size={14}>{title}</KeyvalText>
<br />
</>
)}
{btnAction && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export function DestinationContainer() {
<Container>
{!destinationList?.length ? (
<EmptyList
title={OVERVIEW.EMPTY_ACTION}
btnTitle={OVERVIEW.ADD_NEW_ACTION}
title={OVERVIEW.EMPTY_DESTINATION}
btnTitle={OVERVIEW.ADD_NEW_DESTINATION}
btnAction={handleAddDestination}
/>
) : (
Expand Down
40 changes: 34 additions & 6 deletions frontend/webapp/containers/overview/overview/data.flow/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use client';
import React, { useEffect, useState } from 'react';
import React, { useEffect, useRef, useState } from 'react';
import { useSearchParams } from 'next/navigation';
import { OverviewDataFlowWrapper } from './styled';
import { KeyvalDataFlow, KeyvalLoader } from '@/design.system';
import { useActions, useDestinations, useSources } from '@/hooks';
Expand All @@ -24,20 +25,25 @@ interface FlowEdge {
data?: any;
}

const POLL_DATA = 'poll';
const POLL_INTERVAL = 2000; // Interval in milliseconds between polls
const MAX_ATTEMPTS = 5; // Maximum number of polling attempts

export function DataFlowContainer() {
const [nodes, setNodes] = useState<FlowNode[]>();
const [edges, setEdges] = useState<FlowEdge[]>();
const [pollingAttempts, setPollingAttempts] = useState(0);

const { sources } = useSources();
const { actions } = useActions();
const { destinationList } = useDestinations();
const { sources, refetchSources } = useSources();
const { destinationList, refetchDestinations } = useDestinations();

const useSearch = useSearchParams();
const intervalId = useRef<NodeJS.Timer>();
useEffect(() => {
if (!sources || !destinationList || !actions) return;

const filteredActions = actions.filter(
(action) => action.spec.disabled !== true
);
const filteredActions = actions.filter((action) => !action.spec.disabled);

const { nodes, edges } = buildFlowNodesAndEdges(
sources,
Expand All @@ -48,6 +54,28 @@ export function DataFlowContainer() {
setEdges(edges);
}, [actions, destinationList, sources]);

useEffect(() => {
const pullData = useSearch.get(POLL_DATA);
if (pullData) {
intervalId.current = setInterval(() => {
Promise.all([refetchSources(), refetchDestinations()])
.then(() => {})
.catch(console.error);

setPollingAttempts((prev) => prev + 1);
}, POLL_INTERVAL);

return () => clearInterval(intervalId.current);
}
}, [refetchDestinations, refetchSources, pollingAttempts, useSearch]);

useEffect(() => {
if (pollingAttempts >= MAX_ATTEMPTS) {
clearInterval(intervalId.current);
return;
}
}, [pollingAttempts]);

if (!nodes || !edges) {
return <KeyvalLoader />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export const SectionContainerWrapper = styled.div`
max-height: 100%;
padding: 24px 32px;
overflow: scroll;
overflow-x: hidden;
`;
2 changes: 1 addition & 1 deletion frontend/webapp/hooks/destinations/useDestinations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useEffect, useState } from 'react';
import { getDestinations, getDestinationsTypes } from '@/services';

export function useDestinations() {
const { isLoading, data, isError, error } = useQuery(
const { isLoading, data } = useQuery(
[QUERIES.API_DESTINATION_TYPES],
getDestinationsTypes
);
Expand Down
2 changes: 1 addition & 1 deletion frontend/webapp/hooks/setup/useConnect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function useConnect() {
});

await mutateAsync(body, {
onSuccess: () => router.push(ROUTES.OVERVIEW),
onSuccess: () => router.push(`${ROUTES.OVERVIEW}?poll=true`),
onError: (error) => handleError(error),
});
} catch (error) {
Expand Down
10 changes: 6 additions & 4 deletions frontend/webapp/hooks/sources/useSources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ export function useSources() {
const [instrumentedNamespaces, setInstrumentedNamespaces] = useState<
Namespace[]
>([]);
const { data: sources, isLoading } = useQuery<ManagedSource[]>(
[QUERIES.API_SOURCES],
getSources
);
const {
data: sources,
isLoading,
refetch: refetchSources,
} = useQuery<ManagedSource[]>([QUERIES.API_SOURCES], getSources);

const { data: namespaces } = useQuery<{ namespaces: Namespace[] }>(
[QUERIES.API_NAMESPACES],
Expand Down Expand Up @@ -118,6 +119,7 @@ export function useSources() {

return {
upsertSources,
refetchSources,
sources: sortedSources || [],
isLoading,
sortSources,
Expand Down

0 comments on commit a7576c3

Please sign in to comment.