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-03-07 11:41:29 +05:30
|
|
|
import { isFunction } from 'lodash-es';
|
|
|
|
|
import {
|
|
|
|
|
ChevronDown,
|
|
|
|
|
ChevronRight,
|
|
|
|
|
Copy,
|
|
|
|
|
Eye,
|
|
|
|
|
EyeOff,
|
|
|
|
|
Trash2,
|
|
|
|
|
} from 'lucide-react';
|
2024-03-01 14:51:50 +05:30
|
|
|
import {
|
|
|
|
|
IBuilderQuery,
|
|
|
|
|
QueryFunctionProps,
|
|
|
|
|
} from 'types/api/queryBuilder/queryBuilderData';
|
2024-04-04 11:05:58 +05:30
|
|
|
import { DataSource } from 'types/common/queryBuilder';
|
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;
|
|
|
|
|
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;
|
2024-03-01 14:51:50 +05:30
|
|
|
onQueryFunctionsUpdates?: (functions: QueryFunctionProps[]) => void;
|
2024-02-12 21:42:56 +05:30
|
|
|
showDeleteButton: boolean;
|
2024-02-20 16:21:07 +05:30
|
|
|
isListViewPanel?: boolean;
|
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,
|
|
|
|
|
onDelete,
|
2024-03-07 11:41:29 +05:30
|
|
|
onCloneQuery,
|
2024-02-12 00:23:19 +05:30
|
|
|
onToggleVisibility,
|
|
|
|
|
onCollapseEntity,
|
2024-02-12 21:42:56 +05:30
|
|
|
showDeleteButton,
|
2024-03-01 14:51:50 +05:30
|
|
|
onQueryFunctionsUpdates,
|
|
|
|
|
isListViewPanel,
|
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-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>
|
|
|
|
|
<Button
|
|
|
|
|
value="search"
|
|
|
|
|
className="periscope-btn collapse"
|
|
|
|
|
onClick={onCollapseEntity}
|
|
|
|
|
>
|
|
|
|
|
{isCollapsed ? <ChevronRight size={16} /> : <ChevronDown size={16} />}
|
|
|
|
|
</Button>
|
|
|
|
|
<Button
|
|
|
|
|
value="query-builder"
|
|
|
|
|
className="periscope-btn visibility-toggle"
|
|
|
|
|
onClick={onToggleVisibility}
|
|
|
|
|
disabled={isListViewPanel}
|
|
|
|
|
>
|
|
|
|
|
{entityData.disabled ? <EyeOff size={16} /> : <Eye size={16} />}
|
|
|
|
|
</Button>
|
2024-03-01 14:51:50 +05:30
|
|
|
|
2024-03-07 11:41:29 +05:30
|
|
|
{entityType === 'query' && (
|
|
|
|
|
<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',
|
|
|
|
|
)}
|
|
|
|
|
>
|
|
|
|
|
{entityData.queryName}
|
|
|
|
|
</Button>
|
2024-02-12 00:23:19 +05:30
|
|
|
|
2024-03-07 11:41:29 +05:30
|
|
|
{showFunctions &&
|
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-03-07 11:41:29 +05:30
|
|
|
queryFunctions={query.functions}
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
{showDeleteButton && (
|
|
|
|
|
<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-02-20 16:21:07 +05:30
|
|
|
};
|