Skip to content

Commit debba5d

Browse files
authored
[RI-7058] Replace EuiInMemoryTable with Table (#4640)
* RI-7058: expose redis ui Table component * update Table for TopKeys * use Table for TopNamespaces * use Table for UserApiKeysTable * use Table for TestConnectionsTable * use Table for TableResult * use Table for ClusterNodesTable * update Table for TableInfoResult * use Table for TableResult * use Table for ShortcutsTable * use Table for RedisClusterDatabasesPage * use Table for SentinelDatabasesResultPage * use Table for SentinelDatabasesPage * use Table for RedisCloudSubscriptionsPage * use Table for RedisCloudDatabasesResultPage * use Table for RedisCloudDatabasesPage * use Table for redisgraph * use Table for TableView * use Table for rdi tables
1 parent 01d6ef4 commit debba5d

File tree

69 files changed

+1252
-2395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1252
-2395
lines changed

jest.config.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ module.exports = {
1212
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
1313
'\\.scss\\?inline$': '<rootDir>/redisinsight/__mocks__/scssRaw.js',
1414
'uiSrc/(.*)': '<rootDir>/redisinsight/ui/src/$1',
15+
'@redislabsdev/redis-ui-components': '@redis-ui/components',
1516
'@redislabsdev/redis-ui-styles': '@redis-ui/styles',
1617
'@redislabsdev/redis-ui-icons': '@redis-ui/icons',
18+
'@redislabsdev/redis-ui-table': '@redis-ui/table',
1719
'monaco-editor': '<rootDir>/redisinsight/__mocks__/monacoMock.js',
1820
'monaco-yaml': '<rootDir>/redisinsight/__mocks__/monacoYamlMock.js',
1921
unified: '<rootDir>/redisinsight/__mocks__/unified.js',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@
237237
"@redis-ui/components": "^38.1.3",
238238
"@redis-ui/icons": "^4.16.1",
239239
"@redis-ui/styles": "^11.0.2",
240+
"@redis-ui/table": "^2.4.0",
240241
"@reduxjs/toolkit": "^1.6.2",
241242
"@stablelib/snappy": "^1.0.2",
242243
"ajv": "^8.17.1",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from '@redis-ui/table'

redisinsight/ui/src/components/shortcuts-flyout/ShortcutsFlyout.tsx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import React from 'react'
2-
import cx from 'classnames'
32
import { useDispatch, useSelector } from 'react-redux'
4-
import { EuiBasicTableColumn, EuiInMemoryTable } from '@elastic/eui'
53
import { appInfoSelector, setShortcutsFlyoutState } from 'uiSrc/slices/app/info'
64
import { KeyboardShortcut } from 'uiSrc/components'
75
import { BuildType } from 'uiSrc/constants/env'
@@ -12,44 +10,42 @@ import {
1210
DrawerBody,
1311
} from 'uiSrc/components/base/layout/drawer'
1412
import { Title } from 'uiSrc/components/base/text/Title'
13+
import { Table, ColumnDefinition } from 'uiSrc/components/base/layout/table'
1514

1615
import { SHORTCUTS, ShortcutGroup, separator } from './schema'
1716

18-
import styles from './styles.module.scss'
19-
2017
const ShortcutsFlyout = () => {
2118
const { isShortcutsFlyoutOpen, server } = useSelector(appInfoSelector)
2219

2320
const dispatch = useDispatch()
2421

25-
const tableColumns: EuiBasicTableColumn<any>[] = [
22+
const tableColumns: ColumnDefinition<any>[] = [
2623
{
27-
name: '',
28-
field: 'description',
29-
width: '60%',
24+
header: 'Description',
25+
id: 'description',
26+
accessorKey: 'description',
27+
enableSorting: false,
3028
},
3129
{
32-
name: '',
33-
field: 'keys',
34-
width: '40%',
35-
render: (items: string[]) => (
36-
<KeyboardShortcut items={items} separator={separator} transparent />
37-
),
30+
header: 'Shortcut',
31+
id: 'keys',
32+
accessorKey: 'keys',
33+
enableSorting: false,
34+
cell: ({
35+
row: {
36+
original: { keys },
37+
},
38+
}) => <KeyboardShortcut items={keys} separator={separator} transparent />,
3839
},
3940
]
4041

4142
const ShortcutsTable = ({ name, items }: ShortcutGroup) => (
42-
<div key={name}>
43+
<div key={name} data-testid={`shortcuts-table-${name}`}>
4344
<Title size="XS" data-test-subj={`shortcuts-section-${name}`}>
4445
{name}
4546
</Title>
4647
<Spacer size="m" />
47-
<EuiInMemoryTable
48-
className={cx('inMemoryTableDefault', styles.table)}
49-
columns={tableColumns}
50-
items={items}
51-
responsive={false}
52-
/>
48+
<Table columns={tableColumns} data={items} defaultSorting={[]} />
5349
<Spacer size="xl" />
5450
</div>
5551
)

redisinsight/ui/src/components/shortcuts-flyout/styles.module.scss

Lines changed: 0 additions & 38 deletions
This file was deleted.

redisinsight/ui/src/packages/clients-list/src/components/table-view/TableView.tsx

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,36 @@
11
import React, { useEffect, useState } from 'react'
22
import cx from 'classnames'
3-
import { EuiBasicTableColumn, EuiInMemoryTable } from '@elastic/eui'
3+
import { Table, ColumnDefinition } from 'uiSrc/components/base/layout/table'
44

55
export interface Props {
66
query: string
77
result: any
8-
matched?: number
98
}
109

1110
const noResultMessage = 'No results'
1211

1312
const TableView = React.memo(({ result, query }: Props) => {
14-
const [columns, setColumns] = useState<EuiBasicTableColumn<any>[]>([])
13+
const [columns, setColumns] = useState<ColumnDefinition<any>[]>([])
1514

1615
useEffect(() => {
1716
if (!result?.length) {
1817
return
1918
}
2019

2120
const newColumns = Object.keys(result[0]).map((item) => ({
22-
field: item,
23-
name: item,
24-
truncateText: true,
21+
header: item,
22+
id: item,
23+
accessorKey: item,
24+
enableSorting: true,
2525
}))
2626

2727
setColumns(newColumns)
2828
}, [result, query])
2929

3030
return (
3131
<div className={cx('queryResultsContainer', 'container')}>
32-
<EuiInMemoryTable
33-
pagination
34-
items={result ?? []}
35-
loading={!result}
36-
message={noResultMessage}
37-
columns={columns}
38-
className={cx({
39-
table: true,
40-
inMemoryTableDefault: true,
41-
tableWithPagination: result?.length > 10,
42-
})}
43-
responsive={false}
44-
data-testid={`query-table-result-${query}`}
45-
/>
32+
<Table data={result ?? []} columns={columns} paginationEnabled />
33+
{!result?.length && <span>{noResultMessage}</span>}
4634
</div>
4735
)
4836
})

redisinsight/ui/src/packages/clients-list/tsconfig.json

Lines changed: 0 additions & 32 deletions
This file was deleted.

redisinsight/ui/src/packages/redisearch/src/components/TableInfoResult/TableInfoResult.tsx

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/* eslint-disable react/prop-types */
2-
import React, { ReactElement, useEffect, useState } from 'react'
2+
import React, { useEffect, useState } from 'react'
33
import cx from 'classnames'
44
import { toUpper, flatten, isArray, isEmpty, map, uniq } from 'lodash'
5-
import { EuiBasicTableColumn, EuiIcon, EuiInMemoryTable } from '@elastic/eui'
5+
import { EuiIcon } from '@elastic/eui'
6+
import { Table, ColumnDefinition } from 'uiSrc/components/base/layout/table'
67

78
import { ColorText, Text } from '../../../../../components/base/text'
89
import { LoadingContent } from '../../../../../components/base/layout'
@@ -14,15 +15,13 @@ export interface Props {
1415
result: any
1516
}
1617

17-
const loadingMessage = 'loading...'
1818
const noResultsMessage = 'No results found.'
1919
const noOptionsMessage = 'No options found'
2020

2121
const TableInfoResult = React.memo((props: Props) => {
2222
const { result: resultProp, query } = props
2323

2424
const [result, setResult] = useState(resultProp)
25-
2625
const [items, setItems] = useState([])
2726

2827
useEffect(() => {
@@ -42,26 +41,24 @@ const TableInfoResult = React.memo((props: Props) => {
4241
const uniqColumns =
4342
uniq(flatten(map(items, (item) => Object.keys(item)))) ?? []
4443

45-
const columns: EuiBasicTableColumn<any>[] = uniqColumns.map(
44+
const columns: ColumnDefinition<any>[] = uniqColumns.map(
4645
(title: string = ' ') => ({
47-
field: title,
48-
name: toUpper(title),
49-
truncateText: true,
50-
align: isBooleanColumn(title) ? 'center' : 'left',
51-
'data-testid': `query-column-${title}`,
52-
// sortable: (value) => (value[title] ? value[title].toLowerCase() : Infinity),
53-
render: function Cell(initValue?: string): ReactElement | null {
46+
header: toUpper(title),
47+
id: title,
48+
accessorKey: title,
49+
enableSorting: false,
50+
cell: ({ row: { original } }) => {
51+
const initValue = original[title]
5452
if (isBooleanColumn(title)) {
5553
return (
56-
<div className="icon">
54+
<div className="icon" data-testid={`query-column-${title}`}>
5755
<EuiIcon
5856
type={initValue ? 'check' : 'cross'}
5957
color={initValue ? 'primary' : 'danger'}
6058
/>
6159
</div>
6260
)
6361
}
64-
6562
return <Text>{initValue}</Text>
6663
},
6764
}),
@@ -119,19 +116,9 @@ const TableInfoResult = React.memo((props: Props) => {
119116
return (
120117
<div className="container">
121118
{isDataArr && (
122-
<div className="content">
119+
<div className="content" data-testid={`query-table-result-${query}`}>
123120
{Header()}
124-
<EuiInMemoryTable
125-
items={items ?? []}
126-
loading={!result}
127-
message={loadingMessage}
128-
columns={columns}
129-
className={cx('inMemoryTableDefault', 'tableInfo', {
130-
tableWithPagination: result?.length > 10,
131-
})}
132-
responsive={false}
133-
data-testid={`query-table-result-${query}`}
134-
/>
121+
<Table columns={columns} data={items ?? []} />
135122
{Footer()}
136123
</div>
137124
)}

redisinsight/ui/src/packages/redisearch/src/components/TableResult/TableResult.tsx

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import React, { ReactElement, useEffect, useState } from 'react'
1+
import React, { useEffect, useState } from 'react'
22
import parse from 'html-react-parser'
33
import cx from 'classnames'
44
import { flatten, isArray, isEmpty, map, uniq } from 'lodash'
5-
import { EuiBasicTableColumn, EuiInMemoryTable, EuiToolTip } from '@elastic/eui'
5+
import { EuiToolTip } from '@elastic/eui'
6+
import { Table, ColumnDefinition } from 'uiSrc/components/base/layout/table'
67

78
import { ColorText } from '../../../../../components/base/text/ColorText'
89
import { IconButton } from '../../../../../components/base/forms/buttons'
@@ -17,13 +18,12 @@ export interface Props {
1718
cursorId?: null | number
1819
}
1920

20-
const loadingMessage = 'loading...'
2121
const noResultsMessage = 'No results found.'
2222

2323
const TableResult = React.memo((props: Props) => {
2424
const { result, query, matched, cursorId } = props
2525

26-
const [columns, setColumns] = useState<EuiBasicTableColumn<any>[]>([])
26+
const [columns, setColumns] = useState<ColumnDefinition<any>[]>([])
2727

2828
const checkShouldParsedHTML = (query: string) => {
2929
const command = query.toUpperCase()
@@ -49,15 +49,13 @@ const TableResult = React.memo((props: Props) => {
4949
const uniqColumns =
5050
uniq(flatten(map(result, (doc) => Object.keys(doc)))) ?? []
5151

52-
const newColumns: EuiBasicTableColumn<any>[] = uniqColumns.map(
52+
const newColumns: ColumnDefinition<any>[] = uniqColumns.map(
5353
(title: string = ' ') => ({
54-
field: title,
55-
name: title,
56-
truncateText: true,
57-
dataType: 'string',
58-
'data-testid': `query-column-${title}`,
59-
// sortable: (value) => (value[title] ? value[title].toLowerCase() : Infinity),
60-
render: function Cell(initValue: string = ''): ReactElement | string {
54+
header: title,
55+
id: title,
56+
accessorKey: title,
57+
cell: ({ row: { original } }) => {
58+
const initValue = original[title] || ''
6159
if (!initValue || (isArray(initValue) && isEmpty(initValue))) {
6260
return ''
6361
}
@@ -72,7 +70,11 @@ const TableResult = React.memo((props: Props) => {
7270
}
7371

7472
return (
75-
<div role="presentation" className={cx('tooltipContainer')}>
73+
<div
74+
role="presentation"
75+
className={cx('tooltipContainer')}
76+
data-testid={`query-column-${title}`}
77+
>
7678
<EuiToolTip
7779
position="bottom"
7880
title={title}
@@ -118,20 +120,9 @@ const TableResult = React.memo((props: Props) => {
118120
)}
119121
</div>
120122
{isDataArr && (
121-
<EuiInMemoryTable
122-
pagination
123-
items={result ?? []}
124-
loading={!result}
125-
message={loadingMessage}
126-
columns={columns}
127-
className={cx({
128-
table: true,
129-
inMemoryTableDefault: true,
130-
tableWithPagination: result?.length > 10,
131-
})}
132-
responsive={false}
133-
data-testid={`query-table-result-${query}`}
134-
/>
123+
<div data-testid={`query-table-result-${query}`}>
124+
<Table columns={columns} data={result ?? []} />
125+
</div>
135126
)}
136127
{isDataEl && <div className={cx('resultEl')}>{result}</div>}
137128
{!isDataArr && !isDataEl && (

0 commit comments

Comments
 (0)