mirror of
https://github.com/SigNoz/signoz.git
synced 2025-12-17 23:47:12 +00:00
Converted format options menu to popover (#9094)
This pull request refactors the LogsFormatOptionsMenu component to use the Ant Design Popover for displaying format options, replacing the previous custom dropdown implementation. It also updates the related styles and removes now-unnecessary state and logic from parent components. The changes improve code maintainability, UI consistency, and simplify event handling.
This commit is contained in:
parent
a90904951e
commit
ba8a49929a
File diff suppressed because it is too large
Load Diff
@ -3,24 +3,30 @@
|
|||||||
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
||||||
import './LogsFormatOptionsMenu.styles.scss';
|
import './LogsFormatOptionsMenu.styles.scss';
|
||||||
|
|
||||||
import { Button, Input, InputNumber, Tooltip, Typography } from 'antd';
|
import { Button, Input, InputNumber, Popover, Tooltip, Typography } from 'antd';
|
||||||
import { DefaultOptionType } from 'antd/es/select';
|
import { DefaultOptionType } from 'antd/es/select';
|
||||||
import cx from 'classnames';
|
import cx from 'classnames';
|
||||||
import { LogViewMode } from 'container/LogsTable';
|
import { LogViewMode } from 'container/LogsTable';
|
||||||
import { FontSize, OptionsMenuConfig } from 'container/OptionsMenu/types';
|
import { FontSize, OptionsMenuConfig } from 'container/OptionsMenu/types';
|
||||||
import useDebouncedFn from 'hooks/useDebouncedFunction';
|
import useDebouncedFn from 'hooks/useDebouncedFunction';
|
||||||
import { Check, ChevronLeft, ChevronRight, Minus, Plus, X } from 'lucide-react';
|
import {
|
||||||
|
Check,
|
||||||
|
ChevronLeft,
|
||||||
|
ChevronRight,
|
||||||
|
Minus,
|
||||||
|
Plus,
|
||||||
|
Sliders,
|
||||||
|
X,
|
||||||
|
} from 'lucide-react';
|
||||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||||
|
|
||||||
interface LogsFormatOptionsMenuProps {
|
interface LogsFormatOptionsMenuProps {
|
||||||
title: string;
|
|
||||||
items: any;
|
items: any;
|
||||||
selectedOptionFormat: any;
|
selectedOptionFormat: any;
|
||||||
config: OptionsMenuConfig;
|
config: OptionsMenuConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function LogsFormatOptionsMenu({
|
export default function LogsFormatOptionsMenu({
|
||||||
title,
|
|
||||||
items,
|
items,
|
||||||
selectedOptionFormat,
|
selectedOptionFormat,
|
||||||
config,
|
config,
|
||||||
@ -43,6 +49,7 @@ export default function LogsFormatOptionsMenu({
|
|||||||
const [selectedValue, setSelectedValue] = useState<string | null>(null);
|
const [selectedValue, setSelectedValue] = useState<string | null>(null);
|
||||||
const listRef = useRef<HTMLDivElement>(null);
|
const listRef = useRef<HTMLDivElement>(null);
|
||||||
const initialMouseEnterRef = useRef<boolean>(false);
|
const initialMouseEnterRef = useRef<boolean>(false);
|
||||||
|
const [isPopoverOpen, setIsPopoverOpen] = useState<boolean>(false);
|
||||||
|
|
||||||
const onChange = useCallback(
|
const onChange = useCallback(
|
||||||
(key: LogViewMode) => {
|
(key: LogViewMode) => {
|
||||||
@ -202,7 +209,7 @@ export default function LogsFormatOptionsMenu({
|
|||||||
};
|
};
|
||||||
}, [selectedValue]);
|
}, [selectedValue]);
|
||||||
|
|
||||||
return (
|
const popoverContent = (
|
||||||
<div
|
<div
|
||||||
className={cx(
|
className={cx(
|
||||||
'nested-menu-container',
|
'nested-menu-container',
|
||||||
@ -344,7 +351,7 @@ export default function LogsFormatOptionsMenu({
|
|||||||
</div>
|
</div>
|
||||||
<div className="horizontal-line" />
|
<div className="horizontal-line" />
|
||||||
<div className="menu-container">
|
<div className="menu-container">
|
||||||
<div className="title"> {title} </div>
|
<div className="title">FORMAT</div>
|
||||||
|
|
||||||
<div className="menu-items">
|
<div className="menu-items">
|
||||||
{items.map(
|
{items.map(
|
||||||
@ -440,4 +447,21 @@ export default function LogsFormatOptionsMenu({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
return (
|
||||||
|
<Popover
|
||||||
|
content={popoverContent}
|
||||||
|
trigger="click"
|
||||||
|
placement="bottomRight"
|
||||||
|
arrow={false}
|
||||||
|
open={isPopoverOpen}
|
||||||
|
onOpenChange={setIsPopoverOpen}
|
||||||
|
rootClassName="format-options-popover"
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
className="periscope-btn ghost"
|
||||||
|
icon={<Sliders size={14} />}
|
||||||
|
data-testid="periscope-btn"
|
||||||
|
/>
|
||||||
|
</Popover>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -240,7 +240,6 @@ function LiveLogsContainer(): JSX.Element {
|
|||||||
|
|
||||||
{showFormatMenuItems && (
|
{showFormatMenuItems && (
|
||||||
<LogsFormatOptionsMenu
|
<LogsFormatOptionsMenu
|
||||||
title="FORMAT"
|
|
||||||
items={formatItems}
|
items={formatItems}
|
||||||
selectedOptionFormat={options.format}
|
selectedOptionFormat={options.format}
|
||||||
config={config}
|
config={config}
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
import { Button, Switch, Typography } from 'antd';
|
import { Switch, Typography } from 'antd';
|
||||||
import { WsDataEvent } from 'api/common/getQueryStats';
|
import { WsDataEvent } from 'api/common/getQueryStats';
|
||||||
import { getYAxisFormattedValue } from 'components/Graph/yAxisConfig';
|
import { getYAxisFormattedValue } from 'components/Graph/yAxisConfig';
|
||||||
import LogsFormatOptionsMenu from 'components/LogsFormatOptionsMenu/LogsFormatOptionsMenu';
|
import LogsFormatOptionsMenu from 'components/LogsFormatOptionsMenu/LogsFormatOptionsMenu';
|
||||||
@ -7,9 +7,7 @@ import { LOCALSTORAGE } from 'constants/localStorage';
|
|||||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||||
import Download from 'container/DownloadV2/DownloadV2';
|
import Download from 'container/DownloadV2/DownloadV2';
|
||||||
import { useOptionsMenu } from 'container/OptionsMenu';
|
import { useOptionsMenu } from 'container/OptionsMenu';
|
||||||
import useClickOutside from 'hooks/useClickOutside';
|
import { ArrowUp10, Minus } from 'lucide-react';
|
||||||
import { ArrowUp10, Minus, Sliders } from 'lucide-react';
|
|
||||||
import { useRef, useState } from 'react';
|
|
||||||
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
||||||
|
|
||||||
import QueryStatus from './QueryStatus';
|
import QueryStatus from './QueryStatus';
|
||||||
@ -41,9 +39,6 @@ function LogsActionsContainer({
|
|||||||
isSuccess: boolean;
|
isSuccess: boolean;
|
||||||
queryStats: WsDataEvent | undefined;
|
queryStats: WsDataEvent | undefined;
|
||||||
}): JSX.Element {
|
}): JSX.Element {
|
||||||
const [showFormatMenuItems, setShowFormatMenuItems] = useState(false);
|
|
||||||
const menuRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
const { options, config } = useOptionsMenu({
|
const { options, config } = useOptionsMenu({
|
||||||
storageKey: LOCALSTORAGE.LOGS_LIST_OPTIONS,
|
storageKey: LOCALSTORAGE.LOGS_LIST_OPTIONS,
|
||||||
dataSource: DataSource.LOGS,
|
dataSource: DataSource.LOGS,
|
||||||
@ -71,18 +66,6 @@ function LogsActionsContainer({
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const handleToggleShowFormatOptions = (): void =>
|
|
||||||
setShowFormatMenuItems(!showFormatMenuItems);
|
|
||||||
|
|
||||||
useClickOutside({
|
|
||||||
ref: menuRef,
|
|
||||||
onClickOutside: () => {
|
|
||||||
if (showFormatMenuItems) {
|
|
||||||
setShowFormatMenuItems(false);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="logs-actions-container">
|
<div className="logs-actions-container">
|
||||||
<div className="tab-options">
|
<div className="tab-options">
|
||||||
@ -119,22 +102,12 @@ function LogsActionsContainer({
|
|||||||
isLoading={isFetching}
|
isLoading={isFetching}
|
||||||
fileName="log_data"
|
fileName="log_data"
|
||||||
/>
|
/>
|
||||||
<div className="format-options-container" ref={menuRef}>
|
<div className="format-options-container">
|
||||||
<Button
|
<LogsFormatOptionsMenu
|
||||||
className="periscope-btn ghost"
|
items={formatItems}
|
||||||
onClick={handleToggleShowFormatOptions}
|
selectedOptionFormat={options.format}
|
||||||
icon={<Sliders size={14} />}
|
config={config}
|
||||||
data-testid="periscope-btn"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
{showFormatMenuItems && (
|
|
||||||
<LogsFormatOptionsMenu
|
|
||||||
title="FORMAT"
|
|
||||||
items={formatItems}
|
|
||||||
selectedOptionFormat={options.format}
|
|
||||||
config={config}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user