Merge pull request #1858 from RafaelTaranto/fix/machine-file-uploads
LAM-1300 fix: diagnostics and upload size
This commit is contained in:
commit
c379596b6b
2 changed files with 27 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import { useLazyQuery, useQuery, gql } from '@apollo/client'
|
import { useLazyQuery, useQuery, gql } from '@apollo/client'
|
||||||
import { subMinutes } from 'date-fns'
|
import { subMinutes } from 'date-fns'
|
||||||
import FileSaver from 'file-saver'
|
import FileSaver from 'file-saver'
|
||||||
import React, { useState, useEffect } from 'react'
|
import React, { useState, useEffect, useRef } from 'react'
|
||||||
import Modal from '../Modal'
|
import Modal from '../Modal'
|
||||||
import { H3, P } from '../typography'
|
import { H3, P } from '../typography'
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ const createCsv = async ({ machineLogsCsv }) => {
|
||||||
const DiagnosticsModal = ({ onClose, deviceId, sendAction }) => {
|
const DiagnosticsModal = ({ onClose, deviceId, sendAction }) => {
|
||||||
const [state, setState] = useState(STATES.INITIAL)
|
const [state, setState] = useState(STATES.INITIAL)
|
||||||
const [timestamp, setTimestamp] = useState(null)
|
const [timestamp, setTimestamp] = useState(null)
|
||||||
let timeout = null
|
const timeoutRef = useRef(null)
|
||||||
|
|
||||||
const [fetchSummary, { loading }] = useLazyQuery(MACHINE_LOGS, {
|
const [fetchSummary, { loading }] = useLazyQuery(MACHINE_LOGS, {
|
||||||
onCompleted: data => createCsv(data),
|
onCompleted: data => createCsv(data),
|
||||||
|
|
@ -76,24 +76,41 @@ const DiagnosticsModal = ({ onClose, deviceId, sendAction }) => {
|
||||||
data.machine.diagnostics.timestamp &&
|
data.machine.diagnostics.timestamp &&
|
||||||
data.machine.diagnostics.timestamp !== timestamp
|
data.machine.diagnostics.timestamp !== timestamp
|
||||||
) {
|
) {
|
||||||
clearTimeout(timeout)
|
if (timeoutRef.current) {
|
||||||
|
clearTimeout(timeoutRef.current)
|
||||||
|
timeoutRef.current = null
|
||||||
|
}
|
||||||
setTimestamp(data.machine.diagnostics.timestamp)
|
setTimestamp(data.machine.diagnostics.timestamp)
|
||||||
setState(STATES.FILLED)
|
setState(STATES.FILLED)
|
||||||
stopPolling()
|
stopPolling()
|
||||||
}
|
}
|
||||||
}, [data, stopPolling, timeout, timestamp])
|
}, [data, stopPolling, timestamp])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
return () => {
|
||||||
|
if (timeoutRef.current) {
|
||||||
|
clearTimeout(timeoutRef.current)
|
||||||
|
timeoutRef.current = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
const path = `/operator-data/diagnostics/${deviceId}/`
|
const path = `/operator-data/diagnostics/${deviceId}/`
|
||||||
|
|
||||||
function runDiagnostics() {
|
const runDiagnostics = () => {
|
||||||
|
setState(STATES.RUNNING)
|
||||||
startPolling(2000)
|
startPolling(2000)
|
||||||
|
|
||||||
timeout = setTimeout(() => {
|
if (timeoutRef.current) {
|
||||||
|
clearTimeout(timeoutRef.current)
|
||||||
|
}
|
||||||
|
|
||||||
|
timeoutRef.current = setTimeout(() => {
|
||||||
setState(STATES.FAILURE)
|
setState(STATES.FAILURE)
|
||||||
stopPolling()
|
stopPolling()
|
||||||
|
timeoutRef.current = null
|
||||||
}, 60 * 1000)
|
}, 60 * 1000)
|
||||||
|
|
||||||
setState(STATES.RUNNING)
|
|
||||||
sendAction()
|
sendAction()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -140,7 +157,7 @@ const DiagnosticsModal = ({ onClose, deviceId, sendAction }) => {
|
||||||
<H3>Scan</H3>
|
<H3>Scan</H3>
|
||||||
<img
|
<img
|
||||||
className="w-88"
|
className="w-88"
|
||||||
src={path + 'scan.jpg'}
|
src={`${path}scan.jpg?${Date.now()}`}
|
||||||
alt="Failure getting photo"
|
alt="Failure getting photo"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -148,7 +165,7 @@ const DiagnosticsModal = ({ onClose, deviceId, sendAction }) => {
|
||||||
<H3>Front</H3>
|
<H3>Front</H3>
|
||||||
<img
|
<img
|
||||||
className="w-88"
|
className="w-88"
|
||||||
src={path + 'front.jpg'}
|
src={`${path}front.jpg?${Date.now()}`}
|
||||||
alt="Failure getting photo"
|
alt="Failure getting photo"
|
||||||
/>
|
/>
|
||||||
<P></P>
|
<P></P>
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ const loadRoutes = async () => {
|
||||||
app.use(compression({ threshold: 500 }))
|
app.use(compression({ threshold: 500 }))
|
||||||
app.use(helmet())
|
app.use(helmet())
|
||||||
app.use(nocache())
|
app.use(nocache())
|
||||||
app.use(express.json({ limit: '2mb' }))
|
app.use(express.json({ limit: '25mb' }))
|
||||||
|
|
||||||
morgan.token('bytesRead', (_req, res) => res.bytesRead)
|
morgan.token('bytesRead', (_req, res) => res.bytesRead)
|
||||||
morgan.token('bytesWritten', (_req, res) => res.bytesWritten)
|
morgan.token('bytesWritten', (_req, res) => res.bytesWritten)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue