0

Fix deprecated antd dropdown warnings (#3171)

* Fix deprecated antd dropdown warnings
This commit is contained in:
janWilejan 2023-07-13 20:28:12 +00:00 committed by GitHub
parent 5389554028
commit e15e2dc47c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 65 additions and 105 deletions

View File

@ -1,5 +1,5 @@
import { FC } from 'react'; import { FC } from 'react';
import { Button, Dropdown, Menu } from 'antd'; import { Button, Dropdown } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import styles from './ActionButtonMenu.module.scss'; import styles from './ActionButtonMenu.module.scss';
@ -41,7 +41,7 @@ export const ActionButtonMenu: FC<ActionButtonMenuProps> = ({
showNotifyItem, showNotifyItem,
className, className,
}) => { }) => {
const onMenuClick = a => { const onClick = a => {
if (a.key === NOTIFY_KEY) { if (a.key === NOTIFY_KEY) {
notifyItemSelected(); notifyItemSelected();
return; return;
@ -87,13 +87,11 @@ export const ActionButtonMenu: FC<ActionButtonMenuProps> = ({
}); });
} }
const menu = <Menu items={items} onClick={onMenuClick} />;
const dropdownClasses = classNames([styles.menu, className]); const dropdownClasses = classNames([styles.menu, className]);
return ( return (
<Dropdown <Dropdown
overlay={menu} menu={{ items, onClick }}
placement="bottomRight" placement="bottomRight"
trigger={['click']} trigger={['click']}
className={dropdownClasses} className={dropdownClasses}

View File

@ -1,3 +0,0 @@
.icon {
padding-right: 10px;
}

View File

@ -1,9 +1,8 @@
import { Dropdown, Menu, MenuProps, Space, message, Modal as AntModal } from 'antd'; import { Dropdown, MenuProps, Space, message, Modal as AntModal } from 'antd';
import { FC, useState } from 'react'; import { FC, useState } from 'react';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { Modal } from '../../ui/Modal/Modal'; import { Modal } from '../../ui/Modal/Modal';
import { ChatModerationDetailsModal } from '../ChatModerationDetailsModal/ChatModerationDetailsModal'; import { ChatModerationDetailsModal } from '../ChatModerationDetailsModal/ChatModerationDetailsModal';
import styles from './ChatModerationActionMenu.module.scss';
import ChatModeration from '../../../services/moderation-service'; import ChatModeration from '../../../services/moderation-service';
const { confirm } = AntModal; const { confirm } = AntModal;
@ -82,53 +81,29 @@ export const ChatModerationActionMenu: FC<ChatModerationActionMenuProps> = ({
}); });
}; };
const onMenuClick: MenuProps['onClick'] = ({ key }) => { const items: MenuProps['items'] = [
if (key === 'hide-message') { {
confirmHideMessage(); icon: <EyeInvisibleOutlined />,
} else if (key === 'ban-user') { label: 'Hide Message',
confirmBanUser(); key: 'hide-message',
} else if (key === 'more-info') { onClick: confirmHideMessage,
setShowUserDetailsModal(true); },
} {
}; icon: <CloseCircleOutlined />,
label: 'Ban User',
const menu = ( key: 'ban-user',
<Menu onClick: confirmBanUser,
onClick={onMenuClick} },
items={[ {
{ label: 'More Info...',
label: ( key: 'more-info',
<div> onClick: () => setShowUserDetailsModal(true),
<span className={styles.icon}> },
<EyeInvisibleOutlined /> ];
</span>
Hide Message
</div>
),
key: 'hide-message',
},
{
label: (
<div>
<span className={styles.icon}>
<CloseCircleOutlined />
</span>
Ban User
</div>
),
key: 'ban-user',
},
{
label: <div>More Info...</div>,
key: 'more-info',
},
]}
/>
);
return ( return (
<> <>
<Dropdown overlay={menu} trigger={['click']}> <Dropdown menu={{ items }} trigger={['click']}>
<button type="button" onClick={e => e.preventDefault()}> <button type="button" onClick={e => e.preventDefault()}>
<Space> <Space>
<SmallDashOutlined /> <SmallDashOutlined />

View File

@ -1,4 +1,4 @@
import { Menu, Dropdown, Button } from 'antd'; import { MenuProps, Dropdown, Button } from 'antd';
import classnames from 'classnames'; import classnames from 'classnames';
import { useRecoilState, useRecoilValue } from 'recoil'; import { useRecoilState, useRecoilValue } from 'recoil';
@ -145,37 +145,37 @@ export const UserDropdown: FC<UserDropdownProps> = ({
const { displayName } = currentUser; const { displayName } = currentUser;
const username = defaultUsername || displayName; const username = defaultUsername || displayName;
const menu = (
<Menu> const items: MenuProps['items'] = [
<Menu.Item key="0" icon={<EditOutlined />} onClick={() => handleChangeName()}> {
Change name key: 0,
</Menu.Item> icon: <EditOutlined />,
<Menu.Item key="1" icon={<LockOutlined />} onClick={() => setShowAuthModal(true)}> label: 'Change name',
Authenticate onClick: handleChangeName,
</Menu.Item> },
{canShowHideChat && ( {
<Menu.Item key: 1,
key="3" icon: <LockOutlined />,
icon={<MessageOutlined />} label: 'Authenticate',
onClick={() => toggleChatVisibility()} onClick: () => setShowAuthModal(true),
aria-expanded={chatState === ChatState.VISIBLE} },
className={styles.chatToggle} ];
> if (canShowHideChat)
{chatState === ChatState.VISIBLE ? 'Hide Chat' : 'Show Chat'} items.push({
</Menu.Item> key: 3,
)} 'aria-expanded': chatState === ChatState.VISIBLE,
{canShowChatPopup && className: styles.chatToggle, // TODO why do we hide this button on tablets?
(popupWindow ? ( icon: <MessageOutlined />,
<Menu.Item key="4" icon={<ShrinkOutlined />} onClick={closeChatPopup}> label: chatState === ChatState.VISIBLE ? 'Hide Chat' : 'Show Chat',
Put chat back onClick: toggleChatVisibility,
</Menu.Item> } as MenuProps['items'][0]);
) : ( if (canShowChatPopup)
<Menu.Item key="4" icon={<ExpandAltOutlined />} onClick={openChatPopup}> items.push({
Pop out chat key: 4,
</Menu.Item> icon: popupWindow ? <ShrinkOutlined /> : <ExpandAltOutlined />,
))} label: popupWindow ? 'Put chat back' : 'Pop out chat',
</Menu> onClick: popupWindow ? closeChatPopup : openChatPopup,
); });
return ( return (
<ErrorBoundary <ErrorBoundary
@ -189,7 +189,7 @@ export const UserDropdown: FC<UserDropdownProps> = ({
)} )}
> >
<div className={styles.root}> <div className={styles.root}>
<Dropdown overlay={menu} trigger={['click']}> <Dropdown menu={{ items }} trigger={['click']}>
<Button id={id} type="primary" icon={<UserOutlined className={styles.userIcon} />}> <Button id={id} type="primary" icon={<UserOutlined className={styles.userIcon} />}>
<span <span
className={classnames([ className={classnames([

View File

@ -1,5 +1,5 @@
import React, { useState, useEffect, useContext, ReactElement } from 'react'; import React, { useState, useEffect, useContext, ReactElement } from 'react';
import { Row, Col, Typography, Menu, Dropdown, Spin, Alert } from 'antd'; import { Row, Col, Typography, MenuProps, Dropdown, Spin, Alert } from 'antd';
import { getUnixTime, sub } from 'date-fns'; import { getUnixTime, sub } from 'date-fns';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import { Chart } from '../../components/admin/Chart'; import { Chart } from '../../components/admin/Chart';
@ -85,22 +85,12 @@ export default function ViewersOverTime() {
setTimeWindowStart(times[key]); setTimeWindowStart(times[key]);
}; };
const menu = ( const offset: number = online && streamStart ? 0 : 1;
<Menu> const items: MenuProps['items'] = times.slice(offset).map((time, index) => ({
{online && streamStart && ( key: index + offset,
<Menu.Item key="0" onClick={onTimeWindowSelect}> label: time.title,
{times[0].title} onClick: onTimeWindowSelect,
</Menu.Item> }));
)}
{times.slice(1).map((time, index) => (
// The array is hard coded, so it's safe to use the index as a key.
// eslint-disable-next-line react/no-array-index-key
<Menu.Item key={index + 1} onClick={onTimeWindowSelect}>
{time.title}
</Menu.Item>
))}
</Menu>
);
return ( return (
<> <>
@ -142,7 +132,7 @@ export default function ViewersOverTime() {
)} )}
<Spin spinning={!viewerInfo.length || loadingChart}> <Spin spinning={!viewerInfo.length || loadingChart}>
<Dropdown overlay={menu} trigger={['click']}> <Dropdown menu={{ items }} trigger={['click']}>
<button <button
type="button" type="button"
style={{ float: 'right', background: 'transparent', border: 'unset' }} style={{ float: 'right', background: 'transparent', border: 'unset' }}