Skip to content

Commit a2ea9ec

Browse files
authored
Merge pull request #380 from RedisInsight/feature/bugfix_wb
[bugfix] - cypher, wb, enablement area
2 parents b5d20b4 + e4e5f13 commit a2ea9ec

File tree

7 files changed

+88
-44
lines changed

7 files changed

+88
-44
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const DedicatedEditor = (props: Props) => {
123123
// https://github.com/microsoft/monaco-editor/issues/2756
124124
contribution = editor.getContribution<ISnippetController>('snippetController2')
125125

126-
editor.focus()
126+
setTimeout(() => editor.focus(), 0)
127127

128128
editor.onKeyDown(onKeyDownMonaco)
129129

@@ -183,7 +183,7 @@ const DedicatedEditor = (props: Props) => {
183183
x: 17,
184184
y: 80,
185185
width,
186-
height: 240
186+
height: 176
187187
}}
188188
className={styles.rnd}
189189
dragHandleClassName="draggable-area"

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.rnd {
2-
position: fixed;
2+
position: fixed !important;
33
z-index: 100;
44
}
55
.container {
@@ -34,7 +34,6 @@
3434
.input {
3535
height: calc(100% - 46px);
3636
width: 100%;
37-
background-color: var(--rsInputColor);
3837
}
3938

4039
#script {

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

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ export interface Props {
5050
}
5151

5252
const SYNTAX_CONTEXT_ID = 'syntaxWidgetContext'
53+
const SYNTAX_WIDGET_ID = 'syntax.content.widget'
54+
5355
const argInQuotesRegExp = /^['"](.|[\r\n])*['"]$/
56+
const aroundQuotesRegExp = /(^["']|["']$)/g
57+
5458
let decorations: string[] = []
5559
let execHistoryPos: number = 0
5660
let execHistory: CommandExecutionUI[] = []
@@ -75,14 +79,15 @@ const Query = (props: Props) => {
7579
let disposeCompletionItemProvider = () => {}
7680
let disposeSignatureHelpProvider = () => {}
7781

78-
useEffect(() =>
79-
// componentWillUnmount
80-
() => {
82+
useEffect(() => {
83+
// componentWillUnmount
84+
return () => {
8185
contribution?.dispose?.()
8286
disposeCompletionItemProvider()
8387
disposeSignatureHelpProvider()
84-
},
85-
[])
88+
}
89+
}, [])
90+
8691

8792
useEffect(() => {
8893
// HACK: The Monaco editor memoize the state and ignores updates to it
@@ -116,6 +121,23 @@ const Query = (props: Props) => {
116121
isDedicatedEditorOpenRef.current = isDedicatedEditorOpen
117122
}, [isDedicatedEditorOpen])
118123

124+
const triggerUpdateCursorPosition = (editor: monacoEditor.editor.IStandaloneCodeEditor) => {
125+
const position = editor.getPosition()
126+
isDedicatedEditorOpenRef.current = false
127+
editor.trigger('mouse', '_moveTo', { position: { lineNumber: 1, column: 1 }})
128+
editor.trigger('mouse', '_moveTo', { position })
129+
editor.focus()
130+
}
131+
132+
const onPressWidget = () => {
133+
if (!monacoObjects.current) return
134+
const { editor } = monacoObjects?.current
135+
136+
setIsDedicatedEditorOpen(true)
137+
editor.updateOptions({ readOnly: true })
138+
hideSyntaxWidget(editor)
139+
}
140+
119141
const onChange = (value: string = '') => {
120142
setQuery(value)
121143

@@ -151,7 +173,7 @@ const Query = (props: Props) => {
151173
}
152174

153175
const onTriggerContentWidget = (position: Nullable<monacoEditor.Position>, language: string = ''): monaco.editor.IContentWidget => ({
154-
getId: () => 'syntax.content.widget',
176+
getId: () => SYNTAX_WIDGET_ID,
155177
getDomNode: () => createSyntaxWidget(`Use ${language} Editor`, 'Shift+Space'),
156178
getPosition: () => ({
157179
position,
@@ -166,8 +188,12 @@ const Query = (props: Props) => {
166188
const { editor } = monacoObjects?.current
167189

168190
const position = editor.getPosition()
169-
// @ts-ignore
170-
if (position?.lineNumber !== 1 || editor.getContribution('editor.contrib.suggestController')?.model?.state) return
191+
if (
192+
position?.column !== 1 ||
193+
position?.lineNumber !== 1 ||
194+
// @ts-ignore
195+
editor.getContribution('editor.contrib.suggestController')?.model?.state
196+
) return
171197

172198
if (execHistory[execHistoryPos]) {
173199
const command = execHistory[execHistoryPos].command || ''
@@ -230,10 +256,6 @@ const Query = (props: Props) => {
230256

231257
const queryArg = command.args[argIndex]
232258
const argDSL = command.info?.arguments?.[argIndex]?.dsl || ''
233-
if (!argIndex) {
234-
isWidgetEscaped.current = false
235-
return
236-
}
237259

238260
if (queryArgIndex === argIndex && argInQuotesRegExp.test(queryArg)) {
239261
if (isWidgetEscaped.current) return
@@ -281,35 +303,35 @@ const Query = (props: Props) => {
281303
const { editor } = monacoObjects?.current
282304

283305
editor.updateOptions({ readOnly: false })
306+
triggerUpdateCursorPosition(editor)
284307
}
285308

286309
const updateArgFromDedicatedEditor = (value: string = '') => {
287-
if (syntaxCommand.current) {
288-
if (!monacoObjects.current) return
289-
const { editor } = monacoObjects?.current
310+
if (!syntaxCommand.current || !monacoObjects.current) return
311+
const { editor } = monacoObjects?.current
290312

291-
const model = editor.getModel()
292-
if (!model) return
313+
const model = editor.getModel()
314+
if (!model) return
293315

294-
const wrapQuote = syntaxCommand.current.argToReplace[0]
295-
const replaceCommand = syntaxCommand.current.fullQuery.replace(
296-
syntaxCommand.current.argToReplace,
297-
`${wrapQuote}${value}${wrapQuote}`
298-
)
299-
editor.updateOptions({ readOnly: false })
300-
editor.executeEdits(null, [
301-
{
302-
range: new monaco.Range(
303-
syntaxCommand.current.commandPosition.startLine,
304-
0,
305-
syntaxCommand.current.commandPosition.endLine,
306-
model.getLineLength(syntaxCommand.current.commandPosition.endLine) + 1
307-
),
308-
text: replaceCommand
309-
}
310-
])
311-
setIsDedicatedEditorOpen(false)
312-
}
316+
const wrapQuote = syntaxCommand.current.argToReplace[0]
317+
const replaceCommand = syntaxCommand.current.fullQuery.replace(
318+
syntaxCommand.current.argToReplace,
319+
`${wrapQuote}${value}${wrapQuote}`
320+
)
321+
editor.updateOptions({ readOnly: false })
322+
editor.executeEdits(null, [
323+
{
324+
range: new monaco.Range(
325+
syntaxCommand.current.commandPosition.startLine,
326+
0,
327+
syntaxCommand.current.commandPosition.endLine,
328+
model.getLineLength(syntaxCommand.current.commandPosition.endLine) + 1
329+
),
330+
text: replaceCommand
331+
}
332+
])
333+
setIsDedicatedEditorOpen(false)
334+
triggerUpdateCursorPosition(editor)
313335
}
314336

315337
const editorDidMount = (
@@ -335,11 +357,15 @@ const Query = (props: Props) => {
335357
)
336358

337359
editor.addCommand(monaco.KeyMod.Shift | monaco.KeyCode.Space, () => {
338-
setIsDedicatedEditorOpen(true)
339-
editor.updateOptions({ readOnly: true })
340-
hideSyntaxWidget(editor)
360+
onPressWidget()
341361
}, SYNTAX_CONTEXT_ID)
342362

363+
editor.onMouseDown((e: monaco.editor.IEditorMouseEvent) => {
364+
if (e.target.detail === SYNTAX_WIDGET_ID) {
365+
onPressWidget()
366+
}
367+
})
368+
343369
editor.addCommand(monaco.KeyCode.Escape, () => {
344370
hideSyntaxWidget(editor)
345371
isWidgetEscaped.current = true
@@ -431,7 +457,7 @@ const Query = (props: Props) => {
431457
{isDedicatedEditorOpen && (
432458
<DedicatedEditor
433459
lang={syntaxCommand.current.lang}
434-
value={selectedArg.current.replace(/(^["']|["']$)/g, '')}
460+
value={selectedArg.current.replace(aroundQuotesRegExp, '')}
435461
onSubmit={updateArgFromDedicatedEditor}
436462
onCancel={onCancelDedicatedEditor}
437463
width={input?.current?.scrollWidth || 300}

redisinsight/ui/src/pages/workbench/components/enablement-area/EnablementArea/utils/formatter/MarkdownToJsxString.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { visit } from 'unist-util-visit'
77

88
import { rehypeLinks } from '../rehypeLinks'
99
import { remarkRedisCode } from '../remarkRedisCode'
10+
import { remarkImage } from '../remarkImage'
1011
import { IFormatter, IFormatterConfig } from './formatter.interfaces'
1112

1213
class MarkdownToJsxString implements IFormatter {
@@ -16,6 +17,7 @@ class MarkdownToJsxString implements IFormatter {
1617
.use(remarkParse)
1718
.use(remarkGfm) // support GitHub Flavored Markdown
1819
.use(remarkRedisCode) // Add custom component for Redis code block
20+
.use(remarkImage) // Add custom component for Redis code block
1921
.use(remarkRehype, { allowDangerousHtml: true }) // Pass raw HTML strings through.
2022
.use(rehypeLinks, config ? { history: config.history } : undefined) // Customise links
2123
.use(MarkdownToJsxString.rehypeWrapSymbols) // Wrap special symbols inside curly braces for JSX parse
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { visit } from 'unist-util-visit'
2+
import { IS_ABSOLUTE_PATH } from 'uiSrc/constants/regex'
3+
import { RESOURCES_BASE_URL } from 'uiSrc/services/resourcesService'
4+
5+
export const remarkImage = (): (tree: Node) => void => (tree: any) => {
6+
// Find img node in syntax tree
7+
visit(tree, 'image', (node) => {
8+
node.url = IS_ABSOLUTE_PATH.test(node.url || '') ? node.url : `${RESOURCES_BASE_URL}${node.url.replace(/^\//, '')}`
9+
})
10+
}

redisinsight/ui/src/pages/workbench/components/enablement-area/styles.module.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@
3333
height: 0;
3434
}
3535
}
36+
37+
:global {
38+
img {
39+
max-width: 100%;
40+
}
41+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
height: 30px;
5757
padding: 5px;
5858
font-size: 12px;
59+
cursor: pointer;
5960

6061
&__title {
6162
color: var(--euiTextSubduedColor);

0 commit comments

Comments
 (0)