Skip to content

Commit 55937b0

Browse files
authored
Merge pull request #455 from RedisInsight/feature/RI-2568_dedicated-editor-position
#RI-2568 - improve dedicated editor positioning
2 parents 1112d90 + 1ac296b commit 55937b0

File tree

5 files changed

+83
-18
lines changed

5 files changed

+83
-18
lines changed

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

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,14 @@ export interface Props {
3434
onSubmit: (query?: string) => void
3535
onCancel: () => void
3636
onKeyDown?: (e: React.KeyboardEvent, script: string) => void
37-
width: number
37+
height: number
38+
initialHeight: number
3839
}
3940

41+
// paddings of main editor
42+
const WRAPPER_PADDINGS_HEIGHT = 18
43+
const BOTTOM_INDENT_PADDING = 6
44+
4045
const langs: MonacoSyntaxLang = {
4146
[DSL.cypher]: {
4247
name: DSLNaming[DSL.cypher],
@@ -50,12 +55,13 @@ let decorations: string[] = []
5055
const notCommandRegEx = /^\s|\/\//
5156

5257
const DedicatedEditor = (props: Props) => {
53-
const { width, query = '', lang, onCancel, onSubmit } = props
58+
const { height, initialHeight, query = '', lang, onCancel, onSubmit } = props
5459
const selectedLang = langs[lang]
5560
let contribution: Nullable<ISnippetController> = null
5661

5762
const [value, setValue] = useState<string>(query)
5863
const monacoObjects = useRef<Nullable<IEditorMount>>(null)
64+
const rndRef = useRef<Nullable<any>>(null)
5965
let disposeCompletionItemProvider = () => {}
6066

6167
useEffect(() =>
@@ -66,6 +72,16 @@ const DedicatedEditor = (props: Props) => {
6672
},
6773
[])
6874

75+
useEffect(() => {
76+
if (height === 0) return
77+
78+
const rndHeight = rndRef?.current.resizableElement.current.offsetHeight || 0
79+
const rndTop = rndRef?.current.draggable.state.y
80+
if (height < rndTop + rndHeight + WRAPPER_PADDINGS_HEIGHT) {
81+
rndRef?.current.updatePosition({ x: 0, y: height - rndHeight - WRAPPER_PADDINGS_HEIGHT })
82+
}
83+
}, [height])
84+
6985
useEffect(() => {
7086
if (!monacoObjects.current) return
7187
const commands = value.split('\n')
@@ -182,14 +198,28 @@ const DedicatedEditor = (props: Props) => {
182198

183199
return (
184200
<Rnd
201+
ref={rndRef}
185202
default={{
186-
x: 17,
187-
y: 80,
188-
width,
189-
height: 176
203+
x: 0,
204+
y: initialHeight * 0.4 - BOTTOM_INDENT_PADDING,
205+
width: '100%',
206+
height: '60%'
190207
}}
191-
className={styles.rnd}
208+
minHeight="80px"
209+
enableResizing={{
210+
top: true,
211+
right: false,
212+
bottom: true,
213+
left: false,
214+
topRight: false,
215+
bottomRight: false,
216+
bottomLeft: false,
217+
topLeft: false
218+
}}
219+
dragAxis="y"
220+
bounds=".editorBounder"
192221
dragHandleClassName="draggable-area"
222+
className={styles.rnd}
193223
>
194224
<div className={styles.container} onKeyDown={handleKeyDown} role="textbox" tabIndex={0}>
195225
<div className="draggable-area" />

redisinsight/ui/src/components/query/DedicatedEditor/styles.module.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.rnd {
2-
position: fixed !important;
2+
width: 100% !important;
33
z-index: 100;
44
}
55
.container {

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useContext, useEffect, useRef, useState } from 'react'
2+
import AutoSizer from 'react-virtualized-auto-sizer'
23
import { useSelector } from 'react-redux'
34
import { compact, findIndex } from 'lodash'
45
import cx from 'classnames'
@@ -416,8 +417,13 @@ const Query = (props: Props) => {
416417
}
417418

418419
return (
419-
<>
420-
<div className={styles.container} onKeyDown={handleKeyDown} role="textbox" tabIndex={0}>
420+
<div className={styles.wrapper}>
421+
<div
422+
className={cx(styles.container, { [styles.disabled]: isDedicatedEditorOpen })}
423+
onKeyDown={handleKeyDown}
424+
role="textbox"
425+
tabIndex={0}
426+
>
421427
<div className={styles.input} data-testid="query-input-container" ref={input}>
422428
<MonacoEditor
423429
language={MonacoLanguage.Redis}
@@ -455,15 +461,22 @@ const Query = (props: Props) => {
455461
</div>
456462
</div>
457463
{isDedicatedEditorOpen && (
458-
<DedicatedEditor
459-
lang={syntaxCommand.current.lang}
460-
query={selectedArg.current.replace(aroundQuotesRegExp, '')}
461-
onSubmit={updateArgFromDedicatedEditor}
462-
onCancel={onCancelDedicatedEditor}
463-
width={input?.current?.scrollWidth || 300}
464-
/>
464+
<AutoSizer>
465+
{({ height }) => (
466+
<div className="editorBounder">
467+
<DedicatedEditor
468+
initialHeight={input?.current?.scrollHeight || 0}
469+
height={height}
470+
lang={syntaxCommand.current.lang}
471+
query={selectedArg.current.replace(aroundQuotesRegExp, '')}
472+
onSubmit={updateArgFromDedicatedEditor}
473+
onCancel={onCancelDedicatedEditor}
474+
/>
475+
</div>
476+
)}
477+
</AutoSizer>
465478
)}
466-
</>
479+
</div>
467480
)
468481
}
469482

redisinsight/ui/src/components/query/Query/styles.module.scss

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
:global {
2+
.editorBounder {
3+
position: absolute;
4+
top: 12px;
5+
bottom: 6px;
6+
left: 18px;
7+
right: 46px;
8+
}
9+
}
10+
.wrapper {
11+
position: relative;
12+
height: 100%;
13+
}
114
.container {
215
display: flex;
316
padding: 8px 0 8px 16px;
@@ -11,6 +24,10 @@
1124
border: 1px solid var(--euiColorLightShade);
1225
}
1326

27+
.disabled {
28+
opacity: 0.8;
29+
}
30+
1431
.containerPlaceholder {
1532
display: flex;
1633
padding: 8px 16px 8px 16px;

redisinsight/ui/src/styles/base/_monaco.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@
5858
font-size: 12px;
5959
cursor: pointer;
6060

61+
&:hover {
62+
background: var(--hoverInListColorDarken);
63+
border-color: var(--hoverInListColorLight);
64+
}
65+
6166
&__title {
6267
color: var(--euiTextSubduedColor);
6368
}

0 commit comments

Comments
 (0)