Skip to content

Commit a4c5c79

Browse files
authored
Merge pull request #1781 from RedisInsight/fe/bugfix/RI-3726_profile_explain-new-expressions
[RI-3726] Profile Plugin - Add support for leftoff RediSearch expressions
2 parents f3ed15d + 98bf81b commit a4c5c79

File tree

9 files changed

+363
-186
lines changed

9 files changed

+363
-186
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const QueryCardHeader = (props: Props) => {
110110
setSelectedValue,
111111
onQueryDelete,
112112
onQueryReRun,
113+
onQueryProfile,
113114
db,
114115
} = props
115116

@@ -345,12 +346,12 @@ const QueryCardHeader = (props: Props) => {
345346
</EuiToolTip>
346347
)}
347348
</EuiFlexItem>
348-
<EuiFlexItem
349-
grow={false}
350-
className={cx(styles.buttonIcon, styles.viewTypeIcon)}
351-
onClick={onDropDownViewClick}
352-
>
353-
{isOpen && canCommandProfile && !summaryText && (
349+
{isOpen && canCommandProfile && !summaryText && (
350+
<EuiFlexItem
351+
grow={false}
352+
className={cx(styles.buttonIcon, styles.viewTypeIcon)}
353+
onClick={onDropDownViewClick}
354+
>
354355
<div className={styles.dropdownWrapper}>
355356
<div className={styles.dropdown}>
356357
<EuiSuperSelect
@@ -363,8 +364,8 @@ const QueryCardHeader = (props: Props) => {
363364
/>
364365
</div>
365366
</div>
366-
)}
367-
</EuiFlexItem>
367+
</EuiFlexItem>
368+
)}
368369
<EuiFlexItem
369370
grow={false}
370371
className={cx(styles.buttonIcon, styles.viewTypeIcon)}

redisinsight/ui/src/packages/ri-explain/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"prop-types": "^15.8.1",
6767
"react": "^18.2.0",
6868
"react-dom": "^18.2.0",
69+
"redisinsight-plugin-sdk": "^1.1.0",
6970
"uuid": "^9.0.0"
7071
}
7172
}

redisinsight/ui/src/packages/ri-explain/src/App.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import React from 'react'
22
import Explain from './Explain'
33

4-
const isDarkTheme = document.body.classList.contains('theme_DARK')
5-
64
export function App(props: { command?: string, data: any }) {
75

86
const ErrorResponse = HandleError(props)

redisinsight/ui/src/packages/ri-explain/src/Explain.tsx

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useState, useRef } from 'react'
22
import { Model, Graph } from '@antv/x6'
33
import { register} from '@antv/x6-react-shape'
44
import Hierarchy from '@antv/hierarchy'
5+
import { formatRedisReply } from 'redisinsight-plugin-sdk'
56

67
import {
78
EuiButtonIcon,
@@ -72,6 +73,18 @@ export default function Explain(props: IExplain): JSX.Element {
7273

7374
const module = ModuleType.Search
7475

76+
const [parsedRedisReply, setParsedRedisReply] = useState('')
77+
78+
useEffect(() => {
79+
if (command == 'ft.profile') {
80+
const getParsedResponse = async () => {
81+
const formattedResponse = await formatRedisReply(props.data[0].response, props.command)
82+
setParsedRedisReply(formattedResponse)
83+
}
84+
getParsedResponse()
85+
}
86+
})
87+
7588
if (command == 'ft.profile') {
7689
const info = props.data[0].response[1]
7790

@@ -82,6 +95,12 @@ export default function Explain(props: IExplain): JSX.Element {
8295
let [cluster, entityInfo] = ParseProfileCluster(info)
8396
cluster['Coordinator'].forEach((kv: [string, string]) => profilingTime[kv[0]] = kv[1])
8497
data = entityInfo
98+
return (
99+
<>
100+
<div className="responseFail">Visualization is not supported for a clustered database.</div>
101+
<div className="parsedRedisReply">{parsedRedisReply}</div>
102+
</>
103+
)
85104
} else if (typeof info[0] === 'string' && info[0].toLowerCase().startsWith('coordinator')) {
86105
const resultsProfile = info[2]
87106
data = ParseProfile(resultsProfile)
@@ -91,6 +110,12 @@ export default function Explain(props: IExplain): JSX.Element {
91110
'Parsing time': resultsProfile[1][1],
92111
'Pipeline creation time': resultsProfile[2][1],
93112
}
113+
return (
114+
<>
115+
<div className="responseFail">Visualization is not supported for a clustered database.</div>
116+
<div className="parsedRedisReply">{parsedRedisReply}</div>
117+
</>
118+
)
94119
} else {
95120
data = ParseProfile(info)
96121
profilingTime = {
@@ -213,11 +238,6 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
213238
line: {
214239
stroke: edgeColor,
215240
strokeWidth: (edge.getAttrs() as any)?.line?.strokeWidth,
216-
targetMarker: {
217-
name: 'block',
218-
stroke: edgeColor,
219-
fill: edgeColor,
220-
},
221241
},
222242
})
223243
})
@@ -234,11 +254,6 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
234254
line: {
235255
stroke: edgeColor,
236256
strokeWidth: (edge.getAttrs() as any)?.line?.strokeWidth,
237-
targetMarker: {
238-
name: 'block',
239-
fill: edgeColor,
240-
stroke: edgeColor,
241-
}
242257
},
243258
})
244259
})
@@ -270,8 +285,14 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
270285
if (data) {
271286
const info = data.data as EntityInfo
272287

273-
if (!info.snippet && info.parentSnippet && info.data?.startsWith(info.parentSnippet)) {
274-
info.data = info.data.substr(info.parentSnippet.length)
288+
// snippet if prefix with parent suffix will always be followed by ':'.
289+
//
290+
// Currently snippets are passed to child only for TAG
291+
// expressions which has ':' at the center.
292+
//
293+
// Example child data with parent snippet: <PARENT_SNIPPET>:<DATA>
294+
if (!info.snippet && info.parentSnippet && info.data?.startsWith(`${info.parentSnippet}:`)) {
295+
info.data = info.data.substr(info.parentSnippet.length + 1)
275296
info.snippet = info.parentSnippet
276297
}
277298

@@ -375,11 +396,7 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
375396
line: {
376397
stroke: edgeColor,
377398
strokeWidth: getEdgeSize(itemRecords),
378-
targetMarker: {
379-
name: 'block',
380-
fill: edgeColor,
381-
stroke: edgeColor,
382-
},
399+
targetMarker: null,
383400
},
384401
},
385402
})
@@ -462,7 +479,7 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
462479
name: 'Zoom In',
463480
onClick: () => {
464481
setTimeout(() => document.addEventListener('mouseup', mouseUpHandler), 100)
465-
core?.zoom(0.5)
482+
core && Math.floor(core.zoom()) <= 3 && core?.zoom(0.5)
466483
core?.resize(undefined, core?.getContentBBox().height + 50)
467484
},
468485
icon: 'magnifyWithPlus'
@@ -471,7 +488,11 @@ function ExplainDraw({data, type, module, profilingTime}: {data: any, type: Core
471488
name: 'Zoom Out',
472489
onClick: () => {
473490
setTimeout(() => document.addEventListener('mouseup', mouseUpHandler), 100)
474-
core && Math.floor(core.zoom()) <= 0.5 ? core?.zoom(0) : core?.zoom(-0.5)
491+
if (Math.floor(core?.zoom() || 0) <= 0.5) {
492+
core?.centerContent()
493+
} else {
494+
core?.zoom(-0.5)
495+
}
475496
core?.resize(undefined, core?.getContentBBox().height + 50)
476497
},
477498
icon: 'magnifyWithMinus'

redisinsight/ui/src/packages/ri-explain/src/Node.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export function ExplainNode(props: INodeProps) {
3131
<div className="InfoData">
3232
<EuiToolTip delay='long' content={infoData}><span>{infoData}</span></EuiToolTip>
3333
</div>
34-
{subType && [EntityType.GEO, EntityType.NUMERIC, EntityType.TEXT, EntityType.TAG, EntityType.FUZZY].includes(subType) && <div className="Type">{subType}</div> }
34+
{subType && [EntityType.GEO, EntityType.NUMERIC, EntityType.TEXT, EntityType.TAG, EntityType.FUZZY, EntityType.WILDCARD, EntityType.PREFIX, EntityType.IDS, EntityType.LEXRANGE, EntityType.NUMBER].includes(subType) && <div className="Type">{subType}</div> }
3535
</div>
3636
</div>
3737
{

0 commit comments

Comments
 (0)