2024-05-28 19:09:04 +05:30
|
|
|
/* eslint-disable jsx-a11y/no-static-element-interactions */
|
|
|
|
|
/* eslint-disable jsx-a11y/click-events-have-key-events */
|
|
|
|
|
import './RightContainer.styles.scss';
|
|
|
|
|
|
|
|
|
|
import { Input, InputNumber, Select, Space, Switch, Typography } from 'antd';
|
2022-03-22 12:10:31 +05:30
|
|
|
import TimePreference from 'components/TimePreferenceDropDown';
|
2023-07-26 15:06:07 +05:30
|
|
|
import { PANEL_TYPES } from 'constants/queryBuilder';
|
2024-04-09 13:36:19 +05:30
|
|
|
import GraphTypes, {
|
|
|
|
|
ItemsProps,
|
|
|
|
|
} from 'container/NewDashboard/ComponentsSlider/menuItems';
|
2023-12-15 17:08:35 +05:30
|
|
|
import useCreateAlerts from 'hooks/queryBuilder/useCreateAlerts';
|
2024-04-09 13:36:19 +05:30
|
|
|
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
2024-05-28 19:09:04 +05:30
|
|
|
import { ConciergeBell, Plus } from 'lucide-react';
|
2024-04-09 13:36:19 +05:30
|
|
|
import {
|
|
|
|
|
Dispatch,
|
|
|
|
|
SetStateAction,
|
|
|
|
|
useCallback,
|
|
|
|
|
useEffect,
|
|
|
|
|
useState,
|
|
|
|
|
} from 'react';
|
2023-11-13 13:54:31 +05:30
|
|
|
import { Widgets } from 'types/api/dashboard/getAll';
|
2024-04-09 13:36:19 +05:30
|
|
|
import { DataSource } from 'types/common/queryBuilder';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
import {
|
|
|
|
|
panelTypeVsCreateAlert,
|
|
|
|
|
panelTypeVsFillSpan,
|
|
|
|
|
panelTypeVsPanelTimePreferences,
|
|
|
|
|
panelTypeVsSoftMinMax,
|
|
|
|
|
panelTypeVsThreshold,
|
|
|
|
|
panelTypeVsYAxisUnit,
|
|
|
|
|
} from './constants';
|
2023-11-15 17:14:09 +05:30
|
|
|
import ThresholdSelector from './Threshold/ThresholdSelector';
|
|
|
|
|
import { ThresholdProps } from './Threshold/types';
|
2022-03-22 12:10:31 +05:30
|
|
|
import { timePreferance } from './timeItems';
|
|
|
|
|
import YAxisUnitSelector from './YAxisUnitSelector';
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
const { TextArea } = Input;
|
2023-03-07 12:25:59 +01:00
|
|
|
const { Option } = Select;
|
2022-03-22 12:10:31 +05:30
|
|
|
|
|
|
|
|
function RightContainer({
|
2021-09-23 15:43:43 +05:30
|
|
|
description,
|
|
|
|
|
setDescription,
|
|
|
|
|
setTitle,
|
|
|
|
|
title,
|
|
|
|
|
selectedGraph,
|
|
|
|
|
setSelectedTime,
|
|
|
|
|
selectedTime,
|
2022-03-15 15:18:33 +05:30
|
|
|
yAxisUnit,
|
|
|
|
|
setYAxisUnit,
|
2023-03-07 12:25:59 +01:00
|
|
|
setGraphHandler,
|
2023-11-15 17:14:09 +05:30
|
|
|
thresholds,
|
|
|
|
|
setThresholds,
|
2023-11-13 13:54:31 +05:30
|
|
|
selectedWidget,
|
2023-11-15 18:25:02 +05:30
|
|
|
isFillSpans,
|
|
|
|
|
setIsFillSpans,
|
2024-01-09 14:19:23 +05:30
|
|
|
softMax,
|
|
|
|
|
softMin,
|
|
|
|
|
setSoftMax,
|
|
|
|
|
setSoftMin,
|
2022-03-22 12:10:31 +05:30
|
|
|
}: RightContainerProps): JSX.Element {
|
2021-09-23 15:43:43 +05:30
|
|
|
const onChangeHandler = useCallback(
|
2023-05-19 13:14:32 +05:30
|
|
|
(setFunc: Dispatch<SetStateAction<string>>, value: string) => {
|
2021-09-23 15:43:43 +05:30
|
|
|
setFunc(value);
|
|
|
|
|
},
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const selectedGraphType =
|
|
|
|
|
GraphTypes.find((e) => e.name === selectedGraph)?.display || '';
|
|
|
|
|
|
2023-12-15 17:08:35 +05:30
|
|
|
const onCreateAlertsHandler = useCreateAlerts(selectedWidget);
|
2023-11-13 13:54:31 +05:30
|
|
|
|
2023-11-16 15:27:48 +05:30
|
|
|
const allowThreshold = panelTypeVsThreshold[selectedGraph];
|
2024-01-09 14:19:23 +05:30
|
|
|
const allowSoftMinMax = panelTypeVsSoftMinMax[selectedGraph];
|
2024-02-20 16:21:07 +05:30
|
|
|
const allowFillSpans = panelTypeVsFillSpan[selectedGraph];
|
|
|
|
|
const allowYAxisUnit = panelTypeVsYAxisUnit[selectedGraph];
|
|
|
|
|
const allowCreateAlerts = panelTypeVsCreateAlert[selectedGraph];
|
|
|
|
|
const allowPanelTimePreference =
|
|
|
|
|
panelTypeVsPanelTimePreferences[selectedGraph];
|
2024-01-09 14:19:23 +05:30
|
|
|
|
2024-04-09 13:36:19 +05:30
|
|
|
const { currentQuery } = useQueryBuilder();
|
|
|
|
|
|
|
|
|
|
const [graphTypes, setGraphTypes] = useState<ItemsProps[]>(GraphTypes);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const queryContainsMetricsDataSource = currentQuery.builder.queryData.some(
|
|
|
|
|
(query) => query.dataSource === DataSource.METRICS,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (queryContainsMetricsDataSource) {
|
|
|
|
|
setGraphTypes((prev) =>
|
|
|
|
|
prev.filter((graph) => graph.name !== PANEL_TYPES.LIST),
|
|
|
|
|
);
|
|
|
|
|
} else {
|
|
|
|
|
setGraphTypes(GraphTypes);
|
|
|
|
|
}
|
|
|
|
|
}, [currentQuery]);
|
|
|
|
|
|
2024-01-09 14:19:23 +05:30
|
|
|
const softMinHandler = useCallback(
|
|
|
|
|
(value: number | null) => {
|
|
|
|
|
setSoftMin(value);
|
|
|
|
|
},
|
|
|
|
|
[setSoftMin],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const softMaxHandler = useCallback(
|
|
|
|
|
(value: number | null) => {
|
|
|
|
|
setSoftMax(value);
|
|
|
|
|
},
|
|
|
|
|
[setSoftMax],
|
|
|
|
|
);
|
2023-11-16 15:27:48 +05:30
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
return (
|
2024-05-28 19:09:04 +05:30
|
|
|
<div className="right-container">
|
|
|
|
|
<section className="header">
|
|
|
|
|
<div className="purple-dot" />
|
|
|
|
|
<Typography.Text className="header-text">Panel details</Typography.Text>
|
|
|
|
|
</section>
|
|
|
|
|
<section className="name-description">
|
|
|
|
|
<Typography.Text className="typography">Name</Typography.Text>
|
|
|
|
|
<Input
|
|
|
|
|
placeholder="Enter the panel name here..."
|
|
|
|
|
onChange={(event): void => onChangeHandler(setTitle, event.target.value)}
|
|
|
|
|
value={title}
|
|
|
|
|
rootClassName="name-input"
|
|
|
|
|
/>
|
|
|
|
|
<Typography.Text className="typography">Description</Typography.Text>
|
|
|
|
|
<TextArea
|
|
|
|
|
placeholder="Enter the panel description here..."
|
|
|
|
|
bordered
|
|
|
|
|
allowClear
|
|
|
|
|
value={description}
|
|
|
|
|
onChange={(event): void =>
|
|
|
|
|
onChangeHandler(setDescription, event.target.value)
|
|
|
|
|
}
|
|
|
|
|
rootClassName="description-input"
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
<section className="panel-config">
|
|
|
|
|
<Typography.Text className="typography">Panel Type</Typography.Text>
|
|
|
|
|
<Select
|
|
|
|
|
onChange={setGraphHandler}
|
|
|
|
|
value={selectedGraph}
|
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
|
className="panel-type-select"
|
|
|
|
|
>
|
|
|
|
|
{graphTypes.map((item) => (
|
|
|
|
|
<Option key={item.name} value={item.name}>
|
|
|
|
|
<div className="select-option">
|
|
|
|
|
<div className="icon">{item.icon}</div>
|
|
|
|
|
<Typography.Text className="display">{item.display}</Typography.Text>
|
|
|
|
|
</div>
|
|
|
|
|
</Option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
|
|
|
|
|
|
|
|
|
{allowFillSpans && (
|
|
|
|
|
<Space className="fill-gaps">
|
|
|
|
|
<Typography className="fill-gaps-text">Fill gaps</Typography>
|
|
|
|
|
<Switch
|
|
|
|
|
checked={isFillSpans}
|
|
|
|
|
size="small"
|
|
|
|
|
onChange={(checked): void => setIsFillSpans(checked)}
|
|
|
|
|
/>
|
|
|
|
|
</Space>
|
|
|
|
|
)}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
{allowPanelTimePreference && (
|
2024-05-28 19:09:04 +05:30
|
|
|
<>
|
|
|
|
|
<Typography.Text className="panel-time-text">
|
|
|
|
|
Panel Time Preference
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
<TimePreference
|
|
|
|
|
{...{
|
|
|
|
|
selectedTime,
|
|
|
|
|
setSelectedTime,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
2024-02-20 16:21:07 +05:30
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{allowYAxisUnit && (
|
|
|
|
|
<YAxisUnitSelector
|
|
|
|
|
defaultValue={yAxisUnit}
|
|
|
|
|
onSelect={setYAxisUnit}
|
|
|
|
|
fieldLabel={selectedGraphType === 'Value' ? 'Unit' : 'Y Axis Unit'}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2024-05-28 19:09:04 +05:30
|
|
|
{allowSoftMinMax && (
|
|
|
|
|
<section className="soft-min-max">
|
|
|
|
|
<section className="container">
|
|
|
|
|
<Typography.Text className="text">Soft Min</Typography.Text>
|
|
|
|
|
<InputNumber
|
|
|
|
|
type="number"
|
|
|
|
|
value={softMin}
|
|
|
|
|
onChange={softMinHandler}
|
|
|
|
|
rootClassName="input"
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
<section className="container">
|
|
|
|
|
<Typography.Text className="text">Soft Max</Typography.Text>
|
|
|
|
|
<InputNumber
|
|
|
|
|
value={softMax}
|
|
|
|
|
type="number"
|
|
|
|
|
rootClassName="input"
|
|
|
|
|
onChange={softMaxHandler}
|
|
|
|
|
/>
|
|
|
|
|
</section>
|
|
|
|
|
</section>
|
2023-11-13 13:54:31 +05:30
|
|
|
)}
|
2024-05-28 19:09:04 +05:30
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
{allowCreateAlerts && (
|
|
|
|
|
<section className="alerts" onClick={onCreateAlertsHandler}>
|
|
|
|
|
<div className="left-section">
|
|
|
|
|
<ConciergeBell size={14} className="bell-icon" />
|
|
|
|
|
<Typography.Text className="alerts-text">Alerts</Typography.Text>
|
|
|
|
|
</div>
|
|
|
|
|
<Plus size={14} className="plus-icon" />
|
|
|
|
|
</section>
|
2024-01-09 14:19:23 +05:30
|
|
|
)}
|
|
|
|
|
|
2023-11-16 15:27:48 +05:30
|
|
|
{allowThreshold && (
|
2024-05-28 19:09:04 +05:30
|
|
|
<section>
|
2023-11-16 15:27:48 +05:30
|
|
|
<ThresholdSelector
|
|
|
|
|
thresholds={thresholds}
|
|
|
|
|
setThresholds={setThresholds}
|
|
|
|
|
yAxisUnit={yAxisUnit}
|
|
|
|
|
selectedGraph={selectedGraph}
|
|
|
|
|
/>
|
2024-05-28 19:09:04 +05:30
|
|
|
</section>
|
2023-11-16 15:27:48 +05:30
|
|
|
)}
|
2024-05-28 19:09:04 +05:30
|
|
|
</div>
|
2021-09-23 15:43:43 +05:30
|
|
|
);
|
2022-03-22 12:10:31 +05:30
|
|
|
}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
interface RightContainerProps {
|
|
|
|
|
title: string;
|
2023-05-19 13:14:32 +05:30
|
|
|
setTitle: Dispatch<SetStateAction<string>>;
|
2021-09-23 15:43:43 +05:30
|
|
|
description: string;
|
2023-05-19 13:14:32 +05:30
|
|
|
setDescription: Dispatch<SetStateAction<string>>;
|
2021-09-23 15:43:43 +05:30
|
|
|
stacked: boolean;
|
2023-05-19 13:14:32 +05:30
|
|
|
setStacked: Dispatch<SetStateAction<boolean>>;
|
2021-09-23 15:43:43 +05:30
|
|
|
opacity: string;
|
2023-05-19 13:14:32 +05:30
|
|
|
setOpacity: Dispatch<SetStateAction<string>>;
|
2021-09-23 15:43:43 +05:30
|
|
|
selectedNullZeroValue: string;
|
2023-05-19 13:14:32 +05:30
|
|
|
setSelectedNullZeroValue: Dispatch<SetStateAction<string>>;
|
2023-07-26 15:06:07 +05:30
|
|
|
selectedGraph: PANEL_TYPES;
|
2023-05-19 13:14:32 +05:30
|
|
|
setSelectedTime: Dispatch<SetStateAction<timePreferance>>;
|
2021-09-23 15:43:43 +05:30
|
|
|
selectedTime: timePreferance;
|
2022-03-15 15:18:33 +05:30
|
|
|
yAxisUnit: string;
|
2023-05-19 13:14:32 +05:30
|
|
|
setYAxisUnit: Dispatch<SetStateAction<string>>;
|
2023-07-26 15:06:07 +05:30
|
|
|
setGraphHandler: (type: PANEL_TYPES) => void;
|
2023-11-15 17:14:09 +05:30
|
|
|
thresholds: ThresholdProps[];
|
|
|
|
|
setThresholds: Dispatch<SetStateAction<ThresholdProps[]>>;
|
2023-11-13 13:54:31 +05:30
|
|
|
selectedWidget?: Widgets;
|
2023-11-15 18:25:02 +05:30
|
|
|
isFillSpans: boolean;
|
|
|
|
|
setIsFillSpans: Dispatch<SetStateAction<boolean>>;
|
2024-01-09 14:19:23 +05:30
|
|
|
softMin: number | null;
|
|
|
|
|
softMax: number | null;
|
|
|
|
|
setSoftMin: Dispatch<SetStateAction<number | null>>;
|
|
|
|
|
setSoftMax: Dispatch<SetStateAction<number | null>>;
|
2021-09-23 15:43:43 +05:30
|
|
|
}
|
|
|
|
|
|
2023-11-13 13:54:31 +05:30
|
|
|
RightContainer.defaultProps = {
|
|
|
|
|
selectedWidget: undefined,
|
|
|
|
|
};
|
|
|
|
|
|
2021-09-23 15:43:43 +05:30
|
|
|
export default RightContainer;
|