2024-03-07 11:41:29 +05:30
|
|
|
/* eslint-disable sonarjs/no-duplicate-string */
|
2024-02-12 00:23:19 +05:30
|
|
|
import './QBEntityOptions.styles.scss';
|
|
|
|
|
|
2024-03-07 11:41:29 +05:30
|
|
|
import { Button, Col, Tooltip } from 'antd';
|
|
|
|
|
import { noop } from 'antd/lib/_util/warning';
|
2024-02-12 00:23:19 +05:30
|
|
|
import cx from 'classnames';
|
2024-09-06 10:24:47 +05:30
|
|
|
import ROUTES from 'constants/routes';
|
|
|
|
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
2024-03-07 11:41:29 +05:30
|
|
|
import { isFunction } from 'lodash-es';
|
|
|
|
|
import {
|
|
|
|
|
ChevronDown,
|
|
|
|
|
ChevronRight,
|
|
|
|
|
Copy,
|
|
|
|
|
Eye,
|
|
|
|
|
EyeOff,
|
|
|
|
|
Trash2,
|
|
|
|
|
} from 'lucide-react';
|
2024-09-06 10:24:47 +05:30
|
|
|
import { useLocation } from 'react-router-dom';
|
2025-08-06 00:16:20 +05:30
|
|
|
import { IBuilderQuery } from 'types/api/queryBuilder/queryBuilderData';
|
|
|
|
|
import { QueryFunction } from 'types/api/v5/queryRange';
|
2024-04-04 11:05:58 +05:30
|
|
|
import { DataSource } from 'types/common/queryBuilder';
|
2024-03-01 14:51:50 +05:30
|
|
|
|
2025-07-31 12:16:55 +05:30
|
|
|
import { DataSourceDropdown } from '..';
|
2024-03-01 14:51:50 +05:30
|
|
|
import QueryFunctions from '../QueryFunctions/QueryFunctions';
|
2024-02-12 00:23:19 +05:30
|
|
|
|
|
|
|
|
interface QBEntityOptionsProps {
|
2024-03-01 14:51:50 +05:30
|
|
|
query?: IBuilderQuery;
|
|
|
|
|
isMetricsDataSource?: boolean;
|
|
|
|
|
showFunctions?: boolean;
|
2024-02-12 00:23:19 +05:30
|
|
|
isCollapsed: boolean;
|
|
|
|
|
entityType: string;
|
|
|
|
|
entityData: any;
|
2025-07-31 12:16:55 +05:30
|
|
|
onDelete?: () => void;
|
2024-03-07 11:41:29 +05:30
|
|
|
onCloneQuery?: (type: string, query: IBuilderQuery) => void;
|
2024-02-12 00:23:19 +05:30
|
|
|
onToggleVisibility: () => void;
|
|
|
|
|
onCollapseEntity: () => void;
|
2025-08-06 00:16:20 +05:30
|
|
|
onQueryFunctionsUpdates?: (functions: QueryFunction[]) => void;
|
2025-07-31 12:16:55 +05:30
|
|
|
showDeleteButton?: boolean;
|
|
|
|
|
showCloneOption?: boolean;
|
2024-02-20 16:21:07 +05:30
|
|
|
isListViewPanel?: boolean;
|
2024-09-06 10:24:47 +05:30
|
|
|
index?: number;
|
2025-09-05 21:30:24 +05:30
|
|
|
showTraceOperator?: boolean;
|
|
|
|
|
hasTraceOperator?: boolean;
|
2025-07-31 12:16:55 +05:30
|
|
|
queryVariant?: 'dropdown' | 'static';
|
|
|
|
|
onChangeDataSource?: (value: DataSource) => void;
|
2024-02-12 00:23:19 +05:30
|
|
|
}
|
|
|
|
|
|
2025-07-31 12:16:55 +05:30
|
|
|
// eslint-disable-next-line sonarjs/cognitive-complexity
|
2024-02-12 00:23:19 +05:30
|
|
|
export default function QBEntityOptions({
|
2024-03-01 14:51:50 +05:30
|
|
|
query,
|
|
|
|
|
isMetricsDataSource,
|
2024-02-12 00:23:19 +05:30
|
|
|
isCollapsed,
|
2024-03-01 14:51:50 +05:30
|
|
|
showFunctions,
|
2024-02-12 00:23:19 +05:30
|
|
|
entityType,
|
|
|
|
|
entityData,
|
|
|
|
|
onToggleVisibility,
|
|
|
|
|
onCollapseEntity,
|
2024-03-01 14:51:50 +05:30
|
|
|
onQueryFunctionsUpdates,
|
|
|
|
|
isListViewPanel,
|
2025-07-31 12:16:55 +05:30
|
|
|
onDelete,
|
|
|
|
|
showDeleteButton,
|
|
|
|
|
showCloneOption,
|
|
|
|
|
onCloneQuery,
|
2024-09-06 10:24:47 +05:30
|
|
|
index,
|
2025-07-31 12:16:55 +05:30
|
|
|
queryVariant,
|
2025-09-05 21:30:24 +05:30
|
|
|
hasTraceOperator = false,
|
|
|
|
|
showTraceOperator = false,
|
2025-07-31 12:16:55 +05:30
|
|
|
onChangeDataSource,
|
2024-02-12 00:23:19 +05:30
|
|
|
}: QBEntityOptionsProps): JSX.Element {
|
2024-03-07 11:41:29 +05:30
|
|
|
const handleCloneEntity = (): void => {
|
|
|
|
|
if (isFunction(onCloneQuery)) {
|
|
|
|
|
onCloneQuery(entityType, entityData);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2024-09-06 10:24:47 +05:30
|
|
|
const { pathname } = useLocation();
|
|
|
|
|
|
|
|
|
|
const isLogsExplorerPage = pathname === ROUTES.LOGS_EXPLORER;
|
|
|
|
|
|
|
|
|
|
const { lastUsedQuery } = useQueryBuilder();
|
|
|
|
|
|
2024-04-04 11:05:58 +05:30
|
|
|
const isLogsDataSource = query?.dataSource === DataSource.LOGS;
|
|
|
|
|
|
2024-02-12 00:23:19 +05:30
|
|
|
return (
|
2024-03-07 11:41:29 +05:30
|
|
|
<Col span={24}>
|
|
|
|
|
<div className="qb-entity-options">
|
|
|
|
|
<div className="left-col-items">
|
|
|
|
|
<div className="options periscope-btn-group">
|
|
|
|
|
<Button.Group>
|
2024-05-22 16:00:49 +05:30
|
|
|
<Tooltip title={isCollapsed ? 'Uncollapse' : 'Collapse'}>
|
|
|
|
|
<Button
|
|
|
|
|
value="search"
|
|
|
|
|
className="periscope-btn collapse"
|
|
|
|
|
onClick={onCollapseEntity}
|
|
|
|
|
>
|
|
|
|
|
{isCollapsed ? <ChevronRight size={16} /> : <ChevronDown size={16} />}
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
<Tooltip title={entityData.disabled ? 'Show' : 'Hide'}>
|
|
|
|
|
<Button
|
|
|
|
|
value="query-builder"
|
|
|
|
|
className="periscope-btn visibility-toggle"
|
|
|
|
|
onClick={onToggleVisibility}
|
2025-09-05 21:30:24 +05:30
|
|
|
disabled={isListViewPanel && !showTraceOperator}
|
2024-05-22 16:00:49 +05:30
|
|
|
>
|
|
|
|
|
{entityData.disabled ? <EyeOff size={16} /> : <Eye size={16} />}
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2024-03-01 14:51:50 +05:30
|
|
|
|
2025-07-31 12:16:55 +05:30
|
|
|
{entityType === 'query' && showCloneOption && (
|
2024-03-07 11:41:29 +05:30
|
|
|
<Tooltip title={`Clone Query ${entityData.queryName}`}>
|
|
|
|
|
<Button className={cx('periscope-btn')} onClick={handleCloneEntity}>
|
|
|
|
|
<Copy size={14} />
|
|
|
|
|
</Button>
|
|
|
|
|
</Tooltip>
|
2024-03-01 14:51:50 +05:30
|
|
|
)}
|
2024-02-12 00:23:19 +05:30
|
|
|
|
2024-03-07 11:41:29 +05:30
|
|
|
<Button
|
|
|
|
|
className={cx(
|
|
|
|
|
'periscope-btn',
|
|
|
|
|
entityType === 'query' ? 'query-name' : 'formula-name',
|
2025-09-05 21:30:24 +05:30
|
|
|
query?.dataSource === DataSource.TRACES &&
|
|
|
|
|
(hasTraceOperator || (showTraceOperator && isListViewPanel))
|
|
|
|
|
? 'has-trace-operator'
|
|
|
|
|
: '',
|
2024-09-06 10:24:47 +05:30
|
|
|
isLogsExplorerPage && lastUsedQuery === index ? 'sync-btn' : '',
|
2024-03-07 11:41:29 +05:30
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{entityData.queryName}
|
|
|
|
|
</Button>
|
2024-02-12 00:23:19 +05:30
|
|
|
|
2025-07-31 12:16:55 +05:30
|
|
|
{queryVariant === 'dropdown' && (
|
|
|
|
|
<div className="query-data-source">
|
|
|
|
|
<DataSourceDropdown
|
|
|
|
|
onChange={(value): void => {
|
|
|
|
|
if (onChangeDataSource) {
|
|
|
|
|
onChangeDataSource(value);
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
value={query?.dataSource || DataSource.METRICS}
|
|
|
|
|
isListViewPanel={isListViewPanel}
|
|
|
|
|
className="query-data-source-dropdown"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2024-03-07 11:41:29 +05:30
|
|
|
{showFunctions &&
|
2025-07-31 12:16:55 +05:30
|
|
|
!isListViewPanel &&
|
2024-04-04 11:05:58 +05:30
|
|
|
(isMetricsDataSource || isLogsDataSource) &&
|
2024-03-07 11:41:29 +05:30
|
|
|
query &&
|
|
|
|
|
onQueryFunctionsUpdates && (
|
|
|
|
|
<QueryFunctions
|
2024-04-04 11:05:58 +05:30
|
|
|
query={query}
|
2024-04-18 11:17:28 +05:30
|
|
|
queryFunctions={query.functions || []}
|
|
|
|
|
key={query.functions?.toString()}
|
2024-03-07 11:41:29 +05:30
|
|
|
onChange={onQueryFunctionsUpdates}
|
2024-04-04 11:05:58 +05:30
|
|
|
maxFunctions={isLogsDataSource ? 1 : 3}
|
2024-03-07 11:41:29 +05:30
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Button.Group>
|
2024-03-01 14:51:50 +05:30
|
|
|
</div>
|
2024-03-07 11:41:29 +05:30
|
|
|
|
|
|
|
|
{isCollapsed && (
|
|
|
|
|
<div className="title">
|
|
|
|
|
<span className="entityType"> {entityType} </span> -{' '}
|
|
|
|
|
<span className="entityData"> {entityData.queryName} </span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-07-31 12:16:55 +05:30
|
|
|
{showDeleteButton && !isListViewPanel && (
|
2024-03-07 11:41:29 +05:30
|
|
|
<Button className="periscope-btn ghost" onClick={onDelete}>
|
|
|
|
|
<Trash2 size={14} />
|
|
|
|
|
</Button>
|
2024-02-12 00:23:19 +05:30
|
|
|
)}
|
|
|
|
|
</div>
|
2024-03-07 11:41:29 +05:30
|
|
|
</Col>
|
2024-02-12 00:23:19 +05:30
|
|
|
);
|
|
|
|
|
}
|
2024-02-20 16:21:07 +05:30
|
|
|
|
|
|
|
|
QBEntityOptions.defaultProps = {
|
|
|
|
|
isListViewPanel: false,
|
2024-03-01 14:51:50 +05:30
|
|
|
query: undefined,
|
|
|
|
|
isMetricsDataSource: false,
|
|
|
|
|
onQueryFunctionsUpdates: undefined,
|
|
|
|
|
showFunctions: false,
|
2024-03-07 11:41:29 +05:30
|
|
|
onCloneQuery: noop,
|
2024-09-06 10:24:47 +05:30
|
|
|
index: 0,
|
2025-07-31 12:16:55 +05:30
|
|
|
onDelete: noop,
|
|
|
|
|
showDeleteButton: false,
|
|
|
|
|
showCloneOption: true,
|
|
|
|
|
queryVariant: 'static',
|
|
|
|
|
onChangeDataSource: noop,
|
2025-09-05 21:30:24 +05:30
|
|
|
hasTraceOperator: false,
|
|
|
|
|
showTraceOperator: false,
|
2024-02-20 16:21:07 +05:30
|
|
|
};
|