2023-11-13 13:54:31 +05:30
|
|
|
import { UploadOutlined } from '@ant-design/icons';
|
2023-11-15 18:25:02 +05:30
|
|
|
import {
|
|
|
|
|
Button,
|
|
|
|
|
Divider,
|
|
|
|
|
Input,
|
2024-01-09 14:19:23 +05:30
|
|
|
InputNumber,
|
2023-11-15 18:25:02 +05:30
|
|
|
Select,
|
|
|
|
|
Space,
|
|
|
|
|
Switch,
|
|
|
|
|
Typography,
|
|
|
|
|
} from 'antd';
|
2021-09-23 15:43:43 +05:30
|
|
|
import InputComponent from 'components/Input';
|
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';
|
|
|
|
|
import GraphTypes from 'container/NewDashboard/ComponentsSlider/menuItems';
|
2023-12-15 17:08:35 +05:30
|
|
|
import useCreateAlerts from 'hooks/queryBuilder/useCreateAlerts';
|
2023-05-19 13:14:32 +05:30
|
|
|
import { Dispatch, SetStateAction, useCallback } from 'react';
|
2023-11-13 13:54:31 +05:30
|
|
|
import { Widgets } from 'types/api/dashboard/getAll';
|
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';
|
2022-03-24 12:06:57 +05:30
|
|
|
import { Container, Title } from './styles';
|
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
|
|
|
|
|
|
|
|
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 (
|
|
|
|
|
<Container>
|
2023-03-07 12:25:59 +01:00
|
|
|
<Title>Panel Type</Title>
|
|
|
|
|
<Select
|
2023-03-07 17:49:18 +05:30
|
|
|
onChange={setGraphHandler}
|
2023-03-07 12:25:59 +01:00
|
|
|
value={selectedGraph}
|
2023-03-07 17:49:18 +05:30
|
|
|
disabled
|
2023-03-07 12:25:59 +01:00
|
|
|
style={{ width: '100%', marginBottom: 24 }}
|
|
|
|
|
>
|
|
|
|
|
{GraphTypes.map((item) => (
|
|
|
|
|
<Option key={item.name} value={item.name}>
|
|
|
|
|
{item.display}
|
|
|
|
|
</Option>
|
|
|
|
|
))}
|
|
|
|
|
</Select>
|
2021-09-23 15:43:43 +05:30
|
|
|
<Title>Panel Attributes</Title>
|
|
|
|
|
|
|
|
|
|
<InputComponent
|
|
|
|
|
label="Panel Title"
|
|
|
|
|
size="middle"
|
|
|
|
|
placeholder="Title"
|
|
|
|
|
labelOnTop
|
|
|
|
|
onChangeHandler={(event): void =>
|
|
|
|
|
onChangeHandler(setTitle, event.target.value)
|
|
|
|
|
}
|
|
|
|
|
value={title}
|
|
|
|
|
/>
|
|
|
|
|
|
2022-03-22 12:10:31 +05:30
|
|
|
<Title light="true">Description</Title>
|
2021-09-23 15:43:43 +05:30
|
|
|
|
|
|
|
|
<TextArea
|
|
|
|
|
placeholder="Write something describing the panel"
|
|
|
|
|
bordered
|
|
|
|
|
allowClear
|
|
|
|
|
value={description}
|
|
|
|
|
onChange={(event): void =>
|
|
|
|
|
onChangeHandler(setDescription, event.target.value)
|
|
|
|
|
}
|
|
|
|
|
/>
|
|
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
{allowFillSpans && (
|
|
|
|
|
<Space style={{ marginTop: 10 }} direction="vertical">
|
|
|
|
|
<Typography>Fill gaps</Typography>
|
2023-11-15 18:25:02 +05:30
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
<Switch
|
|
|
|
|
checked={isFillSpans}
|
|
|
|
|
onChange={(checked): void => setIsFillSpans(checked)}
|
|
|
|
|
/>
|
|
|
|
|
</Space>
|
|
|
|
|
)}
|
2023-11-15 18:25:02 +05:30
|
|
|
|
2024-02-20 16:21:07 +05:30
|
|
|
{allowPanelTimePreference && (
|
|
|
|
|
<Title light="true">Panel Time Preference</Title>
|
|
|
|
|
)}
|
2021-09-23 15:43:43 +05:30
|
|
|
|
2023-11-13 13:54:31 +05:30
|
|
|
<Space direction="vertical">
|
2024-02-20 16:21:07 +05:30
|
|
|
{allowPanelTimePreference && (
|
|
|
|
|
<TimePreference
|
|
|
|
|
{...{
|
|
|
|
|
selectedTime,
|
|
|
|
|
setSelectedTime,
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{allowYAxisUnit && (
|
|
|
|
|
<YAxisUnitSelector
|
|
|
|
|
defaultValue={yAxisUnit}
|
|
|
|
|
onSelect={setYAxisUnit}
|
|
|
|
|
fieldLabel={selectedGraphType === 'Value' ? 'Unit' : 'Y Axis Unit'}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
|
|
|
|
|
{allowCreateAlerts && (
|
2023-11-13 13:54:31 +05:30
|
|
|
<Button icon={<UploadOutlined />} onClick={onCreateAlertsHandler}>
|
|
|
|
|
Create Alerts from Queries
|
|
|
|
|
</Button>
|
|
|
|
|
)}
|
|
|
|
|
</Space>
|
2023-11-15 17:14:09 +05:30
|
|
|
|
2024-01-09 14:19:23 +05:30
|
|
|
{allowSoftMinMax && (
|
|
|
|
|
<>
|
|
|
|
|
<Divider />
|
|
|
|
|
<Typography.Text style={{ display: 'block', margin: '5px 0' }}>
|
|
|
|
|
Soft Min
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
<InputNumber
|
|
|
|
|
type="number"
|
|
|
|
|
value={softMin}
|
|
|
|
|
style={{ display: 'block', width: '100%' }}
|
|
|
|
|
onChange={softMinHandler}
|
|
|
|
|
/>
|
|
|
|
|
<Typography.Text style={{ display: 'block', margin: '5px 0' }}>
|
|
|
|
|
Soft Max
|
|
|
|
|
</Typography.Text>
|
|
|
|
|
<InputNumber
|
|
|
|
|
value={softMax}
|
|
|
|
|
type="number"
|
|
|
|
|
style={{ display: 'block', width: '100%' }}
|
|
|
|
|
onChange={softMaxHandler}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
|
|
|
|
|
2023-11-16 15:27:48 +05:30
|
|
|
{allowThreshold && (
|
|
|
|
|
<>
|
|
|
|
|
<Divider />
|
|
|
|
|
<ThresholdSelector
|
|
|
|
|
thresholds={thresholds}
|
|
|
|
|
setThresholds={setThresholds}
|
|
|
|
|
yAxisUnit={yAxisUnit}
|
|
|
|
|
selectedGraph={selectedGraph}
|
|
|
|
|
/>
|
|
|
|
|
</>
|
|
|
|
|
)}
|
2021-09-23 15:43:43 +05:30
|
|
|
</Container>
|
|
|
|
|
);
|
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;
|