Skip to content

Commit a903575

Browse files
Merge branch 'main' of https://github.com/RedisInsight/RedisInsight into bugfix/RI-3525_electron_styles
2 parents 04d5181 + fa0bc58 commit a903575

File tree

41 files changed

+434
-208
lines changed

Some content is hidden

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

41 files changed

+434
-208
lines changed
Lines changed: 9 additions & 0 deletions
Loading

redisinsight/ui/src/components/bottom-group-components/components/bottom-group-minimized/BottomGroupMinimized.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import cx from 'classnames'
33
import { EuiBadge, EuiFlexGroup, EuiFlexItem, EuiIcon } from '@elastic/eui'
44
import { useDispatch, useSelector } from 'react-redux'
55
import { useParams } from 'react-router-dom'
6+
import { EXTERNAL_LINKS } from 'uiSrc/constants/links'
67

78
import {
89
clearSearchingCommand,
@@ -14,6 +15,7 @@ import {
1415
} from 'uiSrc/slices/cli/cli-settings'
1516
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
1617
import { monitorSelector, toggleHideMonitor, toggleMonitor } from 'uiSrc/slices/cli/monitor'
18+
import SurveyIcon from 'uiSrc/assets/img/survey_icon.svg'
1719

1820
import styles from '../../styles.module.scss'
1921

@@ -67,6 +69,12 @@ const BottomGroupMinimized = () => {
6769
dispatch(toggleMonitor())
6870
}
6971

72+
const onClickSurvey = () => {
73+
sendEventTelemetry({
74+
event: TelemetryEvent.USER_SURVEY_LINK_CLICKED
75+
})
76+
}
77+
7078
return (
7179
<div className={styles.containerMinimized}>
7280
<EuiFlexGroup
@@ -117,6 +125,19 @@ const BottomGroupMinimized = () => {
117125
</EuiBadge>
118126
</EuiFlexItem>
119127
</EuiFlexGroup>
128+
<a
129+
className={styles.surveyLink}
130+
target="_blank"
131+
rel="noreferrer"
132+
href={EXTERNAL_LINKS.userSurvey}
133+
onClick={onClickSurvey}
134+
data-testid="user-survey-link"
135+
>
136+
<>
137+
<EuiIcon type={SurveyIcon} className={styles.surveyIcon} />
138+
<span>We need your opinion. Please take our survey.</span>
139+
</>
140+
</a>
120141
</div>
121142
)
122143
}

redisinsight/ui/src/components/bottom-group-components/styles.module.scss

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,31 @@
1111
}
1212

1313
.containerMinimized {
14+
display: flex;
15+
align-items: center;
1416
height: 26px;
1517
line-height: 26px;
1618
border: 1px solid var(--euiColorLightShade);
19+
20+
.surveyLink {
21+
display: flex;
22+
align-items: center;
23+
height: 100%;
24+
padding: 0 12px;
25+
color: var(--htmlColor) !important;
26+
font: normal normal normal 12px/18px Graphik, sans-serif;
27+
28+
&:hover {
29+
background-color: var(--euiColorSecondary);
30+
color: var(--euiColorPrimaryText) !important;
31+
}
32+
}
33+
34+
.surveyIcon {
35+
margin-right: 8px;
36+
width: 18px;
37+
height: 18px;
38+
}
1739
}
1840

1941
.componentBadgeItem {

redisinsight/ui/src/components/charts/donut-chart/DonutChart.tsx

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import cx from 'classnames'
22
import * as d3 from 'd3'
33
import { sumBy } from 'lodash'
4-
import React, { useEffect, useRef } from 'react'
5-
import { truncateNumberToRange } from 'uiSrc/utils'
4+
import React, { useEffect, useRef, useState } from 'react'
5+
import { flushSync } from 'react-dom'
6+
import { Nullable, truncateNumberToRange } from 'uiSrc/utils'
67
import { rgb, RGBColor } from 'uiSrc/utils/colors'
8+
import { getPercentage } from 'uiSrc/utils/numbers'
79

810
import styles from './styles.module.scss'
911

1012
export interface ChartData {
1113
value: number
1214
name: string
1315
color: RGBColor
16+
meta?: {
17+
[key: string]: any
18+
}
1419
}
1520

1621
interface IProps {
@@ -32,8 +37,9 @@ interface IProps {
3237
arcLabelValue?: string
3338
tooltip?: string
3439
}
35-
renderLabel?: (value: number) => string
36-
renderTooltip?: (value: number) => string
40+
renderLabel?: (data: ChartData) => string
41+
renderTooltip?: (data: ChartData) => React.ReactElement | string
42+
labelAs?: 'value' | 'percentage'
3743
}
3844

3945
const ANIMATION_DURATION_MS = 100
@@ -47,17 +53,20 @@ const DonutChart = (props: IProps) => {
4753
title,
4854
config,
4955
classNames,
56+
labelAs = 'value',
5057
renderLabel,
51-
renderTooltip = (v) => v,
58+
renderTooltip,
5259
} = props
5360

5461
const margin = config?.margin || 98
5562
const radius = config?.radius || (width / 2 - margin)
5663
const arcWidth = config?.arcWidth || 8
5764
const percentToShowLabel = config?.percentToShowLabel || 5
5865

66+
const [hoveredData, setHoveredData] = useState<Nullable<ChartData>>(null)
5967
const svgRef = useRef<SVGSVGElement>(null)
6068
const tooltipRef = useRef<HTMLDivElement>(null)
69+
const sum = sumBy(data, 'value')
6170

6271
const arc = d3.arc<d3.PieArcDatum<ChartData>>()
6372
.outerRadius(radius)
@@ -74,12 +83,20 @@ const DonutChart = (props: IProps) => {
7483
.duration(ANIMATION_DURATION_MS)
7584
.attr('d', arcHover)
7685

77-
if (tooltipRef.current) {
78-
tooltipRef.current.innerHTML = `${d.data.name}: ${renderTooltip(d.value)}`
79-
tooltipRef.current.style.visibility = 'visible'
80-
tooltipRef.current.style.top = `${e.pageY + 15}px`
81-
tooltipRef.current.style.left = `${e.pageX + 15}px`
86+
if (!tooltipRef.current) {
87+
return
8288
}
89+
90+
// calculate position after tooltip rendering (do update as synchronous operation)
91+
if (e.type === 'mouseenter') {
92+
flushSync(() => { setHoveredData(d.data) })
93+
}
94+
95+
tooltipRef.current.style.top = `${e.pageY + 15}px`
96+
tooltipRef.current.style.left = (window.innerWidth < (tooltipRef.current.scrollWidth + e.pageX + 20))
97+
? `${e.pageX - tooltipRef.current.scrollWidth - 15}px`
98+
: `${e.pageX + 15}px`
99+
tooltipRef.current.style.visibility = 'visible'
83100
}
84101

85102
const onMouseLeaveSlice = (e: MouseEvent) => {
@@ -91,6 +108,7 @@ const DonutChart = (props: IProps) => {
91108

92109
if (tooltipRef.current) {
93110
tooltipRef.current.style.visibility = 'hidden'
111+
setHoveredData(null)
94112
}
95113
}
96114

@@ -148,11 +166,26 @@ const DonutChart = (props: IProps) => {
148166
.on('mouseenter mousemove', onMouseEnterSlice)
149167
.on('mouseleave', onMouseLeaveSlice)
150168
.append('tspan')
151-
.text((d) => (isShowLabel(d) ? `: ${renderLabel ? renderLabel(d.value) : truncateNumberToRange(d.value)}` : ''))
169+
.text((d) => {
170+
if (!isShowLabel(d)) {
171+
return ''
172+
}
173+
174+
if (renderLabel) {
175+
return renderLabel(d.data)
176+
}
177+
178+
const separator = ': '
179+
if (labelAs === 'percentage') {
180+
return `${separator}${getPercentage(d.value, sum)}%`
181+
}
182+
183+
return `${separator}${truncateNumberToRange(d.value)}`
184+
})
152185
.attr('class', cx(styles.chartLabelValue, classNames?.arcLabelValue))
153186
}, [data])
154187

155-
if (!data.length || sumBy(data, 'value') === 0) {
188+
if (!data.length || sum === 0) {
156189
return null
157190
}
158191

@@ -163,7 +196,9 @@ const DonutChart = (props: IProps) => {
163196
className={cx(styles.tooltip, classNames?.tooltip)}
164197
data-testid="chart-value-tooltip"
165198
ref={tooltipRef}
166-
/>
199+
>
200+
{(renderTooltip && hoveredData) ? renderTooltip(hoveredData) : (hoveredData?.value || '')}
201+
</div>
167202
{title && (
168203
<div className={styles.innerTextContainer}>
169204
{title}

redisinsight/ui/src/components/charts/donut-chart/styles.module.scss

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

1212
.tooltip {
1313
position: fixed;
14-
background: var(--separatorColor);
14+
background: var(--euiTooltipBackgroundColor);
1515
color: var(--htmlColor);
1616
padding: 10px;
1717
visibility: hidden;
1818
border-radius: 4px;
19-
z-index: 5;
19+
z-index: 100;
2020
}
2121

2222
.chartLabel {

redisinsight/ui/src/components/navigation-menu/components/notifications-center/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
display: block;
168168
margin-right: 30px;
169169
margin-bottom: 12px;
170-
font: normal normal 500 18px/24px Graphik;
170+
font: normal normal 500 18px/24px Graphik, sans-serif;
171171
}
172172

173173
.notificationDate {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ const QueryCard = (props: Props) => {
8181
const [viewTypeSelected, setViewTypeSelected] = useState<WBQueryType>(queryType)
8282
const [summaryText, setSummaryText] = useState<string>('')
8383
const [selectedViewValue, setSelectedViewValue] = useState<string>(
84-
getDefaultPlugin(visualizations, command) || queryType
84+
getDefaultPlugin(visualizations, command || '') || queryType
8585
)
8686

8787
const dispatch = useDispatch()

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react'
22
import { instance, mock } from 'ts-mockito'
3+
import { EMPTY_COMMAND } from 'uiSrc/constants'
34
import { render } from 'uiSrc/utils/test-utils'
45
import QueryCardTooltip, { Props } from './QueryCardTooltip'
56

@@ -9,4 +10,12 @@ describe('QueryCardTooltip', () => {
910
it('should render', () => {
1011
expect(render(<QueryCardTooltip {...instance(mockedProps)} />)).toBeTruthy()
1112
})
13+
14+
it(`should show ${EMPTY_COMMAND} if command=null and summary=`, () => {
15+
const { queryByTestId } = render(
16+
<QueryCardTooltip {...instance(mockedProps)} query={null} summary={null} />
17+
)
18+
19+
expect(queryByTestId('query-card-tooltip-anchor')).toHaveTextContent(EMPTY_COMMAND)
20+
})
1221
})

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

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

6-
import { truncateText } from 'uiSrc/utils'
6+
import { Nullable, truncateText } from 'uiSrc/utils'
7+
import { EMPTY_COMMAND } from 'uiSrc/constants'
78
import styles from './styles.module.scss'
89

910
export interface Props {
10-
query: string
11-
summary?: string
11+
query: Nullable<string>
12+
summary?: Nullable<string>
1213
maxLinesNumber?: number
1314
}
1415

@@ -19,10 +20,9 @@ interface IQueryLine {
1920
}
2021

2122
const QueryCardTooltip = (props: Props) => {
22-
const { query = '', maxLinesNumber = 20, summary } = props
23+
const { query = '', maxLinesNumber = 20, summary = '' } = props
2324

24-
let queryLines: IQueryLine[] = query
25-
.split('\n')
25+
let queryLines: IQueryLine[] = (query || EMPTY_COMMAND).split('\n')
2626
.map((query: string, i) => ({
2727
value: truncateText(query, 497, '...'),
2828
index: i
@@ -56,7 +56,7 @@ const QueryCardTooltip = (props: Props) => {
5656
content={<>{contentItems}</>}
5757
position="bottom"
5858
>
59-
<span>{summary || query}</span>
59+
<span data-testid="query-card-tooltip-anchor">{summary || query || EMPTY_COMMAND}</span>
6060
</EuiToolTip>
6161
)
6262
}

redisinsight/ui/src/components/query/Query/Query.tsx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ const aroundQuotesRegExp = /(^["']|["']$)/g
6666
let decorations: string[] = []
6767
let execHistoryPos: number = 0
6868
let execHistory: CommandExecutionUI[] = []
69-
let toggleGroupMode: () => void = () => {}
7069

7170
const Query = (props: Props) => {
7271
const {
@@ -118,11 +117,6 @@ const Query = (props: Props) => {
118117
execHistoryPos = 0
119118
}, [execHistoryItems])
120119

121-
useEffect(() => {
122-
// HACK: The Monaco editor memoize the state and ignores updates to it
123-
toggleGroupMode = onChangeGroupMode
124-
}, [resultsMode])
125-
126120
useEffect(() => {
127121
if (!monacoObjects.current) return
128122
const commands = query.split('\n')
@@ -406,10 +400,6 @@ const Query = (props: Props) => {
406400
getMonacoAction(MonacoAction.Submit, (editor) => handleSubmit(editor.getValue()), monaco)
407401
)
408402

409-
editor.addAction(
410-
getMonacoAction(MonacoAction.ChangeGroupMode, () => toggleGroupMode(), monaco)
411-
)
412-
413403
editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Space, () => {
414404
onPressWidget()
415405
}, SYNTAX_CONTEXT_ID)
@@ -543,18 +533,7 @@ const Query = (props: Props) => {
543533
</EuiToolTip>
544534
<EuiToolTip
545535
position="left"
546-
content={
547-
KEYBOARD_SHORTCUTS?.workbench?.changeGroupMode && (
548-
<div style={{ display: 'flex', alignItems: 'baseline' }}>
549-
<EuiText className={styles.tooltipText} size="s">{`${KEYBOARD_SHORTCUTS.workbench.changeGroupMode?.label}:\u00A0\u00A0`}</EuiText>
550-
<KeyboardShortcut
551-
badgeTextClassName={styles.tooltipText}
552-
separator={KEYBOARD_SHORTCUTS?._separator}
553-
items={KEYBOARD_SHORTCUTS.workbench.changeGroupMode.keys}
554-
/>
555-
</div>
556-
)
557-
}
536+
content="Group Results"
558537
data-testid="run-query-tooltip"
559538
>
560539
<>

0 commit comments

Comments
 (0)