diff --git a/frontend/src/container/MetricsTable/index.tsx b/frontend/src/container/MetricsTable/index.tsx index e81a7badfc..bfc97ba9e2 100644 --- a/frontend/src/container/MetricsTable/index.tsx +++ b/frontend/src/container/MetricsTable/index.tsx @@ -1,9 +1,13 @@ -import Table, { ColumnsType } from 'antd/lib/table'; +import { blue } from '@ant-design/colors'; +import { SearchOutlined } from '@ant-design/icons'; +import { Button, Input, Space, Table } from 'antd'; +import type { ColumnsType, ColumnType } from 'antd/es/table'; +import type { FilterConfirmProps } from 'antd/es/table/interface'; import localStorageGet from 'api/browser/localstorage/get'; import localStorageSet from 'api/browser/localstorage/set'; import { SKIP_ONBOARDING } from 'constants/onboarding'; import ROUTES from 'constants/routes'; -import React, { useState } from 'react'; +import React, { useCallback, useState } from 'react'; import { useSelector } from 'react-redux'; import { Link, useLocation } from 'react-router-dom'; import { AppState } from 'store/reducers'; @@ -27,6 +31,57 @@ function Metrics(): JSX.Element { localStorageSet(SKIP_ONBOARDING, 'true'); setSkipOnboarding(true); }; + const handleSearch = (confirm: (param?: FilterConfirmProps) => void): void => { + confirm(); + }; + + const FilterIcon = useCallback( + ({ filtered }) => ( + + ), + [], + ); + + const filterDropdown = useCallback( + ({ setSelectedKeys, selectedKeys, confirm }) => ( +
+ + setSelectedKeys(e.target.value ? [e.target.value] : []) + } + allowClear + onPressEnter={(): void => handleSearch(confirm)} + style={{ + marginBottom: 8, + }} + /> + + + +
+ ), + [], + ); if ( services.length === 0 && @@ -37,21 +92,37 @@ function Metrics(): JSX.Element { return ; } + type DataIndex = keyof ServicesList; + + const getColumnSearchProps = ( + dataIndex: DataIndex, + ): ColumnType => ({ + filterDropdown, + filterIcon: FilterIcon, + onFilter: (value: string | number | boolean, record: DataProps): boolean => + record[dataIndex] + .toString() + .toLowerCase() + .includes(value.toString().toLowerCase()), + render: (text: string): JSX.Element => ( + + {text} + + ), + }); + const columns: ColumnsType = [ { title: 'Application', dataIndex: 'serviceName', key: 'serviceName', - render: (text: string): JSX.Element => ( - - {text} - - ), + ...getColumnSearchProps('serviceName'), }, { title: 'P99 latency (in ms)', dataIndex: 'p99', key: 'p99', + defaultSortOrder: 'descend', sorter: (a: DataProps, b: DataProps): number => a.p99 - b.p99, render: (value: number): string => (value / 1000000).toFixed(2), },