Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FE: Design update for log context tab #4601

Merged
merged 19 commits into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 5 additions & 1 deletion frontend/src/components/Logs/RawLogView/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ function RawLogView({
>
<LogStateIndicator
type={logType}
isActive={activeLog?.id === data.id || activeContextLog?.id === data.id}
isActive={
activeLog?.id === data.id ||
activeContextLog?.id === data.id ||
isActiveLog
}
/>

<RawLogContent
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
.context-log-renderer {
.virtuoso-list {
overflow-y: hidden !important;
&::-webkit-scrollbar {
width: 0.3rem;
height: 0.3rem;
}

&::-webkit-scrollbar-track {
background: transparent;
}

&::-webkit-scrollbar-thumb {
background: var(--bg-slate-300);
}

&::-webkit-scrollbar-thumb:hover {
background: var(--bg-slate-200);
}

/* Adjust width to fit content for accessing the third descendant, which renders logs */
> div > div > div {
width: fit-content;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import './ContextLogRenderer.styles.scss';

import RawLogView from 'components/Logs/RawLogView';
import Spinner from 'components/Spinner';
import ShowButton from 'container/LogsContextList/ShowButton';
import { ORDERBY_FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config';
import { useCallback, useEffect, useState } from 'react';
import { Virtuoso } from 'react-virtuoso';
import { ILog } from 'types/api/logs/log';
import { Query, TagFilter } from 'types/api/queryBuilder/queryBuilderData';

import { useContextLogData } from './useContextLogData';

function ContextLogRenderer({
isEdit,
query,
log,
filters,
}: ContextLogRendererProps): JSX.Element {
const [firstLog, setFirstLog] = useState<ILog>(log);
const [lastLog, setLastLog] = useState<ILog>(log);
const [prevLogPage, setPrevLogPage] = useState<number>(1);
const [afterLogPage, setAfterLogPage] = useState<number>(1);
const [logs, setLogs] = useState<ILog[]>([log]);

const {
logs: previousLogs,
isFetching: isPreviousLogsFetching,
handleShowNextLines: handlePreviousLogsShowNextLine,
} = useContextLogData({
log: firstLog,
filters,
isEdit,
query,
order: ORDERBY_FILTERS.ASC,
page: prevLogPage,
setPage: setPrevLogPage,
});

const {
logs: afterLogs,
isFetching: isAfterLogsFetching,
handleShowNextLines: handleAfterLogsShowNextLine,
} = useContextLogData({
log: lastLog,
filters,
isEdit,
query,
order: ORDERBY_FILTERS.DESC,
page: afterLogPage,
setPage: setAfterLogPage,
});

useEffect(() => {
setLogs((prev) => [...previousLogs, ...prev]);
setFirstLog(logs[0]);
Rajat-Dabade marked this conversation as resolved.
Show resolved Hide resolved
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [previousLogs]);

useEffect(() => {
setLogs((prev) => [...prev, ...afterLogs]);
setLastLog(logs[logs.length - 1]);
// eslint-disable-next-line react-hooks/exhaustive-deps
Rajat-Dabade marked this conversation as resolved.
Show resolved Hide resolved
}, [afterLogs]);

useEffect(() => {
setLogs([log]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [filters]);
Rajat-Dabade marked this conversation as resolved.
Show resolved Hide resolved

const getItemContent = useCallback(
(_: number, logTorender: ILog): JSX.Element => (
<RawLogView
isActiveLog={logTorender.id === log.id}
isReadOnly
isTextOverflowEllipsisDisabled
key={logTorender.id}
data={logTorender}
linesPerRow={1}
/>
),
[log.id],
);

return (
<div className="context-log-renderer">
<ShowButton
isLoading={isPreviousLogsFetching}
isDisabled={false}
order={ORDERBY_FILTERS.ASC}
onClick={handlePreviousLogsShowNextLine}
/>
{isPreviousLogsFetching && <Spinner size="large" height="20rem" />}
Rajat-Dabade marked this conversation as resolved.
Show resolved Hide resolved
<Virtuoso
className="virtuoso-list"
initialTopMostItemIndex={0}
data={logs}
itemContent={getItemContent}
style={{ height: `calc(${logs.length} * 32px)` }}
Rajat-Dabade marked this conversation as resolved.
Show resolved Hide resolved
// followOutput={order === ORDERBY_FILTERS.DESC}
/>
{isAfterLogsFetching && <Spinner size="large" height="20rem" />}
<ShowButton
isLoading={isAfterLogsFetching}
isDisabled={false}
order={ORDERBY_FILTERS.DESC}
onClick={handleAfterLogsShowNextLine}
/>
</div>
);
}

interface ContextLogRendererProps {
isEdit: boolean;
query: Query;
log: ILog;
filters: TagFilter | null;
}

export default ContextLogRenderer;
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
.log-context-container {
border: 1px solid var(--bg-slate-400);
}
height: 80vh;
position: relative;
overflow: scroll;
overflow-x: hidden;

&::-webkit-scrollbar {
width: 0.3rem;
}

&::-webkit-scrollbar-track {
background: transparent;
}

&::-webkit-scrollbar-thumb {
background: var(--bg-slate-300);
}

&::-webkit-scrollbar-thumb:hover {
background: var(--bg-slate-200);
}
}

.isEditable {
height: 73vh; // when edit is true, reducing the size of log-context-container for avoiding extra scroll bars
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import './ContextView.styles.scss';

import RawLogView from 'components/Logs/RawLogView';
import LogsContextList from 'container/LogsContextList';
import { ORDERBY_FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config';
import cx from 'classnames';
import { ILog } from 'types/api/logs/log';
import { Query, TagFilter } from 'types/api/queryBuilder/queryBuilderData';

import ContextLogRenderer from './ContextLogRenderer';

interface LogContextProps {
log: ILog;
contextQuery: Query | undefined;
Expand All @@ -23,29 +23,12 @@ function ContextView({
if (!contextQuery) return <></>;

return (
<div className="log-context-container">
<LogsContextList
className="logs-context-list-asc"
order={ORDERBY_FILTERS.ASC}
<div className={cx('log-context-container', { isEditable: isEdit })}>
<ContextLogRenderer
filters={filters}
isEdit={isEdit}
log={log}
query={contextQuery}
/>
<RawLogView
isActiveLog
isReadOnly
isTextOverflowEllipsisDisabled={false}
data={log}
linesPerRow={1}
/>
<LogsContextList
className="logs-context-list-desc"
order={ORDERBY_FILTERS.DESC}
filters={filters}
isEdit={isEdit}
log={log}
query={contextQuery}
/>
</div>
);
Expand Down
Loading
Loading