addressing type warnings; account for no-messages returned

This commit is contained in:
gingervitis 2020-12-29 14:59:43 -08:00
parent 422f37c477
commit 12201d0088
4 changed files with 17 additions and 5 deletions

6
web/package-lock.json generated
View File

@ -1575,6 +1575,12 @@
"moment": "^2.10.2"
}
},
"@types/classnames": {
"version": "2.2.11",
"resolved": "https://registry.npmjs.org/@types/classnames/-/classnames-2.2.11.tgz",
"integrity": "sha512-2koNhpWm3DgWRp5tpkiJ8JGc1xTn2q0l+jUNUE7oMKXUf5NpI9AIdC4kbjGNFBdHtcxBD18LAksoudAVhFKCjw==",
"dev": true
},
"@types/color-name": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",

View File

@ -24,6 +24,7 @@
},
"devDependencies": {
"@types/chart.js": "^2.9.28",
"@types/classnames": "^2.2.11",
"@types/node": "^14.11.2",
"@types/prop-types": "^15.7.3",
"@types/react": "^16.9.49",

View File

@ -2,12 +2,12 @@ import React, { useState, useEffect } from "react";
import { Table, Typography, Tooltip, Button } from "antd";
import { CheckCircleFilled, ExclamationCircleFilled, StopOutlined } from "@ant-design/icons";
import classNames from 'classnames';
import { RowSelectionType } from "antd/es/table/interface";
import { ColumnsType } from 'antd/es/table';
import format from 'date-fns/format'
import { CHAT_HISTORY, fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../utils/apis";
import { MessageType } from '../types/chat';
import { isEmptyObject } from "../utils/format";
const { Title } = Typography;
@ -47,7 +47,11 @@ export default function Chat() {
const getInfo = async () => {
try {
const result = await fetchData(CHAT_HISTORY, { auth: true });
setMessages(result);
if (isEmptyObject(result)) {
setMessages([]);
} else {
setMessages(result);
}
} catch (error) {
console.log("==== error", error);
}
@ -62,9 +66,9 @@ export default function Chat() {
const nameFilters = createUserNameFilters(messages);
const rowSelection: RowSelectionType = {
const rowSelection = {
selectedRowKeys,
onChange: selectedKeys => {
onChange: (selectedKeys: string[]) => {
setSelectedRows(selectedKeys);
},
};

View File

@ -15,9 +15,10 @@ export function formatIPAddress(ipAddress: string): string {
// check if obj is {}
export function isEmptyObject(obj) {
return !obj || Object.keys(obj).length === 0;
return !obj || (Object.keys(obj).length === 0 && obj.constructor === Object);
}
export function parseSecondsToDurationString(seconds = 0) {
const finiteSeconds = Number.isFinite(+seconds) ? Math.abs(seconds) : 0;