Skip to content

Commit 13854db

Browse files
authored
Merge pull request #77 from RedisInsight/feature/RI-2067_wb-view-select
#RI-2067 - differentiate default and custom plugins
2 parents 090f416 + a96efae commit 13854db

File tree

16 files changed

+167
-87
lines changed

16 files changed

+167
-87
lines changed
Lines changed: 3 additions & 16 deletions
Loading
Lines changed: 3 additions & 16 deletions
Loading
Lines changed: 5 additions & 10 deletions
Loading
Lines changed: 5 additions & 10 deletions
Loading
Lines changed: 6 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Loading

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

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import {
1313
} from '@elastic/eui'
1414
import { format } from 'date-fns'
1515
import { useParams } from 'react-router-dom'
16+
import { findIndex } from 'lodash'
1617

1718
import { Theme } from 'uiSrc/constants'
1819
import { getVisualizationsByCommand, truncateText, urlForAsset } from 'uiSrc/utils'
1920
import { ThemeContext } from 'uiSrc/contexts/themeContext'
2021
import { appPluginsSelector } from 'uiSrc/slices/app/plugins'
2122
import { sendEventTelemetry, TelemetryEvent } from 'uiSrc/telemetry'
2223
import { getViewTypeOptions, WBQueryType } from 'uiSrc/pages/workbench/constants'
24+
import { IPluginVisualization } from 'uiSrc/slices/interfaces'
2325

2426
import DefaultPluginIconDark from 'uiSrc/assets/img/workbench/default_view_dark.svg'
2527
import DefaultPluginIconLight from 'uiSrc/assets/img/workbench/default_view_light.svg'
@@ -116,7 +118,7 @@ const QueryCardHeader = (props: Props) => {
116118
) || ''
117119

118120
const pluginsOptions = getVisualizationsByCommand(query, visualizations)
119-
.map((visualization: any) => ({
121+
.map((visualization: IPluginVisualization) => ({
120122
id: visualization.uniqId,
121123
value: WBQueryType.Plugin,
122124
text: visualization.name,
@@ -126,11 +128,12 @@ const QueryCardHeader = (props: Props) => {
126128
iconLight: (visualization.plugin.internal && visualization.iconLight)
127129
? urlForAsset(visualization.plugin.baseUrl, visualization.iconLight)
128130
: DefaultPluginIconLight,
131+
internal: visualization.plugin.internal
129132
}))
130133

131-
const options: EuiSuperSelectOption<string>[] = getViewTypeOptions()
134+
const options: any[] = getViewTypeOptions()
132135
options.push(...pluginsOptions)
133-
const modifiedOptions = options.map((item) => {
136+
const modifiedOptions: EuiSuperSelectOption<any>[] = options.map((item) => {
134137
const { value, id, text, iconDark, iconLight } = item
135138
return {
136139
value: id ?? value,
@@ -142,17 +145,35 @@ const QueryCardHeader = (props: Props) => {
142145
anchorClassName={styles.tooltipIcon}
143146
>
144147
<EuiIcon
148+
className={styles.iconDropdownOption}
145149
type={theme === Theme.Dark ? iconDark : iconLight}
146150
data-testid={`view-type-selected-${value}-${id}`}
147151
/>
148152
</EuiToolTip>
149153
</div>
150154
),
151-
dropdownDisplay: truncateText(text, 20),
155+
dropdownDisplay: (
156+
<div className={cx(styles.dropdownOption)}>
157+
<EuiIcon
158+
className={styles.iconDropdownOption}
159+
type={theme === Theme.Dark ? iconDark : iconLight}
160+
/>
161+
<span>{truncateText(text, 20)}</span>
162+
</div>
163+
),
152164
'data-test-subj': `view-type-option-${value}-${id}`,
153165
}
154166
})
155167

168+
const indexForSeparator = findIndex(pluginsOptions, (option) => !option.internal)
169+
if (indexForSeparator > -1) {
170+
modifiedOptions.splice(indexForSeparator + 1, 0, {
171+
value: '',
172+
disabled: true,
173+
inputDisplay: (<span className={styles.separator} />)
174+
})
175+
}
176+
156177
return (
157178
<div
158179
onClick={toggleOpen}
@@ -194,14 +215,18 @@ const QueryCardHeader = (props: Props) => {
194215
onClick={onDropDownViewClick}
195216
>
196217
{isOpen && options.length > 1 && (
197-
<EuiSuperSelect
198-
options={modifiedOptions}
199-
itemClassName={cx('withColorDefinition', styles.changeViewItem)}
200-
className={cx(styles.changeView)}
201-
valueOfSelected={selectedValue}
202-
onChange={(value: string) => onChangeView(value)}
203-
data-testid="select-view-type"
204-
/>
218+
<div className={styles.dropdownWrapper}>
219+
<div className={styles.dropdown}>
220+
<EuiSuperSelect
221+
options={modifiedOptions}
222+
itemClassName={cx(styles.changeViewItem)}
223+
className={cx(styles.changeView)}
224+
valueOfSelected={selectedValue}
225+
onChange={(value: string) => onChangeView(value)}
226+
data-testid="select-view-type"
227+
/>
228+
</div>
229+
</div>
205230
)}
206231
</EuiFlexItem>
207232
<EuiFlexItem grow={false} className={styles.buttonIcon} onClick={onDropDownViewClick}>

redisinsight/ui/src/components/query-card/QueryCardHeader/styles.module.scss

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $marginIcon: 12px;
8181
.timeText, .summaryText {
8282
font: normal normal normal 12px/16px Graphik, sans-serif;
8383
letter-spacing: -0.12px;
84-
color: var(--euiTextSubduedColor) !important;
84+
color: var(--euiColorMediumShade) !important;
8585
min-width: 104px;
8686
text-align: left;
8787
}
@@ -105,6 +105,59 @@ $marginIcon: 12px;
105105
flex: 1;
106106
}
107107

108+
.dropdownWrapper {
109+
position: relative;
110+
height: 40px;
111+
}
112+
113+
.dropdown {
114+
width: 168px;
115+
position: absolute;
116+
z-index: 1;
117+
118+
// move a little bit left to align with dropdown options icons
119+
left: -21px;
120+
121+
:global {
122+
.euiFormControlLayout__childrenWrapper {
123+
width: 46px;
124+
position: relative;
125+
// move right to align self
126+
left: 21px;
127+
}
128+
}
129+
}
130+
131+
.dropdownOption {
132+
display: flex;
133+
align-items: center;
134+
position: relative;
135+
padding: 3px 0 3px 8px;
136+
137+
span {
138+
margin-left: 10px;
139+
line-height: 20px;
140+
overflow: hidden;
141+
max-width: 100px;
142+
}
143+
}
144+
145+
.iconDropdownOption {
146+
width: 20px !important;
147+
height: 20px !important;
148+
}
149+
150+
.dropdownOptionSeparator:after {
151+
content: '';
152+
display: block;
153+
height: 0;
154+
width: 100%;
155+
border-bottom: 1px solid var(--separatorDropdownColor);
156+
opacity: 0.5;
157+
position: absolute;
158+
bottom: -8.5px;
159+
}
160+
108161
.changeView:global(.euiSuperSelectControl) {
109162
border: none !important;
110163
background-color: inherit !important;
@@ -123,11 +176,41 @@ $marginIcon: 12px;
123176

124177
.changeViewItem {
125178
overflow-wrap: break-word;
179+
:global {
180+
.euiContextMenuItem__text {
181+
overflow: visible;
182+
}
183+
.euiContextMenu__icon {
184+
margin-right: 0;
185+
}
186+
}
187+
&:global(.euiContextMenuItem-isDisabled) {
188+
padding-top: 0;
189+
padding-bottom: 0;
190+
min-height: 12px !important;
191+
cursor: auto !important;
192+
&:hover {
193+
background: transparent !important;
194+
}
195+
:global(.euiContextMenu__icon) {
196+
height: 0;
197+
}
198+
}
199+
}
200+
201+
.separator {
202+
height: 1px;
203+
width: 100%;
204+
background: var(--separatorDropdownColor);
205+
display: block;
206+
opacity: 0.5;
126207
}
127208

128209
.buttonIcon {
129210
padding: 0 4px;
130211
width: 32px;
212+
position: relative;
213+
z-index: 2;
131214
}
132215

133216
.container :global(.euiFlexItem).viewTypeIcon {
Lines changed: 5 additions & 10 deletions
Loading
Lines changed: 5 additions & 10 deletions
Loading

0 commit comments

Comments
 (0)