Skip to content

Commit a2edfaf

Browse files
author
Kristiyan Ivanov
committed
RI-6188 There is no dropdown to specify how to add elements for adding a new list
1 parent 41df850 commit a2edfaf

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

redisinsight/api/src/modules/browser/list/list.service.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,25 @@ export class ListService {
234234
client: RedisClient,
235235
dto: PushElementToListDto,
236236
): Promise<void> {
237-
const { keyName, elements } = dto;
238-
await client.sendCommand([BrowserToolListCommands.LPush, keyName, ...elements]);
237+
const { keyName, elements, destination } = dto;
238+
await client.sendCommand([
239+
BrowserToolListCommands[destination === ListElementDestination.Tail ? 'RPush' : 'LPush'],
240+
keyName,
241+
...elements
242+
]);
239243
}
240244

241245
public async createListWithExpiration(
242246
client: RedisClient,
243247
dto: CreateListWithExpireDto,
244248
): Promise<void> {
245-
const { keyName, elements, expire } = dto;
249+
const { keyName, elements, expire, destination } = dto;
246250
const transactionResults = await client.sendPipeline([
247-
[BrowserToolListCommands.LPush, keyName, ...elements],
251+
[
252+
BrowserToolListCommands[destination === ListElementDestination.Tail ? 'RPush' : 'LPush'],
253+
keyName,
254+
...elements
255+
],
248256
[BrowserToolKeysCommands.Expire, keyName, expire],
249257
]);
250258
catchMultiTransactionError(transactionResults);

redisinsight/ui/src/pages/browser/components/add-key/AddKeyList/AddKeyList.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ import {
99
EuiFlexItem,
1010
EuiPanel,
1111
EuiFieldText,
12+
EuiSuperSelect,
1213
} from '@elastic/eui'
1314

1415
import { Maybe, stringToBuffer } from 'uiSrc/utils'
1516
import { addKeyStateSelector, addListKey } from 'uiSrc/slices/browser/keys'
16-
import { CreateListWithExpireDto } from 'apiSrc/modules/browser/list/dto'
17+
import { CreateListWithExpireDto, ListElementDestination } from 'apiSrc/modules/browser/list/dto'
1718

1819
import {
1920
AddListFormConfig as config,
2021
} from '../constants/fields-config'
2122
import AddKeyFooter from '../AddKeyFooter/AddKeyFooter'
2223
import AddMultipleFields from '../../add-multiple-fields'
24+
import { optionsDestinations, TAIL_DESTINATION } from 'uiSrc/pages/browser/modules/key-details/components/list-details/add-list-elements/AddListElements'
25+
2326

2427
export interface Props {
2528
keyName: string
@@ -30,6 +33,7 @@ export interface Props {
3033
const AddKeyList = (props: Props) => {
3134
const { keyName = '', keyTTL, onCancel } = props
3235
const [elements, setElements] = useState<string[]>([''])
36+
const [destination, setDestination] = useState<ListElementDestination>(TAIL_DESTINATION)
3337

3438
const [isFormValid, setIsFormValid] = useState<boolean>(false)
3539

@@ -70,6 +74,7 @@ const AddKeyList = (props: Props) => {
7074

7175
const submitData = (): void => {
7276
const data: CreateListWithExpireDto = {
77+
destination,
7378
keyName: stringToBuffer(keyName),
7479
elements: elements.map((el) => stringToBuffer(el)),
7580
}
@@ -81,6 +86,12 @@ const AddKeyList = (props: Props) => {
8186

8287
return (
8388
<EuiForm component="form" onSubmit={onFormSubmit}>
89+
<EuiSuperSelect
90+
valueOfSelected={destination}
91+
options={optionsDestinations}
92+
onChange={(value) => setDestination(value as ListElementDestination)}
93+
data-testid="destination-select"
94+
/>
8495
<AddMultipleFields
8596
items={elements}
8697
onClickRemove={onClickRemove}

redisinsight/ui/src/pages/browser/modules/key-details/components/list-details/add-list-elements/AddListElements.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export enum ListElementDestination {
3636
export const TAIL_DESTINATION: ListElementDestination = ListElementDestination.Tail
3737
export const HEAD_DESTINATION: ListElementDestination = ListElementDestination.Head
3838

39-
const optionsDestinations: EuiSuperSelectOption<string>[] = [
39+
export const optionsDestinations: EuiSuperSelectOption<string>[] = [
4040
{
4141
value: TAIL_DESTINATION,
4242
inputDisplay: 'Push to tail',

0 commit comments

Comments
 (0)