Skip to content

Commit c2c22b6

Browse files
committed
RI-6188 There is no dropdown to specify how to add elements for adding a new list
1 parent db9e590 commit c2c22b6

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

src/webviews/src/modules/add-key/components/AddKeyList/AddKeyList.tsx

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,39 @@ import React, { ChangeEvent, FormEvent, useState, useEffect } from 'react'
22
import * as l10n from '@vscode/l10n'
33
import { VSCodeButton } from '@vscode/webview-ui-toolkit/react'
44

5-
import { KeyTypes, AddListFormConfig as config } from 'uiSrc/constants'
5+
import { HEAD_DESTINATION, KeyTypes, ListElementDestination, TAIL_DESTINATION, AddListFormConfig as config } from 'uiSrc/constants'
66
import { getRequiredFieldsText, stringToBuffer } from 'uiSrc/utils'
77
import { Maybe } from 'uiSrc/interfaces'
88
import { useKeysApi, useKeysInContext } from 'uiSrc/modules/keys-tree/hooks/useKeys'
9-
import { InputText, Tooltip } from 'uiSrc/ui'
9+
import { InputText, Select, SelectOption, Tooltip } from 'uiSrc/ui'
1010
import { CreateListWithExpireDto } from 'uiSrc/modules/keys-tree/hooks/interface'
1111
import { AddItemsActions } from 'uiSrc/components'
1212

13+
import styles from '../../styles.module.scss'
14+
1315
export interface Props {
1416
keyName: string
1517
keyTTL: Maybe<number>
1618
onClose: (isCancelled?: boolean, keyType?: KeyTypes) => void
1719
}
1820

21+
const optionsDestinations: SelectOption[] = [
22+
{
23+
value: TAIL_DESTINATION,
24+
label: l10n.t('Push to tail'),
25+
testid: TAIL_DESTINATION,
26+
},
27+
{
28+
value: HEAD_DESTINATION,
29+
label: l10n.t('Push to head'),
30+
testid: HEAD_DESTINATION,
31+
},
32+
]
33+
1934
export const AddKeyList = (props: Props) => {
2035
const { keyName = '', keyTTL, onClose } = props
2136
const [elements, setElements] = useState<string[]>([''])
37+
const [destination, setDestination] = useState<ListElementDestination>(TAIL_DESTINATION)
2238
const [isFormValid, setIsFormValid] = useState<boolean>(false)
2339

2440
const keysApi = useKeysApi()
@@ -60,6 +76,7 @@ export const AddKeyList = (props: Props) => {
6076
const submitData = (): void => {
6177
const data: CreateListWithExpireDto = {
6278
keyName: stringToBuffer(keyName),
79+
destination,
6380
elements: elements.map((el) => stringToBuffer(el)),
6481
}
6582
if (keyTTL !== undefined) {
@@ -74,6 +91,17 @@ export const AddKeyList = (props: Props) => {
7491
<>
7592
<form onSubmit={onFormSubmit} className="key-footer-items-container pl-0 h-full">
7693
<h3 className="font-bold uppercase pb-3">{l10n.t('Element')}</h3>
94+
<div className="w-1/3 mr-2 mb-3">
95+
<Select
96+
position="below"
97+
options={optionsDestinations}
98+
containerClassName={styles.select}
99+
itemClassName={styles.selectOption}
100+
idSelected={destination}
101+
onChange={(value) => setDestination(value as ListElementDestination)}
102+
testid="destination-select"
103+
/>
104+
</div>
77105
{elements.map((item, index) => (
78106
<div key={index}>
79107
<div className="flex items-center mb-3">

src/webviews/src/modules/add-key/styles.module.scss

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,14 @@
2222
border-top: 1px solid;
2323
opacity: .5;
2424
}
25+
26+
.select {
27+
@apply h-full w-full bg-vscode-dropdown-background ;
28+
29+
&::part(control) {
30+
@apply border-vscode-dropdown-background;
31+
}
32+
&::part(listbox) {
33+
@apply mt-4;
34+
}
35+
}

src/webviews/src/modules/keys-tree/hooks/interface.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { KeyTypes } from 'uiSrc/constants'
1+
import { KeyTypes, ListElementDestination } from 'uiSrc/constants'
22
import { KeyDto, KeyInfo, Nullable, RedisString } from 'uiSrc/interfaces'
33
import { ZSetMember } from 'uiSrc/modules/key-details/components/zset-details/hooks/interface'
44

@@ -105,7 +105,8 @@ export interface CreateSetWithExpireDto extends KeyWithExpireDto {
105105
}
106106

107107
export interface CreateListWithExpireDto extends KeyWithExpireDto {
108-
elements: RedisString[]
108+
elements: RedisString[],
109+
destination: ListElementDestination,
109110
}
110111

111112
export interface HashFieldDto {

0 commit comments

Comments
 (0)