From 6e03b63a97a3842f93e552c56433d634da741840 Mon Sep 17 00:00:00 2001 From: Abdhesh Nayak Date: Mon, 12 Feb 2024 19:17:33 +0530 Subject: [PATCH] :art: Improved logs --- lib/client/helpers/socket-context.tsx | 193 ----------- lib/client/helpers/socket/context.tsx | 299 ++++++++++++++++++ lib/client/helpers/socket/useSockLogs.tsx | 42 +++ lib/client/hooks/use-debounce.ts | 3 - src/apps/console/components/logger/index.tsx | 19 +- .../components/logger/useSocketLogs.tsx | 71 +++-- src/apps/console/root.tsx | 14 +- .../$environment+/apps/apps-resources.tsx | 27 +- .../routers/router-resources.tsx | 4 - src/apps/console/routes/test.tsx | 19 +- src/apps/console/routes/test2/_index.tsx | 40 +-- src/apps/console/server/r-utils/common.ts | 32 +- 12 files changed, 447 insertions(+), 316 deletions(-) delete mode 100644 lib/client/helpers/socket-context.tsx create mode 100644 lib/client/helpers/socket/context.tsx create mode 100644 lib/client/helpers/socket/useSockLogs.tsx diff --git a/lib/client/helpers/socket-context.tsx b/lib/client/helpers/socket-context.tsx deleted file mode 100644 index 1ca6b9366..000000000 --- a/lib/client/helpers/socket-context.tsx +++ /dev/null @@ -1,193 +0,0 @@ -import { createContext, useContext, useEffect, useMemo } from 'react'; -import * as sock from 'websocket'; -import { v4 as uuid } from 'uuid'; -import { socketUrl } from '~/lib/configs/base-url.cjs'; -import { ChildrenProps } from '~/components/types'; -import logger from './log'; -import { NonNullableString } from '../../types/common'; -import { useReload } from './reloader'; - -type Ievent = 'subscribe' | 'unsubscribe' | NonNullableString; - -type IMessage = { - data: string; - event: Ievent; -}; - -const message = ({ event, data }: IMessage): string => { - return JSON.stringify({ event, data }); -}; - -const socketContextDefaultValue: { - subscribe: ( - topic: string, - callback: (arg: { topic: string; message: string }) => void - ) => string; - unsubscribe: (topic: string, id: string) => void; -} = { - subscribe: (): string => '', - unsubscribe: (): void => {}, -}; - -const createSocketContext = () => { - if (typeof window === 'undefined') { - return socketContextDefaultValue; - } - - const callbacks: { - [key: string]: { - [key: string]: (arg: { topic: string; message: string }) => void; - }; - } = {}; - - const wsclient = new Promise((res, rej) => { - try { - // eslint-disable-next-line new-cap - const w = new sock.w3cwebsocket(`${socketUrl}/ws`, '', '', {}); - - w.onmessage = (msg) => { - try { - const m: { - topic: string; - message: string; - type: 'update' | 'error' | 'info'; - } = JSON.parse(msg.data as string); - - if (m.type === 'error') { - console.error(m.message); - return; - } - - if (m.type === 'info') { - console.log(m.message); - return; - } - - Object.values(callbacks[m.topic]).forEach((cb) => { - cb(m); - }); - } catch (err) { - console.error(err); - } - }; - - w.onopen = () => { - res(w); - }; - - w.onerror = (e) => { - rej(e); - }; - - w.onclose = () => { - // wsclient.send(newMessage({ event: 'unsubscribe', data: 'test' })); - logger.log('socket disconnected'); - }; - } catch (e) { - rej(e); - } - }); - - return { - subscribe: ( - topic: string, - callback: (arg: { topic: string; message: string }) => void - ): string => { - (async () => { - if (!callbacks[topic]) { - callbacks[topic] = {}; - - try { - const w = await wsclient; - - w.send( - message({ - event: 'subscribe', - data: topic, - }) - ); - - logger.log('subscribed to', topic); - } catch (err) { - logger.warn(err); - } - } - })(); - - const id = uuid(); - callbacks[topic][id] = callback; - return id; - }, - - unsubscribe: (topic: string, id: string) => { - (async () => { - delete callbacks[topic][id]; - - try { - const w = await wsclient; - - if (Object.keys(callbacks[topic]).length === 0) { - w.send( - message({ - event: 'unsubscribe', - data: topic, - }) - ); - } - } catch (err) { - logger.warn(err); - } - })(); - }, - }; -}; - -const SocketContext = createContext(socketContextDefaultValue); - -const SocketProvider = ({ children }: ChildrenProps) => { - const socket = useMemo(() => { - if (typeof window !== 'undefined') { - return createSocketContext(); - } - - return socketContextDefaultValue; - }, [typeof window]); - - return ( - {children} - ); -}; - -export const useSubscribe = ( - topics: string[], - callback: (arg: { topic: string; message: string }) => void, - dependencies: any[] = [] -) => { - const t = typeof topics === 'string' ? [topics] : topics; - - const { subscribe, unsubscribe } = useContext(SocketContext); - - useEffect(() => { - const subscriptions = t.map((topic) => ({ - topic, - id: subscribe(topic, callback), - })); - - return () => { - subscriptions.forEach(({ topic, id }) => unsubscribe(topic, id)); - }; - }, [...dependencies, ...t]); -}; - -export const useWatch = (...topics: string[]) => { - const reloadPage = useReload(); - useSubscribe( - topics, - () => { - reloadPage(); - }, - topics - ); -}; - -export default SocketProvider; diff --git a/lib/client/helpers/socket/context.tsx b/lib/client/helpers/socket/context.tsx new file mode 100644 index 000000000..9b01cd669 --- /dev/null +++ b/lib/client/helpers/socket/context.tsx @@ -0,0 +1,299 @@ +import { + createContext, + useCallback, + useContext, + useEffect, + useMemo, + useRef, + useState, +} from 'react'; +import * as wsock from 'websocket'; +import { ChildrenProps } from '~/components/types'; +import logger from '~/root/lib/client/helpers/log'; +import useDebounce from '~/root/lib/client/hooks/use-debounce'; +import { socketUrl } from '~/root/lib/configs/base-url.cjs'; + +type IFor = 'logs' | 'resource-update'; + +interface ISocketResp { + type: 'response' | 'error' | 'info'; + for: IFor; + message: string; + id: string; + data: T; +} + +type IData = { + event?: string; + id: string; +}; + +interface ISocketMsg { + for: IFor; + data: T; +} + +interface IResponses { + [key: string | IFor]: { + [id: string]: ISocketResp[]; + }; +} + +type IsendMsg = (msg: ISocketMsg) => void; + +const Context = createContext<{ + responses: IResponses; + errors: IResponses; + infos: IResponses; + sendMsg: IsendMsg; + clear: (msg: ISocketMsg) => void; +}>({ + clear: () => {}, + responses: {}, + errors: {}, + infos: {}, + sendMsg: () => {}, +}); + +export const useSubscribe = ( + msg: ISocketMsg, + dep: never[] +) => { + const { + sendMsg, + responses, + infos: i, + errors: e, + clear, + } = useContext(Context); + + const [resp, setResp] = useState([]); + const [subscribed, setSubscribed] = useState(false); + const [errors, setErrors] = useState([]); + const [infos, setInfos] = useState([]); + + useEffect(() => { + (async () => { + setResp(responses[msg.for]?.[msg.data.id || 'default'] || []); + + setErrors(e[msg.for]?.[msg.data.id || 'default'] || []); + setInfos(i[msg.for]?.[msg.data.id || 'default'] || []); + + if (resp.length || i[msg.for]?.[msg.data.id || 'default']?.length) { + setSubscribed(true); + } + })(); + }, [responses]); + + useDebounce( + () => { + console.log('subscribing'); + sendMsg({ ...msg, data: { ...msg.data, event: 'subscribe' } }); + + return () => { + console.log('unsubscribing'); + clear(msg); + setSubscribed(false); + sendMsg({ ...msg, data: { ...msg.data, event: 'unsubscribe' } }); + }; + }, + 1000, + [...dep] + ); + + return { + responses: resp, + subscribed, + infos, + errors, + }; +}; + +export const SockProvider = ({ children }: ChildrenProps) => { + const sockPromise = useRef | null>(null); + + const [responses, setResponses] = useState({}); + const [errors, setErrors] = useState({}); + const [infos, setInfos] = useState({}); + + const setResp = useCallback((resp: ISocketResp) => { + setResponses((s) => { + const key = resp.for; + const { id } = resp; + return { + ...s, + [key]: { + ...s[key], + [id]: [...(s[key]?.[id] || []), resp], + }, + }; + }); + }, []); + + const setError = useCallback((resp: ISocketResp) => { + setErrors((s) => { + const key = resp.for; + const { id } = resp; + return { + ...s, + [key]: { + ...s[key], + [id]: [...(s[key]?.[id] || []), resp], + }, + }; + }); + }, []); + + const setInfo = useCallback((resp: ISocketResp) => { + setInfos((s) => { + const key = resp.for; + const { id } = resp; + return { + ...s, + [key]: { + ...s[key], + [id]: [...(s[key]?.[id] || []), resp], + }, + }; + }); + }, []); + + const onMessage = useCallback((msg: wsock.IMessageEvent) => { + try { + const m: ISocketResp = JSON.parse(msg.data as string); + + switch (m.type) { + case 'response': + setResp(m); + break; + + case 'info': + setInfo(m); + break; + case 'error': + setError(m); + break; + default: + logger.log('unknown message', m); + } + } catch (err) { + console.error(err); + } + }, []); + + useDebounce( + () => { + if (typeof window !== 'undefined') { + try { + sockPromise.current = new Promise((res, rej) => { + let rejected = false; + try { + // eslint-disable-next-line new-cap + const w = new wsock.w3cwebsocket(`${socketUrl}/ws`, '', '', {}); + + w.onmessage = onMessage; + + w.onopen = () => { + res(w); + }; + + w.onerror = (e) => { + console.error(e); + if (!rejected) { + rejected = true; + rej(e); + } + }; + + w.onclose = () => {}; + } catch (e) { + rej(e); + } + }); + } catch (e) { + console.log(e); + } + } + }, + 1000, + [] + ); + + const sendMsg = useCallback( + async (msg: ISocketMsg) => { + if (!sockPromise.current) { + logger.log('no socket connection'); + return; + } + try { + const w = await sockPromise.current; + if (!w) { + logger.log('no socket connection'); + return; + } + + w.send(JSON.stringify(msg)); + } catch (err) { + console.error(err); + } + }, + [sockPromise.current] + ); + + const clear = useCallback( + (msg: ISocketMsg) => { + setResponses((s) => { + const key = msg.for; + const id = msg.data.id || 'default'; + return { + ...s, + [key]: { + ...s[key], + [id]: [], + }, + }; + }); + + setErrors((s) => { + const key = msg.for; + const id = msg.data.id || 'default'; + return { + ...s, + [key]: { + ...s[key], + [id]: [], + }, + }; + }); + + setInfos((s) => { + const key = msg.for; + const id = msg.data.id || 'default'; + return { + ...s, + [key]: { + ...s[key], + [id]: [], + }, + }; + }); + }, + [responses] + ); + + return ( + { + return { + clear, + responses, + errors, + infos, + sendMsg, + }; + }, [responses, errors, infos, sendMsg])} + > + {children} + + ); +}; diff --git a/lib/client/helpers/socket/useSockLogs.tsx b/lib/client/helpers/socket/useSockLogs.tsx new file mode 100644 index 000000000..5b532a2f2 --- /dev/null +++ b/lib/client/helpers/socket/useSockLogs.tsx @@ -0,0 +1,42 @@ +import { useEffect, useState } from 'react'; +import { useSubscribe } from './context'; + +interface IuseLog { + account: string; + cluster: string; + trackingId: string; +} + +export const useSocketLogs = ({ account, cluster, trackingId }: IuseLog) => { + const { responses, subscribed, errors } = useSubscribe( + { + for: 'logs', + data: { + id: `${account}.${cluster}.${trackingId}`, + spec: { + account, + cluster, + trackingId, + }, + }, + }, + [] + ); + + const [isLoading, setIsLoading] = useState(true); + + useEffect(() => { + if (subscribed && isLoading) { + setIsLoading(false); + } else if (!subscribed && !isLoading) { + setIsLoading(true); + } + }, []); + + return { + logs: responses, + errors, + isLoading, + subscribed, + }; +}; diff --git a/lib/client/hooks/use-debounce.ts b/lib/client/hooks/use-debounce.ts index f8e9eff45..a96524bf3 100644 --- a/lib/client/hooks/use-debounce.ts +++ b/lib/client/hooks/use-debounce.ts @@ -19,10 +19,7 @@ const useDebounce: IuseDebounce = (action, delay, dep = []) => { clearTimeout(handler); if (typeof resp === 'function') { resp(); - return; } - - console.log('resp', resp); }; }, [delay, ...dep] // Only re-call effect if value or delay changes diff --git a/src/apps/console/components/logger/index.tsx b/src/apps/console/components/logger/index.tsx index 39429addc..8b032d141 100644 --- a/src/apps/console/components/logger/index.tsx +++ b/src/apps/console/components/logger/index.tsx @@ -13,10 +13,11 @@ import { useSearch, } from '~/root/lib/client/helpers/search-filter'; import useClass from '~/root/lib/client/hooks/use-class'; +import { useSocketLogs } from '~/root/lib/client/helpers/socket/useSockLogs'; import { generatePlainColor } from '../color-generator'; import Pulsable from '../pulsable'; import { logsMockData } from '../../dummy/data'; -import { ILog, ISocketMessage, IuseLog, useSocketLogs } from './useSocketLogs'; +import { ILog, ISocketMessage, IuseLog } from './useSocketLogs'; const hoverClass = `hover:bg-[#ddd]`; const hoverClassDark = `hover:bg-[#333]`; @@ -341,7 +342,7 @@ const LogLine = ({ }: ILogLine) => { return (
@@ -543,7 +544,7 @@ const LogBlock = ({ lines={data.length} showAll={showAll} key={getHashId( - `${log.message}${log.timestamp}${log.pod_name}${index}` + `${log.message}${log.timestamp}${log.podName}${index}` )} hideLineNumber={hideLineNumber} selectableLines={selectableLines} @@ -627,7 +628,7 @@ const LogComp = ({ } }, [fullScreen]); - const { logs, error, subscribed } = useSocketLogs(websocket); + const { logs, subscribed, errors } = useSocketLogs(websocket); const [isClientSide, setIsClientSide] = useState(false); @@ -688,13 +689,15 @@ const LogComp = ({ {!subscribed && logs.length === 0 && } - {error ? ( -
{error}
+ {errors.length ? ( +
{JSON.stringify(errors)}
) : ( logs.length > 0 && ( { + return d.data; + }), follow, dark, enableSearch, diff --git a/src/apps/console/components/logger/useSocketLogs.tsx b/src/apps/console/components/logger/useSocketLogs.tsx index 3e0511fc5..a3cfcfce3 100644 --- a/src/apps/console/components/logger/useSocketLogs.tsx +++ b/src/apps/console/components/logger/useSocketLogs.tsx @@ -9,12 +9,13 @@ import { import * as wsock from 'websocket'; import { dayjs } from '~/components/molecule/dayjs'; import { ChildrenProps } from '~/components/types'; +import logger from '~/root/lib/client/helpers/log'; import useDebounce from '~/root/lib/client/hooks/use-debounce'; import { socketUrl } from '~/root/lib/configs/base-url.cjs'; export type ILog = { - pod_name: string; - container_name: string; + podName: string; + containerName: string; message: string; timestamp: string; }; @@ -66,7 +67,7 @@ export const LogsProvider = ({ try { // eslint-disable-next-line new-cap const w = new wsock.w3cwebsocket( - url || `${socketUrl}/logs`, + url || `${socketUrl}/ws`, '', '', {} @@ -75,13 +76,16 @@ export const LogsProvider = ({ w.onmessage = (msg) => { try { const m: { - timestamp: string; message: string; - spec: { + data: { + message: string; + timestamp: string; podName: string; containerName: string; }; - type: 'update' | 'error' | 'info'; + id: string; + for: 'logs'; + type: 'response' | 'error' | 'info'; } = JSON.parse(msg.data as string); if (m.type === 'error') { @@ -98,22 +102,23 @@ export const LogsProvider = ({ return; } - if (m.type === 'update') { - console.log(m.message); - return; - } - - if (m.type === 'log') { + if (m.type === 'response') { + switch (m.for) { + case 'logs': + setLogs((s) => [ + ...s, + { + podName: m.data.podName, + containerName: m.data.containerName, + message: m.message, + timestamp: m.data.timestamp, + }, + ]); + break; + default: + logger.log('unknown message', m); + } // setIsLoading(false); - setLogs((s) => [ - ...s, - { - pod_name: m.spec.podName, - container_name: m.spec.containerName, - message: m.message, - timestamp: m.timestamp, - }, - ]); return; } @@ -148,7 +153,7 @@ export const LogsProvider = ({ useEffect(() => { const sorted = logs.sort((a, b) => { - const resp = a.pod_name.localeCompare(b.pod_name); + const resp = a.podName.localeCompare(b.podName); if (resp === 0) { return dayjs(a.timestamp).unix() - dayjs(b.timestamp).unix(); @@ -210,11 +215,14 @@ export const useSocketLogs = ({ account, cluster, trackingId }: IuseLog) => { sock?.send( JSON.stringify({ - event: 'subscribe', + for: 'logs', data: { - account, - cluster, - trackingId, + event: 'subscribe', + spec: { + account, + cluster, + trackingId, + }, }, }) ); @@ -228,11 +236,14 @@ export const useSocketLogs = ({ account, cluster, trackingId }: IuseLog) => { setSubscribed(false); sock?.send( JSON.stringify({ - event: 'unsubscribe', + for: 'logs', data: { - account, - cluster, - trackingId, + event: 'unsubscribe', + spec: { + account, + cluster, + trackingId, + }, }, }) ); diff --git a/src/apps/console/root.tsx b/src/apps/console/root.tsx index af1ee71c6..0eeebf550 100644 --- a/src/apps/console/root.tsx +++ b/src/apps/console/root.tsx @@ -1,6 +1,7 @@ /* eslint-disable react/jsx-no-useless-fragment */ import Root, { links as baseLinks } from '~/lib/app-setup/root'; import { ChildrenProps } from '~/components/types'; +import { SockProvider } from '~/root/lib/client/helpers/socket/context'; import authStylesUrl from './styles/index.css'; import highlightCss from './styles/hljs/tokyo-night-dark.min.css'; import { DataContextProvider } from './page-components/common-state'; @@ -20,17 +21,18 @@ export const links = () => { export { ErrorBoundary } from '~/lib/app-setup/root'; const Layout = ({ children }: ChildrenProps) => { - // return {children}; return <>{children}; }; const _Root = ({ ...props }) => { return ( - - - - - + + + + + + + ); }; diff --git a/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx b/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx index 80148c5ae..771841875 100644 --- a/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx +++ b/src/apps/console/routes/_main+/$account+/$project+/$environment+/apps/apps-resources.tsx @@ -23,7 +23,7 @@ import { useConsoleApi } from '~/console/server/gql/api-provider'; import { IApps } from '~/console/server/gql/queries/app-queries'; import { ExtractNodeType, - parseName, + parseName as pn, parseUpdateOrCreatedBy, parseUpdateOrCreatedOn, } from '~/console/server/r-utils/common'; @@ -31,7 +31,7 @@ import { handleError } from '~/root/lib/utils/common'; import { toast } from '~/components/molecule/toast'; import { useReload } from '~/root/lib/client/helpers/reloader'; import { listStatus } from '~/console/components/sync-status'; -import { IAppContext } from '../app+/$app+/_layout'; +import { IEnvironmentContext } from '../_layout'; const RESOURCE_NAME = 'app'; type BaseType = ExtractNodeType; @@ -39,7 +39,7 @@ type BaseType = ExtractNodeType; const parseItem = (item: ExtractNodeType) => { return { name: item.displayName, - id: parseName(item), + id: pn(item), intercept: item.spec.intercept, updateInfo: { author: `Updated by ${titleCase(parseUpdateOrCreatedBy(item))}`, @@ -116,7 +116,7 @@ interface IResource { onAction: OnAction; } -const GridView = ({ items = [], onAction }: IResource) => { +const GridView = ({ items = [], onAction: _ }: IResource) => { const { account, project, environment } = useParams(); return ( @@ -228,10 +228,17 @@ const ListView = ({ items = [], onAction }: IResource) => { const AppsResources = ({ items = [] }: Omit) => { const api = useConsoleApi(); - const { environment, project } = useParams(); - const { devicesForUser } = useOutletContext(); + const { environment, project, account } = useParams(); + const { devicesForUser } = useOutletContext(); const reload = useReload(); + // useWatchItems(items, (item) => ({ + // account, + // project, + // environment, + // app: pn(item), + // })); + const interceptApp = async (item: BaseType, intercept: boolean) => { if (!environment || !project) { throw new Error('Environment is required!.'); @@ -240,8 +247,8 @@ const AppsResources = ({ items = [] }: Omit) => { const device = devicesForUser[0]; try { const { errors } = await api.interceptApp({ - appname: parseName(item), - deviceName: parseName(device), + appname: pn(item), + deviceName: pn(device), envName: environment, intercept, projectName: project, @@ -265,7 +272,7 @@ const AppsResources = ({ items = [] }: Omit) => { try { const { errors } = await api.restartApp({ - appName: parseName(item), + appName: pn(item), envName: environment, projectName: project, }); @@ -274,7 +281,7 @@ const AppsResources = ({ items = [] }: Omit) => { throw errors[0]; } toast.success('App restarted successfully'); - reload(); + // reload(); } catch (error) { handleError(error); } diff --git a/src/apps/console/routes/_main+/$account+/$project+/$environment+/routers/router-resources.tsx b/src/apps/console/routes/_main+/$account+/$project+/$environment+/routers/router-resources.tsx index c9f03804a..cb78e4081 100644 --- a/src/apps/console/routes/_main+/$account+/$project+/$environment+/routers/router-resources.tsx +++ b/src/apps/console/routes/_main+/$account+/$project+/$environment+/routers/router-resources.tsx @@ -12,14 +12,12 @@ import Grid from '~/console/components/grid'; import List from '~/console/components/list'; import ListGridView from '~/console/components/list-grid-view'; import ResourceExtraAction from '~/console/components/resource-extra-action'; -import { useConsoleApi } from '~/console/server/gql/api-provider'; import { ExtractNodeType, parseName, parseUpdateOrCreatedBy, parseUpdateOrCreatedOn, } from '~/console/server/r-utils/common'; -import { useReload } from '~/root/lib/client/helpers/reloader'; import { handleError } from '~/root/lib/utils/common'; import { IRouters } from '~/console/server/gql/queries/router-queries'; import { Link, useParams } from '@remix-run/react'; @@ -168,8 +166,6 @@ const RouterResources = ({ items = [] }: { items: BaseType[] }) => { null ); const [visible, setVisible] = useState(null); - const api = useConsoleApi(); - const reloadPage = useReload(); const props: IResource = { items, diff --git a/src/apps/console/routes/test.tsx b/src/apps/console/routes/test.tsx index 6c408999a..5e9ae4409 100644 --- a/src/apps/console/routes/test.tsx +++ b/src/apps/console/routes/test.tsx @@ -1,9 +1,4 @@ import { useLoaderData } from '@remix-run/react'; -import SocketProvider, { - useSubscribe, - // useSubscribe, - useWatch, -} from '~/root/lib/client/helpers/socket-context'; export const loader = () => { return { @@ -12,14 +7,6 @@ export const loader = () => { }; const App = () => { - useSubscribe( - ['account:newteam.cluster'], - () => { - console.log('hi'); - }, - [] - ); - // useWatch('account:newteam.cluster'); // res-updates.account.acc-ruwibp-pf5jvcsew2rnl54kriv59.cluster.* // res-updates.account.accid.project.projid.env.envid.app.* @@ -30,9 +17,5 @@ const App = () => { }; export default () => { - return ( - - - - ); + return ; }; diff --git a/src/apps/console/routes/test2/_index.tsx b/src/apps/console/routes/test2/_index.tsx index f07a41ec2..315d5f0d7 100644 --- a/src/apps/console/routes/test2/_index.tsx +++ b/src/apps/console/routes/test2/_index.tsx @@ -1,34 +1,18 @@ -import LogComp from '~/console/components/logger'; -import axios from "axios"; -import {useEffect} from "react"; -import https from "https"; +import { useEffect } from 'react'; +import { useSocketLogs } from '~/root/lib/client/helpers/socket/useSockLogs'; const App = () => { + const resp = useSocketLogs({ + account: 'ab-641330', + cluster: 'ab-cluster-3', + trackingId: 'app-3ez2fpr-3oc8gqjib-ii5-pbat6d', + }); - useEffect(() => { - (async()=>{ - try{ - var axios1 =await axios({ - url:'http://10.13.0.1:17171', + useEffect(() => { + console.log(resp); + }, [resp]); - }); - - console.log((axios1)) - }catch(err){ - // console.log(err.message) - } - - })() - }, []); - return ( -
- kk -
- ); -}; - -const Logs = () => { - return ; + return
Logs
; }; -export default Logs; +export default App; diff --git a/src/apps/console/server/r-utils/common.ts b/src/apps/console/server/r-utils/common.ts index d97143f60..357a6b843 100644 --- a/src/apps/console/server/r-utils/common.ts +++ b/src/apps/console/server/r-utils/common.ts @@ -1,5 +1,5 @@ /* eslint-disable no-prototype-builtins */ -import { Params } from '@remix-run/react'; +// import { Params } from '@remix-run/react'; import { dayjs } from '~/components/molecule/dayjs'; import { FlatMapType, NonNullableString } from '~/root/lib/types/common'; import { @@ -13,9 +13,9 @@ type IparseNodes = { edges: Array<{ node: T }>; }; -interface IParamsCtx { - params: Params; -} +// interface IParamsCtx { +// params: Params; +// } // export const getProjectQuery = (ctx: IParamsCtx): ProjectId => { // const { project } = ctx.params; @@ -47,10 +47,10 @@ export const parseNodes = (resources: IparseNodes | undefined): T[] => type IparseName = | { - metadata?: { - name: string; - }; - } + metadata?: { + name: string; + }; + } | undefined | null; @@ -74,10 +74,10 @@ export const parseName = (resource: IparseName, ensure = false) => { type IparseNamespace = | { - metadata: { - namespace: string; - }; - } + metadata: { + namespace: string; + }; + } | undefined | null; @@ -86,10 +86,10 @@ export const parseNamespace = (resource: IparseNamespace) => type IparseTargetNs = | { - spec?: { - targetNamespace: string; - }; - } + spec?: { + targetNamespace: string; + }; + } | undefined | null;