Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { useContext, useEffect, useMemo, useRef, useState } from 'react'
import { useDispatch, useSelector } from 'react-redux'
import { compact, first, isFinite } from 'lodash'
import { compact, first } from 'lodash'
import cx from 'classnames'
import MonacoEditor, { monaco as monacoEditor } from 'react-monaco-editor'
import { useParams } from 'react-router-dom'

import { DSLNaming, ICommandTokenType, IRedisCommand, MonacoLanguage, Theme, } from 'uiSrc/constants'
import { DSLNaming, IRedisCommand, MonacoLanguage, Theme, } from 'uiSrc/constants'
import {
actionTriggerParameterHints,
createSyntaxWidget,
Expand All @@ -28,14 +28,14 @@ import { stopProcessing, workbenchResultsSelector } from 'uiSrc/slices/workbench
import DedicatedEditor from 'uiSrc/components/monaco-editor/components/dedicated-editor'
import { QueryActions, QueryTutorials } from 'uiSrc/components/query'

import { addOwnTokenToArgs, findCurrentArgument, } from 'uiSrc/pages/workbench/utils/query'
import { getRange, getRediSearchSignutureProvider, } from 'uiSrc/pages/workbench/utils/monaco'
import { CursorContext } from 'uiSrc/pages/workbench/types'
import { asSuggestionsRef, getCommandsSuggestions, isIndexComplete } from 'uiSrc/pages/workbench/utils/suggestions'
import { COMMANDS_TO_GET_INDEX_INFO, COMPOSITE_ARGS, EmptySuggestionsIds, } from 'uiSrc/pages/workbench/constants'
import { useDebouncedEffect } from 'uiSrc/services'
import { fetchRedisearchInfoAction } from 'uiSrc/slices/browser/redisearch'
import { findSuggestionsByArg } from 'uiSrc/pages/workbench/utils/searchSuggestions'
import { findSuggestionsByQueryArgs } from 'uiSrc/pages/workbench/utils/query'
import {
argInQuotesRegExp,
aroundQuotesRegExp,
Expand Down Expand Up @@ -104,12 +104,6 @@ const Query = (props: Props) => {
const { theme } = useContext(ThemeContext)
const monacoObjects = useRef<Nullable<IEditorMount>>(null)

// TODO: need refactor to avoid this
const REDIS_COMMANDS = useMemo(
() => commands.map((command) => ({ ...addOwnTokenToArgs(command.name!, command) })),
[commands]
)

const compositeTokens = useMemo(() =>
commands
.filter((command) => command.token && command.token.includes(' '))
Expand Down Expand Up @@ -435,12 +429,7 @@ const Query = (props: Props) => {
}

const [beforeOffsetArgs, [currentOffsetArg]] = command.args
const foundArg = findCurrentArgument([{
...command.info,
type: ICommandTokenType.Block,
token: command.name,
arguments: command.info?.arguments
}], beforeOffsetArgs)
const foundArg = findSuggestionsByQueryArgs([{ ...command.info, token: command.name }], beforeOffsetArgs)

const DSL = foundArg?.stopArg?.dsl
if (DSL && argInQuotesRegExp.test(currentOffsetArg)) {
Expand Down Expand Up @@ -575,7 +564,7 @@ const Query = (props: Props) => {

const cursorContext: CursorContext = { ...cursor, currentOffsetArg, offset: command.commandCursorPosition, range }
const { suggestions, helpWidget } = findSuggestionsByArg(
REDIS_COMMANDS,
commands,
command,
cursorContext,
{ fields: attributesRef.current, indexes: indexesRef.current },
Expand Down
10 changes: 8 additions & 2 deletions redisinsight/ui/src/pages/workbench/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ export enum ArgName {
}

export interface FoundCommandArgument {
isComplete: boolean
isComplete?: boolean
stopArg: Maybe<IRedisCommand>
isBlocked: boolean
append: Maybe<Array<IRedisCommandTree[]>>
parent: Maybe<IRedisCommand>
token: Maybe<IRedisCommand>
token?: Maybe<IRedisCommand>
}

export interface CursorContext {
Expand All @@ -26,3 +26,9 @@ export interface CursorContext {
argRightOffset: number
range: monacoEditor.IRange
}

export interface BlockTokensTree {
queryArgs: string[]
command?: IRedisCommand
parent?: BlockTokensTree
}
19 changes: 7 additions & 12 deletions redisinsight/ui/src/pages/workbench/utils/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { ICommandTokenType, IRedisCommand } from 'uiSrc/constants'
import { Maybe } from 'uiSrc/utils'

export const isStringsEqual = (str1?: string, str2?: string) => str1?.toLowerCase() === str2?.toLowerCase()
export const isPureTokenType = (command?: IRedisCommand) => command?.type === ICommandTokenType.PureToken
export const isBlockType = (command?: IRedisCommand) => command?.type === ICommandTokenType.Block
export const isOneOfType = (command?: IRedisCommand) => command?.type === ICommandTokenType.OneOf

export const isTokenEqualsArg = (token: IRedisCommand, arg: string) => {
if (token.type === ICommandTokenType.OneOf) {
return token.arguments
?.some((oneOfArg: IRedisCommand) => isStringsEqual(oneOfArg?.token, arg))
}
if (isStringsEqual(token.token, arg)) return true
if (token.type === ICommandTokenType.Block) return isStringsEqual(token.arguments?.[0]?.token, arg)
return false
}
export const isPureToken = (command?: IRedisCommand, arg?: string) =>
isPureTokenType(command) && isStringsEqual(arg, command?.token)

export const findArgByToken = (list: IRedisCommand[], arg: string): Maybe<IRedisCommand> =>
list.find((command) => isTokenEqualsArg(command, arg))
export const isArgInOneOf = (command?: IRedisCommand, arg?: string) =>
command?.arguments?.some(({ token }) => isStringsEqual(arg, token))
Loading
Loading