Skip to content

Commit 80276ca

Browse files
authored
feat(frontend): refactor (#32)
1 parent 5013307 commit 80276ca

30 files changed

+248
-694
lines changed

package-lock.json

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

web/frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"borp": "^0.17.0",
2020
"d3": "~7.9.0",
2121
"dayjs": "^1.11.13",
22-
"prop-types": "^15.8.1",
2322
"react": "^19.0.0",
2423
"react-dom": "^19.0.0",
2524
"react-router-dom": "^7.0.0",

web/frontend/src/App.jsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, useEffect, useRef } from 'react'
1+
import React, { useState, useEffect } from 'react'
22
import { HashRouter, Routes, Route } from 'react-router-dom'
33
import './App.css'
44
import NotFound from '~/pages/NotFound'
@@ -28,9 +28,6 @@ export default function App () {
2828
const { setCurrentWindowWidth } = globalState
2929
const [innerLoading, setInnerLoading] = useState(false)
3030
const [showErrorComponent, setShowErrorComponent] = useState(false)
31-
const applicationsRef = useRef(null)
32-
const podServicesRef = useRef(null)
33-
const podLogsRef = useRef(null)
3431

3532
const {
3633
ErrorBoundary,
@@ -111,10 +108,7 @@ export default function App () {
111108
element={
112109
<PrivateRouteContainer>
113110
<ApplicationContainer>
114-
<AppDetails
115-
ref={applicationsRef}
116-
key={HOME_PATH}
117-
/>
111+
<AppDetails />
118112
</ApplicationContainer>
119113
</PrivateRouteContainer>
120114
}
@@ -124,10 +118,7 @@ export default function App () {
124118
element={
125119
<PrivateRouteContainer>
126120
<ApplicationContainer>
127-
<ServicesCharts
128-
ref={podServicesRef}
129-
key={POD_SERVICES_PATH}
130-
/>
121+
<ServicesCharts />
131122
</ApplicationContainer>
132123
</PrivateRouteContainer>
133124
}
@@ -137,10 +128,7 @@ export default function App () {
137128
element={
138129
<PrivateRouteContainer>
139130
<ApplicationContainer>
140-
<ServicesLogs
141-
ref={podLogsRef}
142-
key={POD_LOGS_PATH}
143-
/>
131+
<ServicesLogs />
144132
</ApplicationContainer>
145133
</PrivateRouteContainer>
146134
}

web/frontend/src/api.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export const getLogs = async (id) => {
4343
export const getApiMetricsPod = async (id) => {
4444
try {
4545
const response = await fetch(`${host}/runtimes/${id}/metrics`)
46-
4746
const data = await response.json()
4847
return data
4948
} catch (error) {
@@ -55,7 +54,6 @@ export const getApiMetricsPod = async (id) => {
5554
export const getApiMetricsPodService = async (podId, serviceId) => {
5655
try {
5756
const response = await fetch(`${host}/runtimes/${podId}/metrics/${serviceId}`)
58-
5957
const data = await response.json()
6058
return data
6159
} catch (error) {

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import useOnScreen from '~/hooks/useOnScreen'
2323
import useAdminStore from '~/useAdminStore'
2424
import { getLogs } from '../../api'
2525

26-
const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
26+
const AppLogs = ({ filteredServices }) => {
2727
const { runtimePid } = useAdminStore()
2828
const [displayLog, setDisplayLog] = useState(PRETTY)
2929
const [filterLogsByLevel, setFilterLogsByLevel] = useState('')
@@ -110,8 +110,14 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
110110
])
111111

112112
const getData = async () => {
113-
const logs = await getLogs(runtimePid)
114-
setApplicationLogs(logs)
113+
try {
114+
if (runtimePid) {
115+
const logs = await getLogs(runtimePid)
116+
setApplicationLogs(logs)
117+
}
118+
} catch (error) {
119+
console.error('Failed to fetch logs:', error)
120+
}
115121
}
116122

117123
useInterval(() => { getData() }, REFRESH_INTERVAL_LOGS)
@@ -181,7 +187,7 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
181187
}
182188

183189
return (
184-
<div className={styles.container} ref={ref}>
190+
<div className={styles.container}>
185191
<div className={styles.content}>
186192
<div className={`${commonStyles.largeFlexBlock} ${commonStyles.fullWidth} ${styles.flexGrow}`}>
187193
<BorderedBox classes={styles.borderexBoxPodContainer} backgroundColor={RICH_BLACK} color={TRANSPARENT}>
@@ -248,6 +254,6 @@ const AppLogs = React.forwardRef(({ filteredServices }, ref) => {
248254
</div>
249255
</div>
250256
)
251-
})
257+
}
252258

253259
export default AppLogs

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

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect, useState } from 'react'
2-
import PropTypes from 'prop-types'
32
import typographyStyles from '~/styles/Typography.module.css'
43
import styles from './Log.module.css'
54
import { CopyAndPaste, PlatformaticIcon } from '@platformatic/ui-components'
@@ -130,20 +129,4 @@ function Log ({ log, onClickArrow }) {
130129
)
131130
}
132131

133-
Log.propTypes = {
134-
/**
135-
* log
136-
*/
137-
log: PropTypes.string,
138-
/**
139-
* onClickArrow
140-
*/
141-
onClickArrow: PropTypes.func
142-
}
143-
144-
Log.defaultProps = {
145-
log: '',
146-
onClickArrow: () => {}
147-
}
148-
149132
export default Log

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useEffect, useState } from 'react'
2-
import PropTypes from 'prop-types'
32
import styles from './LogFilterSelector.module.css'
43
import typographyStyles from '~/styles/Typography.module.css'
54

@@ -88,15 +87,4 @@ function LogFilterSelector ({
8887
)
8988
}
9089

91-
LogFilterSelector.propTypes = {
92-
/**
93-
* defaultLevelSelected
94-
*/
95-
defaultLevelSelected: PropTypes.number,
96-
/**
97-
* onChangeLevelSelected
98-
*/
99-
onChangeLevelSelected: PropTypes.func
100-
}
101-
10290
export default LogFilterSelector

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import NodeJSMetrics from './NodeJSMetrics'
77
import useAdminStore from '~/useAdminStore'
88
import { getApiApplication } from '../../api'
99

10-
const AppDetails = React.forwardRef(({ _ }, ref) => {
10+
const AppDetails = () => {
1111
const [showErrorComponent, setShowErrorComponent] = useState(false)
1212
const [error, setError] = useState(false)
1313
const [apiApplication, setApiApplication] = useState({})
@@ -31,21 +31,18 @@ const AppDetails = React.forwardRef(({ _ }, ref) => {
3131
}
3232

3333
return (
34-
<div className={styles.container} ref={ref}>
34+
<div className={styles.container}>
3535
<div className={styles.containerElement}>
3636
<div className={styles.content}>
3737
<div className={styles.leftSection}>
3838
<AppNameBox
39-
gridClassName={styles.appNameBox}
4039
onErrorOccurred={(error) => {
4140
setError(error)
4241
setShowErrorComponent(true)
4342
}}
4443
apiApplication={apiApplication}
4544
/>
46-
<NodeJSMetrics
47-
gridClassName={styles.nodeJsMetricsBox}
48-
/>
45+
<NodeJSMetrics />
4946
</div>
5047
<div className={styles.rightSection}>
5148
<ServicesBox />
@@ -54,6 +51,6 @@ const AppDetails = React.forwardRef(({ _ }, ref) => {
5451
</div>
5552
</div>
5653
)
57-
})
54+
}
5855

5956
export default AppDetails

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

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React, { useState, useEffect } from 'react'
2-
import PropTypes from 'prop-types'
32
import { WARNING_YELLOW, WHITE, TRANSPARENT, SMALL, BLACK_RUSSIAN, MEDIUM } from '@platformatic/ui-components/src/components/constants'
43
import styles from './AppNameBox.module.css'
54
import typographyStyles from '~/styles/Typography.module.css'
@@ -14,7 +13,6 @@ import { restartApiApplication, isWattpmVersionOutdated } from '../../api'
1413

1514
function AppNameBox ({
1615
onErrorOccurred = () => {},
17-
gridClassName = '',
1816
apiApplication
1917
}) {
2018
const [appStatus, setAppStatus] = useState(STATUS_STOPPED)
@@ -50,7 +48,7 @@ function AppNameBox ({
5048
}
5149

5250
return apiApplication && (
53-
<BorderedBox classes={`${styles.borderexBoxContainer} ${gridClassName}`} backgroundColor={BLACK_RUSSIAN} color={TRANSPARENT}>
51+
<BorderedBox classes={`${styles.borderexBoxContainer}`} backgroundColor={BLACK_RUSSIAN} color={TRANSPARENT}>
5452
<div className={`${commonStyles.smallFlexBlock} ${commonStyles.fullWidth}`}>
5553
<div className={`${commonStyles.smallFlexResponsiveRow} ${commonStyles.fullWidth}`}>
5654
<div className={`${commonStyles.tinyFlexResponsiveRow} ${commonStyles.fullWidth}`}>
@@ -145,16 +143,4 @@ function AppNameBox ({
145143
)
146144
}
147145

148-
AppNameBox.propTypes = {
149-
/**
150-
* onErrorOccurred
151-
*/
152-
onErrorOccurred: PropTypes.func,
153-
/**
154-
* gridClassName
155-
*/
156-
gridClassName: PropTypes.string
157-
158-
}
159-
160146
export default AppNameBox

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

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React, { useEffect, useState } from 'react'
2-
import PropTypes from 'prop-types'
3-
import { WHITE, BLACK_RUSSIAN, TRANSPARENT, RICH_BLACK, OPACITY_30 } from '@platformatic/ui-components/src/components/constants'
2+
import { WHITE, BLACK_RUSSIAN, TRANSPARENT, OPACITY_30 } from '@platformatic/ui-components/src/components/constants'
43
import styles from './NodeJSMetric.module.css'
54
import typographyStyles from '~/styles/Typography.module.css'
65
import commonStyles from '~/styles/CommonStyles.module.css'
@@ -9,7 +8,7 @@ import loadingSpinnerStyles from '~/styles/LoadingSpinnerStyles.module.css'
98
import NoDataAvailable from '~/components/ui/NoDataAvailable'
109
import NodeJSMetricChart from '~/components//metrics/NodeJSMetricChart'
1110
import LatencyChart from '~/components//metrics/LatencyChart'
12-
import { POSITION_ABSOLUTE, POSITION_FIXED } from '~/ui-constants'
11+
import { POSITION_ABSOLUTE } from '~/ui-constants'
1312
import colorSetMem from '~/components/metrics/memory.module.css'
1413
import colorSetCpu from '~/components/metrics/cpu.module.css'
1514
import colorSetLatency from '~/components/metrics/latency.module.css'
@@ -77,7 +76,7 @@ function NodeJSMetric ({
7776
} else {
7877
setShowNoResult(true)
7978
}
80-
}, [])
79+
}, [dataValues])
8180

8281
function renderComponent () {
8382
if (initialLoading) {
@@ -143,55 +142,4 @@ function NodeJSMetric ({
143142
)
144143
}
145144

146-
NodeJSMetric.propTypes = {
147-
/**
148-
* title
149-
*/
150-
title: PropTypes.string,
151-
/**
152-
* metricURL
153-
*/
154-
metricURL: PropTypes.string,
155-
/**
156-
* unit
157-
*/
158-
unit: PropTypes.string,
159-
/**
160-
* data
161-
*/
162-
data: PropTypes.object,
163-
/**
164-
* initialLoading
165-
*/
166-
initialLoading: PropTypes.bool,
167-
/**
168-
* options
169-
*/
170-
options: PropTypes.arrayOf(PropTypes.shape({
171-
label: PropTypes.string,
172-
key: PropTypes.string,
173-
unit: PropTypes.string
174-
})),
175-
/**
176-
* backgroundColor
177-
*/
178-
backgroundColor: PropTypes.oneOf([BLACK_RUSSIAN, RICH_BLACK]),
179-
/**
180-
* chartTooltipPositionPropTypes
181-
*/
182-
chartTooltipPosition: PropTypes.oneOf([POSITION_ABSOLUTE, POSITION_FIXED]),
183-
/**
184-
* showLegend
185-
*/
186-
showLegend: PropTypes.bool,
187-
/**
188-
* timeline
189-
*/
190-
timeline: PropTypes.bool,
191-
/**
192-
* slimCss
193-
*/
194-
slimCss: PropTypes.bool
195-
}
196-
197145
export default NodeJSMetric

0 commit comments

Comments
 (0)