Fixed when the empty message should appear

This commit is contained in:
José Oliveira 2021-02-04 13:44:29 +00:00 committed by Josh Harvey
parent d2fd305329
commit 037f383540
2 changed files with 30 additions and 35 deletions

View file

@ -16,7 +16,7 @@ import {
TableBody, TableBody,
TableCell TableCell
} from 'src/components/table' } from 'src/components/table'
import { Info3 } from 'src/components/typography' import { Info3, H4 } from 'src/components/typography'
import styles from './Logs.styles' import styles from './Logs.styles'
@ -74,7 +74,7 @@ const Logs = () => {
const { data: machineResponse } = useQuery(GET_MACHINES) const { data: machineResponse } = useQuery(GET_MACHINES)
const { data: logsResponse } = useQuery(GET_MACHINE_LOGS, { const { data: logsResponse, loading } = useQuery(GET_MACHINE_LOGS, {
variables: { deviceId, limit: NUM_LOG_RESULTS }, variables: { deviceId, limit: NUM_LOG_RESULTS },
skip: !selected, skip: !selected,
onCompleted: () => setSaveMessage('') onCompleted: () => setSaveMessage('')
@ -123,22 +123,19 @@ const Logs = () => {
<TableHeader className={classes.fillColumn} /> <TableHeader className={classes.fillColumn} />
</TableRow> </TableRow>
</TableHead> </TableHead>
{logsResponse && <TableBody>
(!logsResponse.machineLogs.length ? ( {logsResponse &&
<p>{'No activity so far'}</p> logsResponse.machineLogs.map((log, idx) => (
) : ( <TableRow key={idx} size="sm">
<TableBody> <TableCell>{formatDate(log.timestamp)}</TableCell>
{logsResponse && <TableCell>{log.logLevel}</TableCell>
logsResponse.machineLogs.map((log, idx) => ( <TableCell>{log.message}</TableCell>
<TableRow key={idx} size="sm"> </TableRow>
<TableCell>{formatDate(log.timestamp)}</TableCell> ))}
<TableCell>{log.logLevel}</TableCell> </TableBody>
<TableCell>{log.message}</TableCell>
</TableRow>
))}
</TableBody>
))}
</Table> </Table>
{loading && <H4>{'Loading...'}</H4>}
{!loading && !logsResponse && <H4>{'No activity so far'}</H4>}
</div> </div>
</div> </div>
</> </>

View file

@ -17,7 +17,7 @@ import {
TableBody, TableBody,
TableCell TableCell
} from 'src/components/table' } from 'src/components/table'
import { Info3 } from 'src/components/typography' import { Info3, H4 } from 'src/components/typography'
import typographyStyles from 'src/components/typography/styles' import typographyStyles from 'src/components/typography/styles'
import { offColor } from 'src/styling/variables' import { offColor } from 'src/styling/variables'
import { startCase } from 'src/utils/string' import { startCase } from 'src/utils/string'
@ -91,7 +91,7 @@ const Logs = () => {
const [saveMessage, setSaveMessage] = useState(null) const [saveMessage, setSaveMessage] = useState(null)
const [logLevel, setLogLevel] = useState(SHOW_ALL) const [logLevel, setLogLevel] = useState(SHOW_ALL)
const { data } = useQuery(GET_DATA, { const { data, loading } = useQuery(GET_DATA, {
onCompleted: () => setSaveMessage(''), onCompleted: () => setSaveMessage(''),
variables: { variables: {
limit: NUM_LOG_RESULTS limit: NUM_LOG_RESULTS
@ -174,24 +174,22 @@ const Logs = () => {
</TableHead> </TableHead>
<TableBody> <TableBody>
{data && {data &&
(!data.serverLogs.length ? ( data.serverLogs
<p>{'No activity so far'} </p> .filter(
) : ( log =>
data.serverLogs logLevel === SHOW_ALL || log.logLevel === logLevel.code
.filter( )
log => .map((log, idx) => (
logLevel === SHOW_ALL || log.logLevel === logLevel.code <TableRow key={idx} size="sm">
) <TableCell>{formatDate(log.timestamp)}</TableCell>
.map((log, idx) => ( <TableCell>{log.logLevel}</TableCell>
<TableRow key={idx} size="sm"> <TableCell>{log.message}</TableCell>
<TableCell>{formatDate(log.timestamp)}</TableCell> </TableRow>
<TableCell>{log.logLevel}</TableCell> ))}
<TableCell>{log.message}</TableCell>
</TableRow>
))
))}
</TableBody> </TableBody>
</Table> </Table>
{loading && <H4>{'Loading...'}</H4>}
{!loading && !data && <H4>{'No activity so far'}</H4>}
</div> </div>
</div> </div>
</> </>