diff --git a/src/components/Popups/ReplyField/ItemList.tsx b/src/components/Popups/ReplyField/ItemList.tsx index 0893186f9..ecb0dfa41 100644 --- a/src/components/Popups/ReplyField/ItemList.tsx +++ b/src/components/Popups/ReplyField/ItemList.tsx @@ -1,31 +1,30 @@ import React, { SyntheticEvent } from 'react'; import noop from 'lodash/noop'; -import uniqueId from 'lodash/uniqueId'; import ItemRow from './ItemRow'; import './ItemList.scss'; -export type Props = { +export type Props = { activeItemIndex?: number; itemRowAs?: JSX.Element; - items: Record[]; + items: T[]; onSelect: (index: number, event: React.SyntheticEvent) => void; setActiveItemIndex?: (index: number) => void; }; -const ItemList = ({ +export default function ItemList({ activeItemIndex = 0, itemRowAs = , items, onSelect, setActiveItemIndex = noop, ...rest -}: Props): JSX.Element => { +}: Props): JSX.Element { return (
    {items.map((item, index) => React.cloneElement(itemRowAs, { ...item, - key: item.id ? String(item.id) : uniqueId(), + key: item.id, className: 'ba-ItemList-row', isActive: index === activeItemIndex, onClick: (event: SyntheticEvent) => { @@ -42,6 +41,4 @@ const ItemList = ({ )}
); -}; - -export default ItemList; +} diff --git a/src/components/Popups/ReplyField/PopupList.tsx b/src/components/Popups/ReplyField/PopupList.tsx index e73126c62..4125f3ec7 100644 --- a/src/components/Popups/ReplyField/PopupList.tsx +++ b/src/components/Popups/ReplyField/PopupList.tsx @@ -7,10 +7,10 @@ import PopupBase from '../PopupBase'; import { Options, PopupReference } from '../Popper'; import './PopupList.scss'; -export type Props = { +export type Props = { activeItemIndex?: number; itemRowAs?: JSX.Element; - items: Record[]; + items: T[]; onSelect: (index: number, event: React.SyntheticEvent) => void; options?: Partial; reference: PopupReference; @@ -35,16 +35,21 @@ const defaultOptions: Partial = { placement: 'bottom-start', }; -const PopupList = ({ items, reference, options, ...rest }: Props): JSX.Element => ( - - {isEmpty(items) ? ( -
- -
- ) : ( - - )} -
-); - -export default PopupList; +export default function PopupList({ + items, + reference, + options, + ...rest +}: Props): JSX.Element { + return ( + + {isEmpty(items) ? ( +
+ +
+ ) : ( + + )} +
+ ); +} diff --git a/src/components/Popups/ReplyField/ReplyField.tsx b/src/components/Popups/ReplyField/ReplyField.tsx index a6e0b5612..962f6b631 100644 --- a/src/components/Popups/ReplyField/ReplyField.tsx +++ b/src/components/Popups/ReplyField/ReplyField.tsx @@ -235,7 +235,7 @@ export default class ReplyField extends React.Component { /> {popupReference && ( - activeItemIndex={activeItemIndex} itemRowAs={itemRowAs} items={this.getCollaborators(getActiveMentionForEditorState(editorState))} diff --git a/src/components/Popups/ReplyField/__tests__/ItemList-test.tsx b/src/components/Popups/ReplyField/__tests__/ItemList-test.tsx index f0b0bf915..b7ba55c1a 100644 --- a/src/components/Popups/ReplyField/__tests__/ItemList-test.tsx +++ b/src/components/Popups/ReplyField/__tests__/ItemList-test.tsx @@ -1,9 +1,10 @@ import React from 'react'; import { shallow, ShallowWrapper } from 'enzyme'; import ItemList, { Props } from '../ItemList'; +import { Collaborator } from '../../../../@types'; describe('components/Popups/ReplyField/ItemList', () => { - const defaults: Props = { + const defaults: Props = { items: [ { id: 'testid1', name: 'test1' }, { id: 'testid2', name: 'test2' }, diff --git a/src/components/Popups/ReplyField/__tests__/PopupList-test.tsx b/src/components/Popups/ReplyField/__tests__/PopupList-test.tsx index 1b0b1ffc8..c3ecc7628 100644 --- a/src/components/Popups/ReplyField/__tests__/PopupList-test.tsx +++ b/src/components/Popups/ReplyField/__tests__/PopupList-test.tsx @@ -2,9 +2,10 @@ import React from 'react'; import { shallow, ShallowWrapper } from 'enzyme'; import PopupBase from '../../PopupBase'; import PopupList, { Props } from '../PopupList'; +import { Collaborator } from '../../../../@types'; describe('components/Popups/ReplyField/PopupList', () => { - const defaults: Props = { + const defaults: Props = { items: [], onSelect: jest.fn(), reference: document.createElement('div'),