Skip to content

Commit 5013307

Browse files
authored
feat(frontend): avoid waiting time to get data (#30)
Signed-off-by: Roberto Bianchi <roberto.bianchi@spendesk.com>
1 parent c5751f3 commit 5013307

File tree

3 files changed

+13
-27
lines changed

3 files changed

+13
-27
lines changed

web/frontend/src/components/application-logs/AppLogs.jsx

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
3434
const logContentRef = useRef()
3535
const [lastScrollTop, setLastScrollTop] = useState(0)
3636
const [displayGoToBottom, setDisplayGoToBottom] = useState(false)
37-
const [showPreviousLogs] = useState(false)
3837
const [statusPausedLogs, setStatusPausedLogs] = useState('')
3938
const [filteredLogsLengthAtPause, setFilteredLogsLengthAtPause] = useState(0)
4039
const bottomRef = useRef()
@@ -110,10 +109,13 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
110109
filteredServices
111110
])
112111

113-
useInterval(async () => {
112+
const getData = async () => {
114113
const logs = await getLogs(runtimePid)
115114
setApplicationLogs(logs)
116-
}, REFRESH_INTERVAL_LOGS)
115+
}
116+
117+
useInterval(() => { getData() }, REFRESH_INTERVAL_LOGS)
118+
useEffect(() => { getData() }, [runtimePid])
117119

118120
useEffect(() => {
119121
if (scrollDirection !== DIRECTION_TAIL && filteredLogsLengthAtPause > 0 && filteredLogsLengthAtPause < filteredLogs.length) {
@@ -127,13 +129,6 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
127129
setFilteredLogsLengthAtPause(0)
128130
}
129131

130-
async function loadPreviousLogs () {
131-
}
132-
133-
/* function onlyUnique (value, index, array) {
134-
return array.indexOf(value) === index
135-
} */
136-
137132
function saveLogs () {
138133
let fileData = ''
139134
applicationLogs.forEach(log => {
@@ -168,7 +163,6 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
168163
}
169164

170165
function handleScroll (event) {
171-
// setStatusPausedLogs(STATUS_PAUSED_LOGS)
172166
const st = event.currentTarget.scrollTop // Credits: "https://github.com/qeremy/so/blob/master/so.dom.js#L426"
173167
if (st > lastScrollTop) {
174168
// downscroll code
@@ -219,12 +213,6 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
219213
</div>
220214
<HorizontalSeparator marginBottom={MARGIN_0} color={WHITE} opacity={OPACITY_15} />
221215
<div className={`${styles.logsContainer} ${styles.lateralPadding}`} ref={logContentRef} onScroll={handleScroll}>
222-
{showPreviousLogs && (
223-
<div className={styles.previousLogContainer}>
224-
<p className={`${typographyStyles.desktopBodySmall} ${typographyStyles.textWhite} ${typographyStyles.textCenter} ${commonStyles.fullWidth} `}><span className={`${commonStyles.cursorPointer} ${typographyStyles.textTertiaryBlue}`} onClick={() => loadPreviousLogs()}>Click Here</span> to load previous logs</p>
225-
</div>
226-
)}
227-
228216
{filteredLogs?.length > 0 && (
229217
<>
230218
<hr className={styles.logDividerTop} />

web/frontend/src/components/application/NodeJSMetrics.jsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState } from 'react'
1+
import React, { useState, useEffect } from 'react'
22
import { useInterval } from '~/hooks/useInterval'
33
import PropTypes from 'prop-types'
44
import { WHITE, MEDIUM, BLACK_RUSSIAN, TRANSPARENT, RICH_BLACK } from '@platformatic/ui-components/src/components/constants'
@@ -24,7 +24,7 @@ function NodeJSMetrics ({
2424
const [latestRefreshDate, setLatestRefreshDate] = useState(new Date())
2525
const { runtimePid } = useAdminStore()
2626

27-
useInterval(async () => {
27+
const getData = async () => {
2828
try {
2929
const data = await getApiMetricsPod(runtimePid)
3030
setAllData(data)
@@ -34,7 +34,10 @@ function NodeJSMetrics ({
3434
} finally {
3535
setInitialLoading(false)
3636
}
37-
}, [REFRESH_INTERVAL_METRICS])
37+
}
38+
39+
useInterval(() => { getData() }, [REFRESH_INTERVAL_METRICS])
40+
useEffect(() => { getData() }, [runtimePid])
3841

3942
return (
4043
<BorderedBox classes={`${styles.borderexBoxContainer} ${gridClassName}`} backgroundColor={BLACK_RUSSIAN} color={TRANSPARENT}>

web/frontend/src/components/metrics/ServicesMetrics.jsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,8 @@ const ServicesMetrics = React.forwardRef(({
4343
}
4444
}
4545

46-
useInterval(() => {
47-
getData()
48-
}, REFRESH_INTERVAL_METRICS)
49-
50-
useEffect(() => {
51-
getData()
52-
}, [serviceId])
46+
useInterval(() => { getData() }, REFRESH_INTERVAL_METRICS)
47+
useEffect(() => { getData() }, [runtimePid, serviceId])
5348

5449
return (
5550
<div className={styles.container} ref={ref}>

0 commit comments

Comments
 (0)