Browse Source

addressing type warnings; account for no-messages returned

pull/1886/head
gingervitis 5 years ago
parent
commit
12201d0088
  1. 6
      web/package-lock.json
  2. 1
      web/package.json
  3. 12
      web/pages/chat.tsx
  4. 3
      web/utils/format.ts

6
web/package-lock.json generated

@ -1575,6 +1575,12 @@ @@ -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",

1
web/package.json

@ -24,6 +24,7 @@ @@ -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",

12
web/pages/chat.tsx

@ -2,12 +2,12 @@ import React, { useState, useEffect } from "react"; @@ -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() { @@ -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() { @@ -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);
},
};

3
web/utils/format.ts

@ -15,9 +15,10 @@ export function formatIPAddress(ipAddress: string): string { @@ -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;

Loading…
Cancel
Save