From a0cdaefea8fc5a407adc5c9d83190f48953abc84 Mon Sep 17 00:00:00 2001 From: Artyom Podymov Date: Fri, 26 Nov 2021 19:48:05 +0300 Subject: [PATCH] #RI-2065 - handle case when complexity is array of strings --- redisinsight/ui/src/utils/commands.ts | 6 ++++-- redisinsight/ui/src/utils/tests/commands.spec.ts | 8 ++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/redisinsight/ui/src/utils/commands.ts b/redisinsight/ui/src/utils/commands.ts index 0a9006af89..30a57a1706 100644 --- a/redisinsight/ui/src/utils/commands.ts +++ b/redisinsight/ui/src/utils/commands.ts @@ -1,8 +1,10 @@ import { flatten, isArray, isEmpty, reject } from 'lodash' import { CommandArgsType, CommandGroup, ICommandArg, ICommandArgGenerated } from 'uiSrc/constants' -export const getComplexityShortNotation = (text: string) => - (text.endsWith(')') && text.startsWith('O') ? text : '') +export const getComplexityShortNotation = (complexity: string[] | string): string => { + const value = isArray(complexity) ? complexity.join(' ') : complexity + return value.endsWith(')') && value.startsWith('O') ? value : '' +} const generateArgName = ( arg: ICommandArg, diff --git a/redisinsight/ui/src/utils/tests/commands.spec.ts b/redisinsight/ui/src/utils/tests/commands.spec.ts index 1edcc51d1a..adfa774301 100644 --- a/redisinsight/ui/src/utils/tests/commands.spec.ts +++ b/redisinsight/ui/src/utils/tests/commands.spec.ts @@ -148,6 +148,14 @@ describe('getComplexityShortNotation', () => { } }) }) + it('handle case when complexity is array of strings', () => { + const result = getComplexityShortNotation([ + 'O(1) for each field/value pair added', + 'O(N) to add N field/value pairs when the command is called with multiple field/value pairs.' + ]) + + expect(result).toEqual('') + }) }) describe('generateArgs', () => {