Skip to content

Commit 6cb550f

Browse files
Merge pull request #2508 from RedisInsight/fe/bugfix/RI-4879
#RI-4879 - fix showing message for key details
2 parents 9a80394 + b24c549 commit 6cb550f

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

redisinsight/ui/src/pages/browser/components/browser-right-panel/BrowserRightPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const BrowserRightPanel = (props: Props) => {
4646
} = props
4747

4848
const { isBrowserFullScreen, viewType } = useSelector(keysSelector)
49-
const { total } = useSelector(keysDataSelector)
49+
const { total, lastRefreshTime: keysLastRefreshTime } = useSelector(keysDataSelector)
5050
const { type, length } = useSelector(selectedKeyDataSelector) ?? { type: '', length: 0 }
5151

5252
const { instanceId } = useParams<{ instanceId: string }>()
@@ -119,6 +119,7 @@ const BrowserRightPanel = (props: Props) => {
119119
onEditKey={onEditKey}
120120
onRemoveKey={onSelectKey}
121121
totalKeys={total}
122+
keysLastRefreshTime={keysLastRefreshTime}
122123
/>
123124
)}
124125
{isAddKeyPanelOpen && every([!isBulkActionsPanelOpen, !isCreateIndexPanelOpen], Boolean) && (

redisinsight/ui/src/pages/browser/components/key-details/KeyDetails/KeyDetails.spec.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,21 @@ describe('KeyDetails', () => {
1010
expect(render(<KeyDetails {...instance(mockedProps)} />)).toBeTruthy()
1111
})
1212

13+
it('should render nothing when there are no keys', () => {
14+
render(<KeyDetails {...instance(mockedProps)} totalKeys={0} keysLastRefreshTime={null} />)
15+
16+
expect(screen.queryByTestId('explore-guides')).not.toBeInTheDocument()
17+
expect(screen.queryByTestId('select-key-message')).not.toBeInTheDocument()
18+
})
19+
1320
it('should render explore-guides when there are no keys', () => {
14-
render(<KeyDetails {...instance(mockedProps)} totalKeys={0} />)
21+
render(<KeyDetails {...instance(mockedProps)} totalKeys={0} keysLastRefreshTime={1} />)
1522

1623
expect(screen.getByTestId('explore-guides')).toBeInTheDocument()
1724
})
1825

1926
it('should render proper message when there are keys', () => {
20-
render(<KeyDetails {...instance(mockedProps)} totalKeys={10} />)
27+
render(<KeyDetails {...instance(mockedProps)} totalKeys={10} keysLastRefreshTime={1} />)
2128

2229
expect(screen.getByTestId('select-key-message')).toBeInTheDocument()
2330
})

redisinsight/ui/src/pages/browser/components/key-details/KeyDetails/KeyDetails.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { sendEventTelemetry, TelemetryEvent, getBasedOnViewTypeEvent } from 'uiS
3030
import { RedisResponseBuffer } from 'uiSrc/slices/interfaces'
3131

3232
import ExploreGuides from 'uiSrc/components/explore-guides'
33+
import { Nullable } from 'uiSrc/utils'
3334
import KeyDetailsHeader from '../../key-details-header/KeyDetailsHeader'
3435
import ZSetDetails from '../../zset-details/ZSetDetails'
3536
import StringDetails from '../../string-details/StringDetails'
@@ -56,10 +57,11 @@ export interface Props {
5657
onEditTTL: (key: RedisResponseBuffer, ttl: number) => void
5758
onEditKey: (key: RedisResponseBuffer, newKey: RedisResponseBuffer, onFailure?: () => void) => void
5859
totalKeys: number
60+
keysLastRefreshTime: Nullable<number>
5961
}
6062

6163
const KeyDetails = ({ ...props }: Props) => {
62-
const { onClosePanel, onRemoveKey, totalKeys } = props
64+
const { onClosePanel, onRemoveKey, totalKeys, keysLastRefreshTime } = props
6365
const { loading, error = '', data } = useSelector(selectedKeySelector)
6466
const { type: selectedKeyType, name: selectedKey } = useSelector(selectedKeyDataSelector) ?? {
6567
type: KeyTypes.String,
@@ -139,6 +141,16 @@ const KeyDetails = ({ ...props }: Props) => {
139141
[KeyTypes.Stream]: <StreamDetailsWrapper isFooterOpen={isAddItemPanelOpen} />,
140142
}
141143

144+
const NoKeysSelectedMessage = () => (
145+
<>
146+
{totalKeys > 0 ? (
147+
<span data-testid="select-key-message">
148+
Select the key from the list on the left to see the details of the key.
149+
</span>
150+
) : (<ExploreGuides />)}
151+
</>
152+
)
153+
142154
return (
143155
<div className={styles.page}>
144156
<EuiFlexGroup
@@ -169,15 +181,7 @@ const KeyDetails = ({ ...props }: Props) => {
169181
<p data-testid="no-keys-selected-text">
170182
{error}
171183
</p>
172-
) : (
173-
<>
174-
{totalKeys > 0 ? (
175-
<span data-testid="select-key-message">
176-
Select the key from the list on the left to see the details of the key.
177-
</span>
178-
) : (<ExploreGuides />)}
179-
</>
180-
)}
184+
) : (!!keysLastRefreshTime && <NoKeysSelectedMessage />)}
181185
</EuiText>
182186
</div>
183187
</>

redisinsight/ui/src/pages/browser/components/key-details/KeyDetailsWrapper.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { fetchReJSON } from 'uiSrc/slices/browser/rejson'
2323
import { refreshStream } from 'uiSrc/slices/browser/stream'
2424
import { getBasedOnViewTypeEvent, sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
2525
import { RedisResponseBuffer } from 'uiSrc/slices/interfaces'
26+
import { Nullable } from 'uiSrc/utils'
2627
import KeyDetails from './KeyDetails/KeyDetails'
2728

2829
export interface Props {
@@ -34,6 +35,7 @@ export interface Props {
3435
onRemoveKey: () => void
3536
keyProp: RedisResponseBuffer | null
3637
totalKeys: number
38+
keysLastRefreshTime: Nullable<number>
3739
}
3840

3941
const KeyDetailsWrapper = (props: Props) => {
@@ -45,7 +47,8 @@ const KeyDetailsWrapper = (props: Props) => {
4547
onEditKey,
4648
onRemoveKey,
4749
keyProp,
48-
totalKeys
50+
totalKeys,
51+
keysLastRefreshTime,
4952
} = props
5053

5154
const { instanceId } = useParams<{ instanceId: string }>()
@@ -158,6 +161,7 @@ const KeyDetailsWrapper = (props: Props) => {
158161
onEditTTL={handleEditTTL}
159162
onEditKey={handleEditKey}
160163
totalKeys={totalKeys}
164+
keysLastRefreshTime={keysLastRefreshTime}
161165
/>
162166
)
163167
}

0 commit comments

Comments
 (0)