Skip to content

Commit

Permalink
Merge branch 'features/design' of https://github.com/kloudlite/web in…
Browse files Browse the repository at this point in the history
…to features/design
  • Loading branch information
tulsiojha committed Jan 24, 2024
2 parents d69d843 + c1331ba commit b29eb0f
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 63 deletions.
5 changes: 3 additions & 2 deletions gql-queries-generator/doc/queries.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,7 @@ query consoleListBuildRuns($repoName: String!, $search: SearchBuildRuns, $pq: Cu
edges {
cursor
node {
id
clusterName
creationTime
markedForDeletion
Expand Down Expand Up @@ -3989,8 +3990,8 @@ query authCli_getDevice($clusterName: String!, $name: String!) {
}
}

query authCli_listDevices($pq: CursorPaginationIn) {
infra_listVPNDevices(pq: $pq) {
query authCli_listDevices($pq: CursorPaginationIn, $clusterName: String) {
infra_listVPNDevices(clusterName: $clusterName, pq: $pq) {
edges {
node {
displayName
Expand Down
31 changes: 17 additions & 14 deletions src/apps/auth/server/gql/queries/device-queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.core_updateVPNDevicePorts,
vars: (_: any) => { },
vars: (_: any) => {},
}
),
cli_CoreUpdateDeviceEnv: executor(
Expand All @@ -32,7 +32,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.core_updateVPNDeviceEnv,
vars: (_: any) => { },
vars: (_: any) => {},
}
),

Expand Down Expand Up @@ -69,7 +69,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.core_listVPNDevicesForUser,
vars: (_: any) => { },
vars: (_: any) => {},
}
),
cli_getCoreDevice: executor(
Expand Down Expand Up @@ -98,7 +98,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.core_getVPNDevice,
vars: (_: any) => { },
vars: (_: any) => {},
}
),
cli_createCoreDevice: executor(
Expand All @@ -117,7 +117,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.core_createVPNDevice,
vars: (_: any) => { },
vars: (_: any) => {},
}
),

Expand All @@ -129,7 +129,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.core_updateVPNDevicePorts,
vars: (_: any) => { },
vars: (_: any) => {},
}
),

Expand Down Expand Up @@ -170,14 +170,17 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.infra_getVPNDevice,
vars: (_: any) => { },
vars: (_: any) => {},
}
),

cli_listDevices: executor(
gql`
query Infra_listVPNDevices($pq: CursorPaginationIn) {
infra_listVPNDevices(pq: $pq) {
query Infra_listVPNDevices(
$pq: CursorPaginationIn
$clusterName: String
) {
infra_listVPNDevices(clusterName: $clusterName, pq: $pq) {
edges {
node {
displayName
Expand Down Expand Up @@ -210,7 +213,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.infra_listVPNDevices,
vars: (_: any) => { },
vars: (_: any) => {},
}
),

Expand Down Expand Up @@ -246,7 +249,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.infra_updateVPNDevice,
vars: (_: any) => { },
vars: (_: any) => {},
}
),

Expand All @@ -266,7 +269,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.infra_updateVPNDevicePorts,
vars: (_: any) => { },
vars: (_: any) => {},
}
),
cli_updateDeviceNs: executor(
Expand All @@ -285,7 +288,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.infra_updateVPNDeviceNs,
vars: (_: any) => { },
vars: (_: any) => {},
}
),
cli_createDevice: executor(
Expand All @@ -306,7 +309,7 @@ export const vpnQueries = (executor: IExecutor) => ({
`,
{
transformer: (data: any) => data.infra_createVPNDevice,
vars: (_: any) => { },
vars: (_: any) => {},
}
),
});
4 changes: 4 additions & 0 deletions src/apps/console/components/color-generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ const generateColor = (str = '#', contrast: Contrast = 'dark') => {
)}, ${generateColorFromName(`${str + str + str}`, cc, contrast)})`;
};

export const generatePlainColor = (str = '#') => {
const cc = colorCode(str);
return generateColorFromName(str, cc, 'dark');
};
export default generateColor;
10 changes: 7 additions & 3 deletions src/apps/console/components/logger.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import useClass from '~/root/lib/client/hooks/use-class';
import logger from '~/root/lib/client/helpers/log';
import { socketUrl } from '~/root/lib/configs/base-url.cjs';
import generateColor from './color-generator';
import { generatePlainColor } from './color-generator';
import Pulsable from './pulsable';
import { logsMockData } from '../dummy/data';

Expand Down Expand Up @@ -331,8 +331,9 @@ const LogLine = ({

<div
className="w-[3px] mr-xl ml-sm h-full pulsable pulsable-hidden"
style={{ backgroundImage: generateColor(log.pod_name) }}
style={{ background: generatePlainColor(log.pod_name) }}
/>

<div className="inline-flex gap-xl pulsable">
<HighlightIt
{...{
Expand Down Expand Up @@ -597,16 +598,18 @@ const useSocketLogs = ({ url, account, cluster, trackingId }: IuseLog) => {
};

w.onopen = () => {
// console.log('socket connected');
res(w);
};

w.onerror = (e) => {
console.error(e);
rej(e);
};

w.onclose = () => {
// wsclient.send(newMessage({ event: 'unsubscribe', data: 'test' }));
logger.log('socket disconnected');
// logger.log('socket disconnected');
};
} catch (e) {
rej(e);
Expand All @@ -633,6 +636,7 @@ const useSocketLogs = ({ url, account, cluster, trackingId }: IuseLog) => {
setIsLoading(true);

const client = await wsclient;
console.log('client', client);

setSocState(client);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { toast } from '~/components/molecule/toast';
import { generateKey, titleCase } from '~/components/utils';
import { cn, generateKey, titleCase } from '~/components/utils';
import {
ListBody,
ListTitle,
Expand All @@ -18,8 +18,21 @@ import {
} from '~/console/server/r-utils/common';
import { useReload } from '~/root/lib/client/helpers/reloader';
import { handleError } from '~/root/lib/utils/common';
import { useParams } from '@remix-run/react';
import { useOutletContext, useParams } from '@remix-run/react';
import { IBuildRuns } from '~/console/server/gql/queries/build-run-queries';
import AnimateHide from '~/components/atoms/animate-hide';
import LogComp from '~/console/components/logger';
import { Button } from '~/components/atoms/button';
import {
CheckCircleFill,
GitBranch,
PlayCircleFill,
Tag,
XCircleFill,
} from '@jengaicons/react';
import dayjs from 'dayjs';
import { Badge } from '~/components/atoms/badge';
import { IAccountContext } from '../../../_layout';

const RESOURCE_NAME = 'build run';
type BaseType = ExtractNodeType<IBuildRuns>;
Expand Down Expand Up @@ -77,13 +90,13 @@ const GridView = ({ items, onDelete }: IResource) => {
<ListTitle
title={name}
subtitle={id}
// action={
// <ExtraButton
// onDelete={() => {
// onDelete(item);
// }}
// />
// }
// action={
// <ExtraButton
// onDelete={() => {
// onDelete(item);
// }}
// />
// }
/>
),
},
Expand All @@ -102,21 +115,127 @@ const GridView = ({ items, onDelete }: IResource) => {
};

const ListItem = ({ item }: { item: BaseType }) => {
const { name, id, updateInfo } = parseItem(item);
const [open, setOpen] = useState<boolean>(false);
const { account } = useOutletContext<IAccountContext>();
const commitHash = item.metadata?.annotations['github.com/commit'];

// eslint-disable-next-line no-nested-ternary
const state: 'running' | 'done' | 'error' = item.status?.isReady
? 'done'
: item.status?.message?.RawMessage
? 'error'
: 'running';

const isLatest = dayjs(item.updateTime).isAfter(dayjs().subtract(3, 'hour'));

return (
<div className="flex flex-col">
<div className="flex flex-row">
<ListTitle title={name} subtitle={id} />
<div className="flex flex-col flex-1">
<div className="flex flex-row justify-between items-center gap-6xl">
<div className="flex justify-between items-center flex-1">
<div className="flex gap-xl items-center justify-start flex-1">
<div>
<span
className={cn({
'text-text-success': state === 'done',
'text-text-critical': state === 'error',
'text-text-warning': state === 'running',
})}
title={
// eslint-disable-next-line no-nested-ternary
state === 'done'
? 'Build completed successfully'
: state === 'error'
? 'Build failed'
: 'Build in progress'
}
>
{state === 'done' && (
<CheckCircleFill size={16} color="currentColor" />
)}

{state === 'error' && (
<XCircleFill size={16} color="currentColor" />
)}

{state === 'running' && (
<PlayCircleFill size={16} color="currentColor" />
)}
</span>
</div>
<ListTitle
title={
<div className="flex items-center gap-xl">
{item.metadata?.annotations['github.com/repository']}{' '}
</div>
}
subtitle={
<div className="flex items-center gap-md">
{`#${commitHash.substring(
commitHash.length - 7,
commitHash.length
)}`}
<GitBranch size={12} />
{item.metadata?.annotations['github.com/branch']}{' '}
</div>
}
/>
</div>

<div className="flex-1 flex items-center justify-center">
<div className="flex flex-row items-center gap-lg mb-md">
{item.spec?.registry.repo.tags.map((tag) => (
<button
key={tag}
className="rounded-full outline-none ring-offset-1 focus-visible:ring-2 focus-visible:ring-border-focus hover:underline text-text-primary"
>
<Badge type="info" icon={<Tag />}>
{tag}
</Badge>
</button>
))}
</div>
</div>
</div>

<div className="bodyMd text-text-soft truncate">
{parseUpdateOrCreatedOn(item)}
</div>

{/* <pre>{JSON.stringify(item, null, 2)}</pre> */}
{isLatest && (
<Button
size="sm"
variant="basic"
content={open ? 'Hide Logs' : 'Show Logs'}
onClick={() => setOpen((s) => !s)}
/>
)}
</div>
<div className="">Logs</div>

<AnimateHide show={open} className="w-full pt-4xl">
<LogComp
{...{
dark: true,
width: '100%',
height: '40rem',
title: 'Logs',
hideLines: true,
websocket: {
account: parseName(account),
cluster: item.clusterName,
trackingId: item.id,
},
}}
/>
</AnimateHide>
</div>
);
};
const ListView = ({ items, onDelete }: IResource) => {
return (
<List.Root>
{items.map((item, index) => {
const { name, id, updateInfo } = parseItem(item);
const { name, id } = parseItem(item);
const keyPrefix = `${RESOURCE_NAME}-${id}-${index}`;
return (
<List.Row
Expand All @@ -125,6 +244,7 @@ const ListView = ({ items, onDelete }: IResource) => {
columns={[
{
key: generateKey(keyPrefix, name + id),
className: 'w-full',
render: () => <ListItem item={item} />,
},
]}
Expand Down
Loading

0 comments on commit b29eb0f

Please sign in to comment.