Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions frontend/src/pages/Runs/Details/Logs/components/LogRow/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import React, { useEffect, useRef, useState } from 'react';
import cn from 'classnames';

import { Icon } from 'components';

import styles from '../../styles.module.scss';

export const LogRow: React.FC<{
logItem: ILogItem;
isShowTimestamp?: boolean;
}> = ({ logItem, isShowTimestamp }) => {
const [collapsed, setCollapsed] = useState(true);
const [showChevron, setShowChevron] = useState(true);
const messageInnerRef = useRef(null);

const toggleCollapsed = () => setCollapsed((val) => !val);

useEffect(() => {
const observeTarget = messageInnerRef.current;
if (!observeTarget) return;

const resizeObserver = new ResizeObserver((entries) => {
const entry = entries[0];
if (entry) {
const { height } = entry.contentRect;

setShowChevron(height > 32);
}
});

resizeObserver.observe(observeTarget);

return () => {
resizeObserver.unobserve(observeTarget);
};
}, []);

return (
<tr className={styles.logItem}>
{isShowTimestamp && (
<td className={styles.timestamp}>
<span className={cn(styles.toggleCollapse, { [styles.hidden]: !showChevron })} onClick={toggleCollapsed}>
<Icon name={collapsed ? 'caret-right-filled' : 'caret-down-filled'} />
</span>{' '}
{new Date(logItem.timestamp).toISOString()}
</td>
)}
<td className={styles.messageCol}>
<div className={cn(styles.message, { [styles.collapsed]: collapsed && isShowTimestamp })}>
<div ref={messageInnerRef} className={styles.messageInner}>
{logItem.message}
</div>
</div>
</td>
</tr>
);
};
34 changes: 22 additions & 12 deletions frontend/src/pages/Runs/Details/Logs/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Box, Button, Code, Container, Header, ListEmptyMessage, Loader, TextCon
import { useLocalStorageState } from 'hooks/useLocalStorageState';
import { useLazyGetProjectLogsQuery } from 'services/project';

import { LogRow } from './components/LogRow';
import { decodeLogs } from './helpers';

import { IProps } from './types';
Expand All @@ -26,7 +27,7 @@ export const Logs: React.FC<IProps> = ({ className, projectName, runName, jobSub
const [isLoading, setIsLoading] = useState(false);
const [getProjectLogs] = useLazyGetProjectLogsQuery();
const [isEnabledDecoding, setIsEnabledDecoding] = useLocalStorageState('enable-encode-logs', false);
// const [isShowTimestamp, setIsShowTimestamp] = useLocalStorageState('enable-showing-timestamp-logs', false);
const [isShowTimestamp, setIsShowTimestamp] = useLocalStorageState('enable-showing-timestamp-logs', false);

const logsForView = useMemo(() => {
if (isEnabledDecoding) {
Expand Down Expand Up @@ -103,6 +104,10 @@ export const Logs: React.FC<IProps> = ({ className, projectName, runName, jobSub
setIsEnabledDecoding(!isEnabledDecoding);
};

const toggleShowingTimestamp = () => {
setIsShowTimestamp(!isShowTimestamp);
};

useEffect(() => {
getLogItems();
}, []);
Expand Down Expand Up @@ -172,11 +177,15 @@ export const Logs: React.FC<IProps> = ({ className, projectName, runName, jobSub
/>
</Box>

{/*<Box>*/}
{/* <Toggle onChange={({ detail }) => setIsShowTimestamp(detail.checked)} checked={isShowTimestamp}>*/}
{/* Show timestamp*/}
{/* </Toggle>*/}
{/*</Box>*/}
<Box>
<Button
ariaLabel="Show timestamp"
formAction="none"
iconName="status-pending"
variant={isShowTimestamp ? 'primary' : 'icon'}
onClick={toggleShowingTimestamp}
/>
</Box>
</div>
</div>
}
Expand All @@ -193,12 +202,13 @@ export const Logs: React.FC<IProps> = ({ className, projectName, runName, jobSub

{Boolean(logsForView.length) && (
<Code className={styles.terminal} ref={codeRef}>
{logsForView.map((log, i) => (
<p key={i}>
{/*{isShowTimestamp && <span className={styles.timestamp}>{log.timestamp}</span>}*/}
{log.message}
</p>
))}
<table>
<tbody>
{logsForView.map((log, i) => (
<LogRow logItem={log} key={i} isShowTimestamp={isShowTimestamp} />
))}
</tbody>
</table>
</Code>
)}
</TextContent>
Expand Down
36 changes: 32 additions & 4 deletions frontend/src/pages/Runs/Details/Logs/styles.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
.switchers {
margin-left: auto;
display: flex;
gap: 24px;
gap: 10px;

button {
width: 32px !important;
}
}
}

Expand Down Expand Up @@ -81,13 +85,37 @@
color: awsui.$color-text-body-default !important;
}

p {
padding: 0 !important;
.logItem {
font-size: awsui.$font-size-body-s !important;
line-height: awsui.$line-height-body-s !important;

.toggleCollapse {
position: relative;
top: -3px;
vertical-align: middle;
cursor: pointer;

&.hidden {
opacity: 0;
pointer-events: none;
}
}

.timestamp {
padding-right: 8px;
vertical-align: top;
padding-right: 16px;
white-space: nowrap;
}

.messageCol {
vertical-align: top;
}

.message {
overflow-y: hidden;
&.collapsed {
max-height: calc(awsui.$line-height-body-s * 2);
}
}
}
}
Expand Down
Loading