Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
added scroll to bottom for logviewer
Browse files Browse the repository at this point in the history
  • Loading branch information
sinamics committed Jul 25, 2022
1 parent aae329d commit e3c8926
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 32 deletions.
36 changes: 20 additions & 16 deletions frontend/src/pages/logviewer/containers/dockerLog.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { useEffect } from 'react';
import { Label } from 'semantic-ui-react';
import { useGetDockerLogMutation } from '../../../graphql/generated/dist';
//@ts-ignore
import ScrollToBottom from 'react-scroll-to-bottom';

const DockerLog = () => {
//get server logs
const [fetchLog, { data, loading, error }] = useGetDockerLogMutation({
variables: { properties: { minutes: 240, limit: 35 } },
variables: { properties: { minutes: 240 } },
fetchPolicy: 'network-only'
});

Expand All @@ -17,21 +19,23 @@ const DockerLog = () => {
if (error) return <div>Error</div>;

return (
<div className='themeBg themeText'>
{data?.getDockerLog.file?.map((log: any, idx: number) => {
// check if first word is error or failed
const errorWords = ['failed', 'error'];
const isError = new RegExp(errorWords.join('|')).test(log?.message.toLowerCase());
return (
<div key={idx} style={{ fontSize: '16px' }}>
<Label color={`${isError ? 'red' : 'green'}`} horizontal>
{log.timestamp}
</Label>
<span style={{ background: `${isError ? '#a1131366' : ''}` }}>{`${log.message}`}</span>
</div>
);
})}
</div>
<ScrollToBottom>
<div className='themeBg themeText logContainer'>
{data?.getDockerLog.file?.map((log: any, idx: number) => {
// check if first word is error or failed
const errorWords = ['failed', 'error'];
const isError = new RegExp(errorWords.join('|')).test(log?.message.toLowerCase());
return (
<div key={idx} style={{ fontSize: '16px' }}>
<Label color={`${isError ? 'red' : 'green'}`} horizontal>
{log.timestamp}
</Label>
<span style={{ background: `${isError ? '#a1131366' : ''}` }}>{`${log.message}`}</span>
</div>
);
})}
</div>
</ScrollToBottom>
);
};

Expand Down
36 changes: 20 additions & 16 deletions frontend/src/pages/logviewer/containers/systemLog.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';
import { Label } from 'semantic-ui-react';
import { useGetServerLogQuery } from '../../../graphql/generated/dist';
//@ts-ignore
import ScrollToBottom from 'react-scroll-to-bottom';

const SystemLog = () => {
//get server logs
Expand All @@ -9,30 +11,32 @@ const SystemLog = () => {
loading,
error
} = useGetServerLogQuery({
variables: { properties: { minutes: 240, limit: 35 } },
variables: { properties: { minutes: 240 } },
fetchPolicy: 'network-only'
});

if (loading) return <div>Loading...</div>;
if (error) return <div>Error</div>;

return (
<div className='themeBg themeText'>
{getServerLog.file?.map((log: any, idx: number) => {
// check if first word is error or failed
const errorWords = ['failed', 'error'];
const isError = new RegExp(errorWords.join('|')).test(log?.message.toLowerCase());
<ScrollToBottom>
<div className='themeBg themeText logContainer'>
{getServerLog.file?.map((log: any, idx: number) => {
// check if first word is error or failed
const errorWords = ['failed', 'error'];
const isError = new RegExp(errorWords.join('|')).test(log?.message.toLowerCase());

return (
<div key={idx} style={{ fontSize: '16px' }}>
<Label color={`${isError ? 'red' : 'green'}`} horizontal>
{log.timestamp}
</Label>
<span style={{ background: `${isError ? '#a1131366' : ''}` }}>{`${log.message}`}</span>
</div>
);
})}
</div>
return (
<div key={idx} style={{ fontSize: '16px' }}>
<Label color={`${isError ? 'red' : 'green'}`} horizontal>
{log.timestamp}
</Label>
<span style={{ background: `${isError ? '#a1131366' : ''}` }}>{`${log.message}`}</span>
</div>
);
})}
</div>
</ScrollToBottom>
);
};

Expand Down
5 changes: 5 additions & 0 deletions frontend/src/scss/core/_logviewer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
:is(.logContainer) {
max-height: calc(100vh - 130px);
// overflow-y: scroll;
position: relative;
}
1 change: 1 addition & 0 deletions frontend/src/scss/core/core.scss
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
@import 'switch';
@import 'map';
@import 'chart';
@import 'logviewer';

0 comments on commit e3c8926

Please sign in to comment.