Skip to content

Commit 5bc74d2

Browse files
committed
#RI-5371 - fix showing no results messages
1 parent 1963447 commit 5bc74d2

File tree

10 files changed

+44
-11
lines changed

10 files changed

+44
-11
lines changed

redisinsight/ui/src/pages/browser/components/key-list/KeyList.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ const KeyList = forwardRef((props: Props, ref) => {
146146
return ''
147147
}
148148

149-
if (itemsRef.current.length < keysState.keys.length) {
149+
if (!keysState.lastRefreshTime || itemsRef.current.length < keysState.keys.length) {
150150
return 'loading...'
151151
}
152152

@@ -331,6 +331,8 @@ const KeyList = forwardRef((props: Props, ref) => {
331331
},
332332
]
333333

334+
const noItemsMessage = getNoItemsMessage()
335+
334336
const VirtualizeTable = () => (
335337
<VirtualTable
336338
selectable
@@ -346,7 +348,7 @@ const KeyList = forwardRef((props: Props, ref) => {
346348
items={itemsRef.current}
347349
totalItemsCount={keysState.total ?? Infinity}
348350
scanned={isSearched || isFiltered ? keysState.scanned : 0}
349-
noItemsMessage={getNoItemsMessage()}
351+
noItemsMessage={noItemsMessage}
350352
selectedKey={selectedKey.data}
351353
scrollTopProp={scrollTopPosition}
352354
setScrollTopPosition={setScrollTopPosition}

redisinsight/ui/src/pages/workbench/components/wb-results/WBResults/WBResults.spec.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { cloneDeep } from 'lodash'
22
import React from 'react'
33
import { instance, mock } from 'ts-mockito'
44
import { CommandExecutionUI } from 'uiSrc/slices/interfaces'
5-
import { cleanup, mockedStore, render } from 'uiSrc/utils/test-utils'
5+
import { cleanup, mockedStore, render, screen } from 'uiSrc/utils/test-utils'
66
import WBResults, { Props } from './WBResults'
77

88
const mockedProps = mock<Props>()
@@ -27,12 +27,18 @@ describe('WBResults', () => {
2727
expect(render(<WBResults {...instance(mockedProps)} />)).toBeTruthy()
2828
})
2929

30-
it('should not render NoResults component with empty items', () => {
31-
const { getByTestId } = render(<WBResults {...instance(mockedProps)} items={[]} />)
30+
it('should render NoResults component with empty items', () => {
31+
const { getByTestId } = render(<WBResults {...instance(mockedProps)} items={[]} isResultsLoaded />)
3232

3333
expect(getByTestId('wb_no-results')).toBeInTheDocument()
3434
})
3535

36+
it('should not render NoResults component with empty items and loading state', () => {
37+
render(<WBResults {...instance(mockedProps)} items={[]} isResultsLoaded={false} />)
38+
39+
expect(screen.queryByTestId('wb_no-results')).not.toBeInTheDocument()
40+
})
41+
3642
it('should render with custom props', () => {
3743
const itemsMock: CommandExecutionUI[] = [
3844
{

redisinsight/ui/src/pages/workbench/components/wb-results/WBResults/WBResults.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react'
22
import cx from 'classnames'
33
import {
4-
EuiButtonEmpty,
4+
EuiButtonEmpty, EuiProgress,
55
} from '@elastic/eui'
66

77
import { CodeButtonParams } from 'uiSrc/constants'
@@ -16,6 +16,7 @@ import WbNoResultsMessage from 'uiSrc/pages/workbench/components/wb-no-results-m
1616
import styles from './styles.module.scss'
1717

1818
export interface Props {
19+
isResultsLoaded: boolean
1920
items: CommandExecutionUI[]
2021
clearing: boolean
2122
processing: boolean
@@ -30,6 +31,7 @@ export interface Props {
3031
}
3132
const WBResults = (props: Props) => {
3233
const {
34+
isResultsLoaded,
3335
items = [],
3436
clearing,
3537
processing,
@@ -60,7 +62,15 @@ const WBResults = (props: Props) => {
6062

6163
return (
6264
<div className={styles.wrapper}>
63-
{!!items.length && (
65+
{!isResultsLoaded && (
66+
<EuiProgress
67+
color="primary"
68+
size="xs"
69+
position="absolute"
70+
data-testid="progress-wb-history"
71+
/>
72+
)}
73+
{!!items?.length && (
6474
<div className={styles.header}>
6575
<EuiButtonEmpty
6676
size="s"
@@ -76,7 +86,7 @@ const WBResults = (props: Props) => {
7686
)}
7787
<div className={cx(styles.container)}>
7888
<div ref={scrollDivRef} />
79-
{items.length ? items.map((
89+
{items?.length ? items.map((
8090
{
8191
command = '',
8292
isOpen = false,
@@ -124,7 +134,7 @@ const WBResults = (props: Props) => {
124134
onQueryDelete={() => onQueryDelete(id)}
125135
/>
126136
)) : null}
127-
{!items.length && (<WbNoResultsMessage />)}
137+
{(isResultsLoaded && !items.length) && (<WbNoResultsMessage />)}
128138
</div>
129139
</div>
130140
)

redisinsight/ui/src/pages/workbench/components/wb-results/WBResults/styles.module.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
display: flex;
1313
flex-direction: column;
14+
15+
position: relative;
1416
}
1517

1618
.container {

redisinsight/ui/src/pages/workbench/components/wb-results/WBResultsWrapper.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { CodeButtonParams } from 'uiSrc/constants'
66
import WBResults from './WBResults'
77

88
export interface Props {
9+
isResultsLoaded: boolean
910
items: CommandExecutionUI[]
1011
clearing: boolean
1112
processing: boolean

redisinsight/ui/src/pages/workbench/components/wb-view/WBView/WBView.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface Props {
3939
items: CommandExecutionUI[]
4040
clearing: boolean
4141
processing: boolean
42+
isResultsLoaded: boolean
4243
setScript: (script: string) => void
4344
setScriptEl: Function
4445
scriptEl: Nullable<monacoEditor.editor.IStandaloneCodeEditor>
@@ -74,6 +75,7 @@ const WBView = (props: Props) => {
7475
scriptEl,
7576
activeMode,
7677
resultsMode,
78+
isResultsLoaded,
7779
onSubmit,
7880
onQueryOpen,
7981
onQueryDelete,
@@ -218,6 +220,7 @@ const WBView = (props: Props) => {
218220
items={items}
219221
clearing={clearing}
220222
processing={processing}
223+
isResultsLoaded={isResultsLoaded}
221224
activeMode={activeMode}
222225
activeResultsMode={resultsMode}
223226
scrollDivRef={scrollDivRef}

redisinsight/ui/src/pages/workbench/components/wb-view/WBViewWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const WBViewWrapper = () => {
6363
const { instanceId } = useParams<{ instanceId: string }>()
6464

6565
const {
66+
isLoaded,
6667
loading,
6768
items,
6869
clearing,
@@ -233,6 +234,7 @@ const WBViewWrapper = () => {
233234
items={items}
234235
clearing={clearing}
235236
processing={processing}
237+
isResultsLoaded={isLoaded}
236238
script={script}
237239
setScript={setScript}
238240
setScriptEl={setScriptEl}

redisinsight/ui/src/slices/interfaces/workbench.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface StateWorkbenchSettings {
99
}
1010

1111
export interface StateWorkbenchResults {
12+
isLoaded: boolean
1213
loading: boolean
1314
processing: boolean
1415
clearing: boolean

redisinsight/ui/src/slices/tests/workbench/wb-results.spec.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,8 @@ describe('workbench results slice', () => {
302302
const mockCommandExecution = [{ mode: null, id: 'e3553f5a-0fdf-4282-8406-8b377c2060d2', databaseId: '3f795233-e26a-463b-a116-58cf620b18f2', command: 'get test', role: null, nodeOptions: null, createdAt: '2022-06-10T15:47:13.000Z', emptyCommand: false }]
303303
const state = {
304304
...initialStateWithItems,
305-
items: mockCommandExecution
305+
items: mockCommandExecution,
306+
isLoaded: true
306307
}
307308

308309
// Act
@@ -323,7 +324,8 @@ describe('workbench results slice', () => {
323324

324325
const state = {
325326
...initialStateWithItems,
326-
items: [{ mode: null, id: 'e3553f5a-0fdf-4282-8406-8b377c2060d2', databaseId: '3f795233-e26a-463b-a116-58cf620b18f2', command: EMPTY_COMMAND, role: null, nodeOptions: null, createdAt: '2022-06-10T15:47:13.000Z', emptyCommand: true }]
327+
items: [{ mode: null, id: 'e3553f5a-0fdf-4282-8406-8b377c2060d2', databaseId: '3f795233-e26a-463b-a116-58cf620b18f2', command: EMPTY_COMMAND, role: null, nodeOptions: null, createdAt: '2022-06-10T15:47:13.000Z', emptyCommand: true }],
328+
isLoaded: true,
327329
}
328330

329331
// Act

redisinsight/ui/src/slices/workbench/wb-results.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {
2929
} from '../interfaces'
3030

3131
export const initialState: StateWorkbenchResults = {
32+
isLoaded: false,
3233
loading: false,
3334
processing: false,
3435
clearing: false,
@@ -54,11 +55,13 @@ const workbenchResultsSlice = createSlice({
5455
state.items = payload.map((item) =>
5556
({ ...item, command: item.command || EMPTY_COMMAND, emptyCommand: !item.command }))
5657
state.loading = false
58+
state.isLoaded = true
5759
},
5860

5961
loadWBHistoryFailure: (state, { payload }) => {
6062
state.error = payload
6163
state.loading = false
64+
state.isLoaded = true
6265
},
6366

6467
// Process Workbench command to API
@@ -177,6 +180,7 @@ const workbenchResultsSlice = createSlice({
177180

178181
resetWBHistoryItems: (state) => {
179182
state.items = []
183+
state.isLoaded = false
180184
},
181185

182186
stopProcessing: (state) => {

0 commit comments

Comments
 (0)