addressing type warnings; account for no-messages returned
This commit is contained in:
6
web/package-lock.json
generated
6
web/package-lock.json
generated
@@ -1575,6 +1575,12 @@
|
|||||||
"moment": "^2.10.2"
|
"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": {
|
"@types/color-name": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||||
|
|||||||
@@ -24,6 +24,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/chart.js": "^2.9.28",
|
"@types/chart.js": "^2.9.28",
|
||||||
|
"@types/classnames": "^2.2.11",
|
||||||
"@types/node": "^14.11.2",
|
"@types/node": "^14.11.2",
|
||||||
"@types/prop-types": "^15.7.3",
|
"@types/prop-types": "^15.7.3",
|
||||||
"@types/react": "^16.9.49",
|
"@types/react": "^16.9.49",
|
||||||
|
|||||||
@@ -2,12 +2,12 @@ import React, { useState, useEffect } from "react";
|
|||||||
import { Table, Typography, Tooltip, Button } from "antd";
|
import { Table, Typography, Tooltip, Button } from "antd";
|
||||||
import { CheckCircleFilled, ExclamationCircleFilled, StopOutlined } from "@ant-design/icons";
|
import { CheckCircleFilled, ExclamationCircleFilled, StopOutlined } from "@ant-design/icons";
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import { RowSelectionType } from "antd/es/table/interface";
|
|
||||||
import { ColumnsType } from 'antd/es/table';
|
import { ColumnsType } from 'antd/es/table';
|
||||||
import format from 'date-fns/format'
|
import format from 'date-fns/format'
|
||||||
|
|
||||||
import { CHAT_HISTORY, fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../utils/apis";
|
import { CHAT_HISTORY, fetchData, UPDATE_CHAT_MESSGAE_VIZ } from "../utils/apis";
|
||||||
import { MessageType } from '../types/chat';
|
import { MessageType } from '../types/chat';
|
||||||
|
import { isEmptyObject } from "../utils/format";
|
||||||
|
|
||||||
const { Title } = Typography;
|
const { Title } = Typography;
|
||||||
|
|
||||||
@@ -47,7 +47,11 @@ export default function Chat() {
|
|||||||
const getInfo = async () => {
|
const getInfo = async () => {
|
||||||
try {
|
try {
|
||||||
const result = await fetchData(CHAT_HISTORY, { auth: true });
|
const result = await fetchData(CHAT_HISTORY, { auth: true });
|
||||||
setMessages(result);
|
if (isEmptyObject(result)) {
|
||||||
|
setMessages([]);
|
||||||
|
} else {
|
||||||
|
setMessages(result);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log("==== error", error);
|
console.log("==== error", error);
|
||||||
}
|
}
|
||||||
@@ -62,9 +66,9 @@ export default function Chat() {
|
|||||||
|
|
||||||
const nameFilters = createUserNameFilters(messages);
|
const nameFilters = createUserNameFilters(messages);
|
||||||
|
|
||||||
const rowSelection: RowSelectionType = {
|
const rowSelection = {
|
||||||
selectedRowKeys,
|
selectedRowKeys,
|
||||||
onChange: selectedKeys => {
|
onChange: (selectedKeys: string[]) => {
|
||||||
setSelectedRows(selectedKeys);
|
setSelectedRows(selectedKeys);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,9 +15,10 @@ export function formatIPAddress(ipAddress: string): string {
|
|||||||
|
|
||||||
// check if obj is {}
|
// check if obj is {}
|
||||||
export function isEmptyObject(obj) {
|
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) {
|
export function parseSecondsToDurationString(seconds = 0) {
|
||||||
const finiteSeconds = Number.isFinite(+seconds) ? Math.abs(seconds) : 0;
|
const finiteSeconds = Number.isFinite(+seconds) ? Math.abs(seconds) : 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user