Skip to content

Commit 8d2b8b2

Browse files
author
Artem
committed
#RI-4384, #RI-4385 add backward compatibility so new helper will work for "main" commands only
1 parent e416675 commit 8d2b8b2

File tree

12 files changed

+365
-48
lines changed

12 files changed

+365
-48
lines changed

redisinsight/api/src/modules/commands/commands.service.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { assign } from 'lodash';
1+
import { assign, forEach } from 'lodash';
22
import { Injectable, OnModuleInit } from '@nestjs/common';
33
import { CommandsJsonProvider } from 'src/modules/commands/commands-json.provider';
44

@@ -31,10 +31,15 @@ export class CommandsService implements OnModuleInit {
3131
* Get all commands merged into single object
3232
*/
3333
async getAll(): Promise<any> {
34-
return assign(
35-
{},
36-
...Object.values(await this.getCommandsGroups()),
37-
);
34+
const commands = {};
35+
36+
Object.entries(await this.getCommandsGroups()).forEach(([provider, groupCommands]) => {
37+
return forEach(groupCommands as {}, (value: {}, command) => {
38+
commands[command] = { ...value, provider };
39+
});
40+
});
41+
42+
return commands;
3843
}
3944

4045
async getCommandsGroups(): Promise<any> {

redisinsight/ui/src/components/cli/components/cli-input/CliAutocomplete/CliAutocomplete.spec.tsx

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,42 @@ describe('CliAutocomplete', () => {
7979
expect(store.getActions().slice(-2)).toEqual(expectedActions)
8080
})
8181

82-
it('Autocomplete should be only with optional args for "scan" command with filled in required args ', () => {
82+
it('Autocomplete should be only with optional args for "scan" command with filled in required args (new realization)', () => {
8383
const autocompleteOptionalText = '[MATCH pattern] [COUNT count] [TYPE type]'
84+
const { queryByTestId } = render(
85+
<CliAutocomplete
86+
{...instance(mockedProps)}
87+
provider="main"
88+
commandName={scanCommand}
89+
arguments={scanArgs}
90+
wordsTyped={2}
91+
/>
92+
)
93+
94+
const autocompleteComponent = queryByTestId(CliAutocompleteTestId)
95+
96+
expect(autocompleteOptionalText).toEqual(autocompleteComponent?.textContent)
97+
})
98+
99+
it('Autocomplete should be only with optional args for "scan" command with filled in required args (old realization)', () => {
100+
const autocompleteOptionalText = '[pattern] [count] [type]'
101+
const { queryByTestId } = render(
102+
<CliAutocomplete
103+
{...instance(mockedProps)}
104+
provider="someprovider"
105+
commandName={scanCommand}
106+
arguments={scanArgs}
107+
wordsTyped={2}
108+
/>
109+
)
110+
111+
const autocompleteComponent = queryByTestId(CliAutocompleteTestId)
112+
113+
expect(autocompleteOptionalText).toEqual(autocompleteComponent?.textContent)
114+
})
115+
116+
it('Autocomplete should be only with optional args for "scan" command with filled in required args (old realization)', () => {
117+
const autocompleteOptionalText = '[pattern] [count] [type]'
84118
const { queryByTestId } = render(
85119
<CliAutocomplete
86120
{...instance(mockedProps)}
@@ -100,6 +134,7 @@ describe('CliAutocomplete', () => {
100134
const { queryByTestId } = render(
101135
<CliAutocomplete
102136
{...instance(mockedProps)}
137+
provider="main"
103138
commandName={scanCommand}
104139
arguments={scanArgs}
105140
wordsTyped={10}

redisinsight/ui/src/components/cli/components/cli-input/CliAutocomplete/CliAutocomplete.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ import { setMatchedCommand, clearSearchingCommand } from 'uiSrc/slices/cli/cli-s
99
import styles from './styles.module.scss'
1010

1111
export interface Props {
12+
provider: string;
1213
commandName: string;
1314
wordsTyped: number;
1415
arguments?: ICommandArg[];
1516
}
1617

1718
const CliAutocomplete = (props: Props) => {
18-
const { commandName = '', arguments: args = [], wordsTyped } = props
19+
const { commandName = '', provider = '', arguments: args = [], wordsTyped } = props
1920

2021
const dispatch = useDispatch()
2122

@@ -47,7 +48,7 @@ const CliAutocomplete = (props: Props) => {
4748
}
4849

4950
if (args.length) {
50-
argsList = generateArgsNames(args)
51+
argsList = generateArgsNames(provider, args)
5152

5253
untypedArgs = argsList.slice(getUntypedArgs()).join(' ')
5354
argsList = argsList.join(' ')

redisinsight/ui/src/components/cli/components/cli-input/CliInputWrapper.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const CliInputWrapper = (props: Props) => {
2727
const secondCommandMatch = `${firstCommandMatch} ${secondCommand ? secondCommand.toUpperCase() : null}`
2828

2929
const matchedCmd = ALL_REDIS_COMMANDS[secondCommandMatch] || ALL_REDIS_COMMANDS[firstCommandMatch]
30+
const provider = matchedCmd?.provider || 'unknown'
3031
const commandName = !isUndefined(ALL_REDIS_COMMANDS[secondCommandMatch])
3132
? `${firstCommand} ${secondCommand}`
3233
: firstCommand
@@ -42,6 +43,7 @@ const CliInputWrapper = (props: Props) => {
4243
/>
4344
{matchedCmd && (
4445
<CliAutocomplete
46+
provider={provider}
4547
commandName={commandName}
4648
wordsTyped={repeatCommand === 1 ? wordsTyped : wordsTyped - 1}
4749
{...matchedCmd}

redisinsight/ui/src/components/command-helper/CommandHelperWrapper.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const CommandHelperWrapper = () => {
4949
group = CommandGroup.Generic,
5050
complexity = '',
5151
since = '',
52+
provider,
5253
}: ICommand = ALL_REDIS_COMMANDS[lastMatchedCommand.toUpperCase()] ?? {}
5354

5455
if (isSearching) {
@@ -61,9 +62,9 @@ const CommandHelperWrapper = () => {
6162
})
6263
}
6364

64-
const generatedArgs = generateArgs(args)
65+
const generatedArgs = generateArgs(provider, args)
6566
const complexityShort = getComplexityShortNotation(complexity)
66-
const argString = [lastMatchedCommand.toUpperCase(), ...generateArgsNames(args)].join(' ')
67+
const argString = [lastMatchedCommand.toUpperCase(), ...generateArgsNames(provider, args)].join(' ')
6768

6869
const generateArgData = (arg: ICommandArgGenerated, i: number): ReactElement => {
6970
const type = arg.multiple ? 'Multiple' : arg.optional ? 'Optional' : 'Required'

redisinsight/ui/src/components/command-helper/components/command-helper-search-output/CHSearchOutput.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const CHSearchOutput = ({ searchedCommands }: Props) => {
3535
const renderDescription = (command: string) => {
3636
const args = ALL_REDIS_COMMANDS[command].arguments || []
3737
if (args.length) {
38-
const argString = generateArgsNames(args).join(' ')
38+
const argString = generateArgsNames(ALL_REDIS_COMMANDS[command]?.provider, args).join(' ')
3939
return (
4040
<EuiText
4141
size="s"

redisinsight/ui/src/constants/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export interface ICommand {
99
arguments?: ICommandArg[];
1010
since: string;
1111
group: CommandGroup | string;
12+
provider?: string;
1213
}
1314

1415
export interface ICommandArg {

0 commit comments

Comments
 (0)