Skip to content

Commit

Permalink
feat: rework context controls
Browse files Browse the repository at this point in the history
  • Loading branch information
WitoDelnat committed Apr 17, 2023
1 parent d33c85a commit dc52b01
Show file tree
Hide file tree
Showing 24 changed files with 851 additions and 129 deletions.
16 changes: 12 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
"execa": "5.1.1",
"fast-json-stable-stringify": "2.1.0",
"flat": "5.0.2",
"framer-motion": "9.1.7",
"framer-motion": "10.10.0",
"git-url-parse": "13.1.0",
"html-to-image": "1.11.11",
"json-schema-faker": "0.5.0-rcv.46",
Expand Down
16 changes: 16 additions & 0 deletions src/assets/ClusterIndicationPlain.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions src/components/atoms/Tooltip/Tooltip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import {Tooltip as AntdTooltip, TooltipProps} from 'antd';

import {TOOLTIP_DELAY} from '@constants/constants';

export function Tooltip(props: TooltipProps) {
return <AntdTooltip mouseEnterDelay={TOOLTIP_DELAY} {...props} />;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import styled from 'styled-components';

import ClusterIndicationSvg from '@assets/ClusterIndicationPlain.svg';

import {Colors} from '@shared/styles';

export function ClusterIndication() {
return (
<Box>
<Content>
<div>Click here to connect from anywhere in the app</div>
</Content>
<Image alt="Cluster Indication" src={ClusterIndicationSvg} />
</Box>
);
}

const Box = styled.div`
position: absolute;
display: flex;
gap: 12px;
right: 128px;
`;

const Content = styled.div`
width: 200px;
height: 100px;
color: ${Colors.grey7};
display: flex;
flex-direction: column-reverse;
text-align: right;
`;

const Image = styled.img<{$right?: number}>`
width: 66px;
min-width: 66px;
`;
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
137 changes: 137 additions & 0 deletions src/components/organisms/Dashboard/Disconnected/DebugClusterDrawer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
import {useCallback, useEffect, useMemo, useState} from 'react';

import {Button, Drawer} from 'antd';

import {DateTime} from 'luxon';
import styled from 'styled-components';

import {Tooltip} from '@components/atoms/Tooltip/Tooltip';

import {useMainPaneDimensions} from '@utils/hooks';

import {ContextId} from '@shared/ipc';
import {Colors} from '@shared/styles';

import {useClusterDebug} from '../useClusterDebug';
import {TextWrapSvg} from './TextWrap';

type Props = {
contextId: ContextId | undefined;
open: boolean;
onClose: () => void;
};

export function DebugClusterDrawer({contextId, open, onClose}: Props) {
const [wordWrap, setWordWrap] = useState(false);
const {width} = useMainPaneDimensions();
const {fetch, status, data} = useClusterDebug(contextId);

useEffect(() => {
if (!open) return;
fetch();
}, [open, fetch]);

const toggleWordWrap = useCallback(() => {
setWordWrap(!wordWrap);
}, [wordWrap, setWordWrap]);

const logs = useMemo(() => {
return [...(data?.logs ?? [])].map(l => ({...l, id: `${l.timestamp}-${l.content}`}));
}, [data?.logs]);

return (
<Drawer
title="Cluster connection debug logs"
placement="right"
onClose={onClose}
open={open}
width={width * 0.85}
bodyStyle={{overflowX: 'auto'}}
contentWrapperStyle={{overflowX: 'auto'}}
getContainer={false}
extra={
<Tooltip title="Toggle word wrap" placement="bottomLeft" showArrow={false}>
<HeaderButton onClick={toggleWordWrap} type="link">
<ButtonBox $wrap={wordWrap}>
<TextWrapSvg />
</ButtonBox>
</HeaderButton>
</Tooltip>
}
>
{status === 'idle' || status === 'loading' ? (
<p>loading..</p>
) : status === 'error' ? (
<p>Something went wrong fetching the debug logs.</p>
) : (
<div
style={{
height: '100%',
overflowY: 'auto',
display: 'flex',
flexDirection: 'column-reverse',
marginTop: 'auto',
justifyContent: 'space-between',
}}
>
<div />

<div style={{paddingBottom: 8}}>
{logs.map(l => (
<LogEntry key={l.timestamp}>
<LogMeta>
[{DateTime.fromMillis(l.timestamp).toFormat('HH:MM:ss')} - {l.type}]
</LogMeta>
<LogContent $wrap={wordWrap}>{l.content}</LogContent>
</LogEntry>
))}
</div>
</div>
)}
</Drawer>
);
}

const LogEntry = styled.div`
display: flex;
`;

const LogMeta = styled.div`
display: flex;
color: ${Colors.grey8};
flex: 0 0 155px;
`;

const LogContent = styled.div<{$wrap: boolean}>`
white-space: ${({$wrap}) => ($wrap ? 'nowrap' : 'auto')};
padding-right: 8px;
`;

const HeaderButton = styled(Button)`
padding: 0;
width: 24px;
height: 24px;
`;

const ButtonBox = styled.div<{$wrap: boolean}>`
color: ${({$wrap}) => ($wrap ? Colors.blue6 : Colors.grey7)};
border-radius: 50%;
width: 24px;
height: 24px;
display: flex;
align-items: center;
justify-content: center;
background: ${Colors.grey3b};
:hover {
background: ${Colors.grey3b};
color: ${Colors.lightSeaGreen};
}
:focus,
:active {
background: ${Colors.grey3b};
color: ${Colors.lightSeaGreen};
}
`;
3 changes: 3 additions & 0 deletions src/components/organisms/Dashboard/Disconnected/TextWrap.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/components/organisms/Dashboard/Disconnected/TextWrap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export function TextWrapSvg() {
return (
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16">
<path
fill="currentColor"
d="M2 3.5a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5Zm0 4a.5.5 0 0 1 .5-.5h9a2.5 2.5 0 0 1 0 5h-1.293l.647.646a.5.5 0 0 1-.708.708l-1.5-1.5a.5.5 0 0 1 0-.708l1.5-1.5a.5.5 0 0 1 .708.708l-.647.646H11.5a1.5 1.5 0 0 0 0-3h-9a.5.5 0 0 1-.5-.5Zm0 4a.5.5 0 0 1 .5-.5H7a.5.5 0 0 1 0 1H2.5a.5.5 0 0 1-.5-.5Z"
/>
</svg>
);
}
13 changes: 7 additions & 6 deletions src/components/organisms/Dashboard/EmptyDashboard.styled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import {Colors} from '@shared/styles/colors';

export const Container = styled.div`
display: flex;
position: relative;
justify-content: center;
gap: 10px;
align-items: center;
justify-content: flex-end;
padding-right: 145px;
padding-top: 20px;
height: 100%;
width: 100%;
background-color: ${Colors.grey3000};
`;

export const Image = styled.img<{$right?: number}>`
width: 180px;
min-width: 180px;
width: 66px;
min-width: 66px;
`;

export const Text = styled.div`
Expand Down
Loading

0 comments on commit dc52b01

Please sign in to comment.