Skip to content

Commit 4ea43b0

Browse files
committed
Merge remote-tracking branch 'origin/be/feature/RI-3997_Display_indexes_in_Workbench_and_Analytics' into be/feature/RI-3997_Display_indexes_in_Workbench_and_Analytics
2 parents 39d345b + 4a1c91f commit 4ea43b0

File tree

17 files changed

+79
-30
lines changed

17 files changed

+79
-30
lines changed

redisinsight/ui/src/components/cli/components/cli-header/CliHeader.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { sessionStorageService } from 'uiSrc/services'
2222
import { connectedInstanceSelector } from 'uiSrc/slices/instances/instances'
2323
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
2424
import { outputSelector, resetOutputLoading } from 'uiSrc/slices/cli/cli-output'
25+
import { getDbIndex } from 'uiSrc/utils'
2526

2627
import styles from './styles.module.scss'
2728

@@ -32,7 +33,7 @@ const CliHeader = () => {
3233

3334
const { host, port } = useSelector(connectedInstanceSelector)
3435
const { db } = useSelector(outputSelector)
35-
const endpoint = db > 0 ? `${host}:${port}[${db}]` : `${host}:${port}`
36+
const endpoint = `${host}:${port}${getDbIndex(db)}`
3637

3738
const removeCliClient = () => {
3839
const cliClientUuid = sessionStorageService.get(BrowserStorageItem.cliClientUuid) ?? ''

redisinsight/ui/src/components/cli/components/cli-input/CliInput/CliInput.spec.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('CliInput', () => {
2323
const dbIndexEl = queryByTestId('cli-db-index')
2424

2525
expect(dbIndexEl).toBeInTheDocument()
26-
expect(dbIndexEl).toHaveTextContent('[1]')
26+
expect(dbIndexEl).toHaveTextContent('[db1]')
2727
})
2828

2929
it('should not render db index if it is 0', () => {

redisinsight/ui/src/components/cli/components/cli-input/CliInput/CliInput.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ContentEditableEvent } from 'react-contenteditable'
33

44
import { ContentEditable } from 'uiSrc/components'
55
import { parseContentEditableChangeHtml } from 'uiSrc/components/ContentEditable'
6+
import { getDbIndex } from 'uiSrc/utils'
67

78
import styles from './styles.module.scss'
89

@@ -28,7 +29,7 @@ const CliInput = (props: Props) => {
2829
return (
2930
<>
3031
<span>
31-
{dbIndex !== 0 && <span data-testid="cli-db-index">{`[${dbIndex}] `}</span>}
32+
{dbIndex !== 0 && <span data-testid="cli-db-index">{`${getDbIndex(dbIndex)} `}</span>}
3233
&gt;&nbsp;
3334
</span>
3435
<ContentEditable

redisinsight/ui/src/components/query-card/QueryCard.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export interface Props {
4040
loading?: boolean
4141
isNotStored?: boolean
4242
executionTime?: number
43+
db?: number
4344
onQueryDelete: () => void
4445
onQueryReRun: () => void
4546
onQueryOpen: () => void
@@ -79,6 +80,7 @@ const QueryCard = (props: Props) => {
7980
emptyCommand,
8081
isNotStored,
8182
executionTime,
83+
db,
8284
} = props
8385

8486
const { visualizations = [] } = useSelector(appPluginsSelector)
@@ -178,6 +180,7 @@ const QueryCard = (props: Props) => {
178180
summary={summary}
179181
summaryText={getSummaryText(summary, resultsMode)}
180182
executionTime={executionTime}
183+
db={db}
181184
toggleOpen={toggleOpen}
182185
toggleFullScreen={toggleFullScreen}
183186
setSelectedValue={changeViewTypeSelected}
@@ -194,6 +197,7 @@ const QueryCard = (props: Props) => {
194197
<QueryCardCliResultWrapper
195198
loading={loading}
196199
query={command}
200+
db={db}
197201
resultsMode={resultsMode}
198202
result={result}
199203
isNotStored={isNotStored}

redisinsight/ui/src/components/query-card/QueryCardCliGroupResult/QueryCardCliGroupResult.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import { CommonErrorResponse } from '../QueryCardCommonResult'
99
export interface Props {
1010
result?: Maybe<CommandExecutionResult[]>
1111
isFullScreen?: boolean
12+
db?: number
1213
}
1314

1415
const QueryCardCliGroupResult = (props: Props) => {
15-
const { result = [], isFullScreen } = props
16+
const { result = [], isFullScreen, db } = props
1617

1718
return (
1819
<div data-testid="query-cli-default-result" className="query-card-output-response-success">
@@ -23,7 +24,7 @@ const QueryCardCliGroupResult = (props: Props) => {
2324
if (React.isValidElement(commonError)) {
2425
return ([wbSummaryCommand(item.command), commonError])
2526
}
26-
return flatten(cliParseCommandsGroupResult(item))
27+
return flatten(cliParseCommandsGroupResult(item, db))
2728
}))}
2829
/>
2930
</div>

redisinsight/ui/src/components/query-card/QueryCardCliResultWrapper/QueryCardCliResultWrapper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ export interface Props {
2020
resultsMode?: ResultsMode
2121
isNotStored?: boolean
2222
isFullScreen?: boolean
23+
db?: number
2324
}
2425

2526
const QueryCardCliResultWrapper = (props: Props) => {
26-
const { result = [], query, loading, resultsMode, isNotStored, isFullScreen } = props
27+
const { result = [], query, loading, resultsMode, isNotStored, isFullScreen, db } = props
2728

2829
return (
2930
<div className={cx('queryResultsContainer', styles.container)}>
@@ -36,7 +37,7 @@ const QueryCardCliResultWrapper = (props: Props) => {
3637
</EuiText>
3738
)}
3839
{isGroupResults(resultsMode) && isArray(result[0]?.response)
39-
? <QueryCardCliGroupResult result={result} isFullScreen={isFullScreen} />
40+
? <QueryCardCliGroupResult result={result} isFullScreen={isFullScreen} db={db} />
4041
: (
4142
<QueryCardCliDefaultResult
4243
isFullScreen={isFullScreen}

redisinsight/ui/src/components/query-card/QueryCardHeader/QueryCardHeader.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface Props {
6464
loading?: boolean
6565
executionTime?: number
6666
emptyCommand?: boolean
67+
db?: number
6768
toggleOpen: () => void
6869
toggleFullScreen: () => void
6970
setSelectedValue: (type: WBQueryType, value: string) => void
@@ -108,6 +109,7 @@ const QueryCardHeader = (props: Props) => {
108109
setSelectedValue,
109110
onQueryDelete,
110111
onQueryReRun,
112+
db,
111113
} = props
112114

113115
const { visualizations = [] } = useSelector(appPluginsSelector)
@@ -267,7 +269,7 @@ const QueryCardHeader = (props: Props) => {
267269
>
268270
<div className="copy-btn-wrapper">
269271
<EuiTextColor className={styles.title} color="subdued" component="div" data-testid="query-card-command">
270-
<QueryCardTooltip query={query} summary={summaryText} />
272+
<QueryCardTooltip query={query} summary={summaryText} db={db} resultsMode={resultsMode} />
271273
</EuiTextColor>
272274
<EuiButtonIcon
273275
iconType="copy"

redisinsight/ui/src/components/query-card/QueryCardTooltip/QueryCardTooltip.spec.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ describe('QueryCardTooltip', () => {
1111
expect(render(<QueryCardTooltip {...instance(mockedProps)} />)).toBeTruthy()
1212
})
1313

14+
it('should show db index', () => {
15+
const { queryByTestId } = render(
16+
<QueryCardTooltip {...instance(mockedProps)} query={null} summary={null} db={2} />
17+
)
18+
19+
expect(queryByTestId('query-card-tooltip-anchor')).toHaveTextContent('[db2]')
20+
})
21+
1422
it(`should show ${EMPTY_COMMAND} if command=null and summary=`, () => {
1523
const { queryByTestId } = render(
1624
<QueryCardTooltip {...instance(mockedProps)} query={null} summary={null} />

redisinsight/ui/src/components/query-card/QueryCardTooltip/QueryCardTooltip.tsx

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@ import { EuiToolTip } from '@elastic/eui'
33
import { take } from 'lodash'
44
import cx from 'classnames'
55

6-
import { Nullable, truncateText } from 'uiSrc/utils'
6+
import { Nullable, getDbIndex, isGroupResults, truncateText } from 'uiSrc/utils'
77
import { EMPTY_COMMAND } from 'uiSrc/constants'
8+
import { ResultsMode } from 'uiSrc/slices/interfaces'
89
import styles from './styles.module.scss'
910

1011
export interface Props {
1112
query: Nullable<string>
1213
summary?: Nullable<string>
1314
maxLinesNumber?: number
15+
resultsMode?: ResultsMode
16+
db?: number
1417
}
1518

1619
interface IQueryLine {
@@ -20,7 +23,8 @@ interface IQueryLine {
2023
}
2124

2225
const QueryCardTooltip = (props: Props) => {
23-
const { query = '', maxLinesNumber = 20, summary = '' } = props
26+
const { query = '', maxLinesNumber = 20, summary = '', resultsMode, db } = props
27+
const command = summary || query || EMPTY_COMMAND
2428

2529
let queryLines: IQueryLine[] = (query || EMPTY_COMMAND).split('\n')
2630
.map((query: string, i) => ({
@@ -39,13 +43,14 @@ const QueryCardTooltip = (props: Props) => {
3943
const contentItems = queryLines
4044
.map((item: IQueryLine) => {
4145
const { value, index, isFolding } = item
42-
return !isMultilineCommand ? <span key={index}>{value}</span> : (
46+
const command = `${getDbIndex(db)} ${value}`
47+
return !isMultilineCommand ? <span key={index}>{command}</span> : (
4348
<pre
4449
key={index}
4550
className={cx(styles.queryLine, styles.queryMultiLine, { [styles.queryLineFolding]: isFolding })}
4651
>
4752
<div className={styles.queryLineNumber}>{`${index + 1}`}</div>
48-
<span>{value}</span>
53+
<span>{command}</span>
4954
</pre>
5055
)
5156
})
@@ -57,7 +62,9 @@ const QueryCardTooltip = (props: Props) => {
5762
content={<>{contentItems}</>}
5863
position="bottom"
5964
>
60-
<span data-testid="query-card-tooltip-anchor">{summary || query || EMPTY_COMMAND}</span>
65+
<span data-testid="query-card-tooltip-anchor">
66+
{`${!isGroupResults(resultsMode) ? getDbIndex(db) : ''} ${command}`}
67+
</span>
6168
</EuiToolTip>
6269
)
6370
}

redisinsight/ui/src/constants/cliOutput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { EuiLink, EuiTextColor } from '@elastic/eui'
22
import React, { Fragment } from 'react'
33
import { getRouterLinkProps } from 'uiSrc/services'
4+
import { getDbIndex } from 'uiSrc/utils'
45

56
export const ClearCommand = 'clear'
67
export const SelectCommand = 'select'
@@ -38,8 +39,7 @@ export const InitOutputText = (
3839
'\n\n',
3940
'Pinging Redis server on ',
4041
<EuiTextColor color="default" key={Math.random()}>
41-
{`${host}:${port}`}
42-
{dbIndex > 0 && `[${dbIndex}]`}
42+
{`${host}:${port}${getDbIndex(dbIndex)}`}
4343
</EuiTextColor>,
4444
]
4545

0 commit comments

Comments
 (0)