-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #224 from RedisInsight/feature/RIVS-299_Add_featur…
…e_from_RI #RIVS-299 - Add the changes from the main project
- Loading branch information
Showing
39 changed files
with
769 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/webviews/src/components/super-select/SuperSelect.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react' | ||
import { instance, mock } from 'ts-mockito' | ||
|
||
import { render, constants, fireEvent, waitFor } from 'testSrc/helpers' | ||
import { SuperSelect, Props } from './SuperSelect' | ||
|
||
const mockedProps = mock<Props>() | ||
const testIdMock = 'my-select-component' | ||
|
||
describe('SuperSelect', () => { | ||
it('should render', async () => { | ||
expect(render( | ||
<SuperSelect {...instance(mockedProps)} options={constants.SUPER_SELECT_OPTIONS} />), | ||
).toBeTruthy() | ||
}) | ||
|
||
it('should call onChange when the first option is selected', async () => { | ||
const mockedOnChange = vi.fn() | ||
const mockedLabel = constants.SUPER_SELECT_OPTIONS?.[0].label ?? '' | ||
const mockedValue = constants.SUPER_SELECT_OPTIONS?.[0].value ?? '' | ||
|
||
const { getByText, queryByTestId } = render(<SuperSelect | ||
options={constants.SUPER_SELECT_OPTIONS} | ||
onChange={mockedOnChange} | ||
testid={testIdMock} | ||
/>) | ||
|
||
const mySelectComponent = queryByTestId('my-select-component') | ||
|
||
expect(mySelectComponent).toBeDefined() | ||
expect(mySelectComponent).not.toBeNull() | ||
expect(mockedOnChange).toHaveBeenCalledTimes(0) | ||
|
||
fireEvent.keyDown(mySelectComponent?.firstChild!, { key: 'ArrowDown' }) | ||
await waitFor(() => getByText(mockedLabel)) | ||
fireEvent.click(getByText(mockedLabel)) | ||
|
||
expect(mockedOnChange).toHaveBeenCalledTimes(1) | ||
expect(mockedOnChange).toHaveBeenCalledWith( | ||
{ label: mockedLabel, value: mockedValue }, | ||
{ action: 'select-option', name: undefined, option: undefined }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import React, { FC } from 'react' | ||
import cx from 'classnames' | ||
import Select, { Props as SelectProps } from 'react-select' | ||
|
||
import { Maybe } from 'uiSrc/interfaces' | ||
import styles from './styles.module.scss' | ||
|
||
export interface SuperSelectOption { | ||
value: string | ||
label: string | ||
testid?: string | ||
} | ||
|
||
export interface Props extends SelectProps<SuperSelectOption, false> { | ||
selectedOption?: Maybe<SuperSelectOption> | ||
containerClassName?: string | ||
itemClassName?: string | ||
testid?: string | ||
} | ||
|
||
const SuperSelect: FC<Props> = (props) => { | ||
const { | ||
selectedOption, | ||
containerClassName, | ||
testid, | ||
} = props | ||
|
||
return ( | ||
<div className={cx(styles.container, containerClassName)} data-testid={testid}> | ||
<Select<SuperSelectOption> | ||
{...props} | ||
closeMenuOnSelect | ||
closeMenuOnScroll | ||
isSearchable={false} | ||
isMulti={false} | ||
value={selectedOption} | ||
classNames={{ | ||
container: () => styles.selectContainer, | ||
control: () => styles.control, | ||
option: ({ isSelected }) => cx(styles.option, { [styles.optionSelected]: isSelected }), | ||
singleValue: () => styles.singleValue, | ||
menu: () => styles.menu, | ||
indicatorsContainer: () => styles.indicatorsContainer, | ||
indicatorSeparator: () => 'hidden', | ||
}} | ||
/> | ||
</div> | ||
) | ||
} | ||
|
||
export { SuperSelect } |
13 changes: 13 additions & 0 deletions
13
...webviews/src/components/super-select/components/removable-option/RemovableOption.spec.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import { instance, mock } from 'ts-mockito' | ||
|
||
import { render, constants } from 'testSrc/helpers' | ||
import { SuperSelectRemovableOption, Props } from './RemovableOption' | ||
|
||
const mockedProps = mock<Props>() | ||
|
||
describe('SuperSelectRemovableOption', () => { | ||
it('should render', async () => { | ||
expect(render(<SuperSelectRemovableOption {...instance(mockedProps)} options={constants.SUPER_SELECT_OPTIONS} />)).toBeTruthy() | ||
}) | ||
}) |
63 changes: 63 additions & 0 deletions
63
src/webviews/src/components/super-select/components/removable-option/RemovableOption.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import React, { Children, useCallback, useState } from 'react' | ||
import { MenuListProps } from 'react-select' | ||
import cx from 'classnames' | ||
import * as l10n from '@vscode/l10n' | ||
|
||
import { PopoverDelete, SuperSelectOption } from 'uiSrc/components' | ||
import { Maybe, RedisString } from 'uiSrc/interfaces' | ||
|
||
import styles from '../../styles.module.scss' | ||
|
||
export interface Props extends MenuListProps<SuperSelectOption, false> { | ||
suffix: string | ||
countDefaultOptions: number | ||
onDeleteOption: (id: RedisString, onSuccess: () => void) => void | ||
} | ||
|
||
const SuperSelectRemovableOption = (props: Props) => { | ||
const { suffix, countDefaultOptions = 0, options, children, getValue, selectOption, onDeleteOption } = props | ||
|
||
const [activeOptionId, setActiveOptionId] = useState<Maybe<string>>(undefined) | ||
|
||
const showPopover = useCallback((id = '') => { | ||
setActiveOptionId(`${id}${suffix}`) | ||
}, []) | ||
|
||
const handleRemoveOption = (id: RedisString) => { | ||
onDeleteOption(id, () => { | ||
const selectedValue = getValue()?.[0] | ||
setActiveOptionId(undefined) | ||
|
||
// reset selected option if removed value is selected | ||
if (selectedValue?.value === id) { | ||
selectOption(options?.[0] as SuperSelectOption) | ||
} else { | ||
selectOption(selectedValue) | ||
} | ||
}) | ||
} | ||
|
||
return ( | ||
<div> | ||
{Children.map(children, (child, i) => ( | ||
<div key={(options[i] as SuperSelectOption).value} className={cx(styles.option, 'flex justify-between items-center relative')}> | ||
{child} | ||
{i + 1 > countDefaultOptions && <PopoverDelete | ||
header={`${(options[i] as SuperSelectOption).label}`} | ||
text={l10n.t('will be removed from Redis for VS Code.')} | ||
item={(options[i] as SuperSelectOption).value} | ||
suffix={suffix} | ||
triggerClassName='absolute right-2.5' | ||
position='right center' | ||
deleting={activeOptionId} | ||
showPopover={showPopover} | ||
handleDeleteItem={handleRemoveOption} | ||
testid={`delete-option-${(options[i] as SuperSelectOption).value}`} | ||
/>} | ||
</div> | ||
))} | ||
</div> | ||
) | ||
} | ||
|
||
export { SuperSelectRemovableOption } |
Oops, something went wrong.