Skip to content

Commit

Permalink
🐛 Fixed issue with logger component scroll and page reload
Browse files Browse the repository at this point in the history
  • Loading branch information
abdheshnayak committed Mar 11, 2024
1 parent 9a43afd commit 06b8746
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 76 deletions.
5 changes: 3 additions & 2 deletions lib/app-setup/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import Container from '~/components/atoms/container';
import ProgressContainer, {
useProgress,
} from '~/components/atoms/progress-bar';
// import { SelectPortalContainer } from '~/components/atoms/select';
import Tooltip from '~/components/atoms/tooltip';
import { BrandLogo } from '~/components/branding/brand-logo';
import { ToastContainer } from '~/components/molecule/toast';
Expand All @@ -30,7 +29,8 @@ import styleZenerSelect from '@oshq/react-select/index.css';
import stylesUrl from '~/design-system/index.css';
import rcss from 'react-highlightjs-logs/dist/index.css';
import tailwindBase from '~/design-system/tailwind-base.js';
import { isDev } from '../client/helpers/log';
import { ReloadIndicator } from '~/lib/client/components/reload-indicator';
import { isDev } from '~/lib/client/helpers/log';
import { getClientEnv, getServerEnv } from '../configs/base-url.cjs';

export const links: LinksFunction = () => [
Expand Down Expand Up @@ -202,6 +202,7 @@ const Root = ({
<LiveReload port={443} />
<Tooltip.Provider>
<ProgressContainer>
<ReloadIndicator />
<NonIdleProgressBar />
<ToastContainer position="bottom-left" />
<Wrapper>
Expand Down
32 changes: 11 additions & 21 deletions lib/client/components/logger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import React, {
useRef,
useState,
} from 'react';
import { ViewportList } from 'react-viewport-list';
import { ViewportList, ViewportListRef } from 'react-viewport-list';
import { dayjs } from '~/components/molecule/dayjs';
import {
ISearchInfProps,
Expand All @@ -28,6 +28,7 @@ import { generatePlainColor } from '~/root/lib/utils/color-generator';
import ReactPulsable from 'react-pulsable';
import { ChildrenProps } from '~/components/types';
import { logsMockData } from './dummy';
import { LoadingIndicator } from '../reload-indicator';

const pulsableContext = createContext(false);

Expand Down Expand Up @@ -499,22 +500,14 @@ const LogBlock = ({

const [showAll, setShowAll] = useState(true);

const ref = useRef(null);
const ref = useRef<ViewportListRef>(null);

useEffect(() => {
(async () => {
if (
follow &&
ref.current &&
// @ts-ignore
typeof ref.current.scrollToIndex === 'function'
) {
// @ts-ignore
ref.current.scrollToIndex({
index: data.length - 1,
});
}
})();
if (follow && ref.current) {
ref.current.scrollToIndex({
index: data.length - 1,
});
}
}, [data, maxLines]);

return (
Expand Down Expand Up @@ -575,13 +568,8 @@ const LogBlock = ({
<div
className="flex-1 flex flex-col pb-8 scroll-container"
style={{ lineHeight: `${fontSize * 1.5}px` }}
ref={ref}
>
<ViewportList
items={showAll ? data : searchResult}
ref={ref}
// viewportRef={listRef}
>
<ViewportList items={showAll ? data : searchResult} ref={ref}>
{(log, index) => {
return (
<LogLine
Expand Down Expand Up @@ -750,6 +738,8 @@ const LogComp = ({
</div>
</div>
</div>

<LoadingIndicator className="absolute z-20 bottom-lg right-lg" />
</div>
</Pulsable>
)}
Expand Down
37 changes: 37 additions & 0 deletions lib/client/components/reload-indicator.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { CircleFill, CircleNotch } from '@jengaicons/react';
import { useRevalidator } from '@remix-run/react';
import { cn } from '~/components/utils';

export const LoadingIndicator = ({
className,
size = 1,
}: {
className?: string;
size?: number;
}) => {
return (
<div
className={cn(
'text-text-warning animate-spin flex items-center justify-center aspect-square',
className
)}
>
<CircleNotch size={16 * size} className="relative" />
<CircleFill size={8 * size} className="absolute" />
</div>
);
};

export const ReloadIndicator = () => {
const { state } = useRevalidator();

if (state === 'loading') {
return (
<div className="fixed z-20 bottom-lg right-lg">
<LoadingIndicator className="" size={1} />
</div>
);
}

return null;
};
8 changes: 4 additions & 4 deletions lib/client/helpers/reloader.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useLocation, useNavigate } from '@remix-run/react';
import { useRevalidator } from '@remix-run/react';

export const useReload = () => {
const location = useLocation();
const navigate = useNavigate();
const revalidator = useRevalidator();

return () => {
navigate(location.pathname + location.search, { replace: true });
revalidator.revalidate();
};
};
4 changes: 2 additions & 2 deletions lib/configs/base-url.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ const baseUrls = () => {
cookieDomain,
baseUrl: bUrl,
githubAppName: 'kloudlite-dev',
socketUrl: `wss://websocket.${bUrl}`,
// socketUrl: `wss://websocket.kloudlite.io`,
// socketUrl: `wss://websocket.${bUrl}`,
socketUrl: `wss://websocket.kloudlite.io`,
observeUrl: `https://observe.${bUrl}`,
};
};
Expand Down
11 changes: 6 additions & 5 deletions src/apps/console/components/listV2.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as RovingFocusGroup from '@radix-ui/react-roving-focus';
import { KeyboardEvent, ReactNode, useRef } from 'react';
import { cn } from '~/components/utils';
import logger from '~/root/lib/client/helpers/log';
import { LoadingPlaceHolder } from './loading';

const focusableElement = 'a[href], button, input, select, textarea';
Expand Down Expand Up @@ -77,7 +78,7 @@ const handleKeyNavigation = (
}
}
} catch {
console.log('Error focusing');
logger.error('Error focusing');
}
};

Expand Down Expand Up @@ -224,7 +225,7 @@ const Root = ({
}: IRoot) => {
const ref = useRef<HTMLDivElement>(null);

console.log(data);
// logger.log(data);
return (
<>
{!loading && (
Expand All @@ -250,7 +251,7 @@ const Root = ({
}
}
} catch {
console.log('Error Focusing');
logger.error('Error Focusing');
}
}}
onKeyDown={(e) => {
Expand All @@ -265,7 +266,7 @@ const Root = ({
)}
>
{data?.headers.map((h, index) => (
<div key={index} className={cn(h.className)}>
<div key={`${index + h.name}`} className={cn(h.className)}>
{h.render()}
</div>
))}
Expand All @@ -274,7 +275,7 @@ const Root = ({
{data?.rows.map((r, index) => (
<RowBase
linkComponent={linkComponent}
key={index}
key={`${index + (r.to || '')}`}
columns={r.columns}
to={r.to}
headers={data.headers}
Expand Down
23 changes: 22 additions & 1 deletion src/apps/console/components/loading.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Spinner } from '@jengaicons/react';
import { CircleFill, CircleNotch, Spinner } from '@jengaicons/react';
import { ReactNode } from 'react';
import { cn } from '~/components/utils';

export const LoadingPlaceHolder = ({
height = 100,
Expand All @@ -20,3 +21,23 @@ export const LoadingPlaceHolder = ({
</div>
);
};

export const LoadingIndicator = ({
className,
size = 1,
}: {
className?: string;
size?: 1 | 2 | 3;
}) => {
return (
<div
className={cn(
'text-text-warning animate-spin flex items-center justify-center aspect-square',
className
)}
>
<CircleNotch size={16 * size} />
<CircleFill size={8 * size} className="absolute" />
</div>
);
};
92 changes: 52 additions & 40 deletions src/apps/console/routes/_main+/$account+/projects/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { IRemixCtx } from '~/root/lib/types/common';
import fake from '~/root/fake-data-generator/fake';
import { ensureAccountSet } from '~/console/server/utils/auth-utils';
import { GQLServerHandler } from '~/console/server/gql/saved-queries';
import { useReload } from '~/root/lib/client/helpers/reloader';
import Tools from './tools';
import ProjectResourcesV2 from './project-resources-v2';

Expand Down Expand Up @@ -153,47 +154,58 @@ const Projects = () => {
};
};

return (
<LoadingComp
data={promise}
skeletonData={{
projectsData: fake.ConsoleListProjectsQuery.core_listProjects as any,
clustersCount: 1,
cloudProviderSecretsCount: 1,
}}
>
{({ projectsData, clustersCount, cloudProviderSecretsCount }) => {
const projects = projectsData.edges?.map(({ node }) => node);
if (!projects) {
return null;
}
const reloadPage = useReload();

return (
<Wrapper
header={{
title: 'Projects',
action: projects.length > 0 && (
<Button
variant="primary"
content="Create Project"
prefix={<PlusFill />}
to={`/${account}/new-project`}
LinkComponent={Link}
/>
),
}}
empty={getEmptyState({
projectLength: projects.length,
clustersLength: clustersCount,
secretsLength: cloudProviderSecretsCount,
})}
tools={<Tools />}
>
<ProjectResourcesV2 items={projects} />
</Wrapper>
);
}}
</LoadingComp>
return (
<div>
<div
onClick={() => {
reloadPage();
}}
>
reloadPage
</div>
<LoadingComp
data={promise}
skeletonData={{
projectsData: fake.ConsoleListProjectsQuery.core_listProjects as any,
clustersCount: 1,
cloudProviderSecretsCount: 1,
}}
>
{({ projectsData, clustersCount, cloudProviderSecretsCount }) => {
const projects = projectsData.edges?.map(({ node }) => node);
if (!projects) {
return null;
}

return (
<Wrapper
header={{
title: 'Projects',
action: projects.length > 0 && (
<Button
variant="primary"
content="Create Project"
prefix={<PlusFill />}
to={`/${account}/new-project`}
LinkComponent={Link}
/>
),
}}
empty={getEmptyState({
projectLength: projects.length,
clustersLength: clustersCount,
secretsLength: cloudProviderSecretsCount,
})}
tools={<Tools />}
>
<ProjectResourcesV2 items={projects} />
</Wrapper>
);
}}
</LoadingComp>
</div>
);
};

Expand Down
3 changes: 2 additions & 1 deletion src/design-system/components/atoms/animate-hide.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AnimatePresence, motion } from 'framer-motion';
import { ReactNode } from 'react';
import { cn } from '../utils';

interface IAnimateHide {
children: ReactNode;
Expand Down Expand Up @@ -35,7 +36,7 @@ const AnimateHide = ({
height: 0,
y: -5,
}}
className={className}
className={cn(className, 'overflow-hidden')}
>
{children}
</motion.div>
Expand Down

0 comments on commit 06b8746

Please sign in to comment.