diff --git a/frontend/src/container/NewWidget/RightContainer/index.tsx b/frontend/src/container/NewWidget/RightContainer/index.tsx index f1c9460fd0..eb80d3c62f 100644 --- a/frontend/src/container/NewWidget/RightContainer/index.tsx +++ b/frontend/src/container/NewWidget/RightContainer/index.tsx @@ -1,8 +1,10 @@ -import { Input } from 'antd'; +import { Input, Select } from 'antd'; import InputComponent from 'components/Input'; import TimePreference from 'components/TimePreferenceDropDown'; import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider'; -import GraphTypes from 'container/NewDashboard/ComponentsSlider/menuItems'; +import GraphTypes, { + ITEMS, +} from 'container/NewDashboard/ComponentsSlider/menuItems'; import React, { useCallback } from 'react'; import { Container, Title } from './styles'; @@ -10,6 +12,7 @@ import { timePreferance } from './timeItems'; import YAxisUnitSelector from './YAxisUnitSelector'; const { TextArea } = Input; +const { Option } = Select; function RightContainer({ description, @@ -21,6 +24,7 @@ function RightContainer({ selectedTime, yAxisUnit, setYAxisUnit, + setGraphHandler, }: RightContainerProps): JSX.Element { const onChangeHandler = useCallback( (setFunc: React.Dispatch>, value: string) => { @@ -34,14 +38,18 @@ function RightContainer({ return ( - - + Panel Type + Panel Attributes >; + setGraphHandler: (type: ITEMS) => void; } export default RightContainer; diff --git a/frontend/src/container/NewWidget/index.tsx b/frontend/src/container/NewWidget/index.tsx index 269d6e3666..c9ccd7c1f9 100644 --- a/frontend/src/container/NewWidget/index.tsx +++ b/frontend/src/container/NewWidget/index.tsx @@ -1,6 +1,7 @@ import { Button, Modal, Typography } from 'antd'; import ROUTES from 'constants/routes'; import { GRAPH_TYPES } from 'container/NewDashboard/ComponentsSlider'; +import { ITEMS } from 'container/NewDashboard/ComponentsSlider/menuItems'; import { getDashboardVariables } from 'lib/dashbaordVariables/getDashboardVariables'; import history from 'lib/history'; import { DashboardWidgetPageParams } from 'pages/DashboardWidget'; @@ -86,6 +87,7 @@ function NewWidget({ const [saveModal, setSaveModal] = useState(false); const [hasUnstagedChanges, setHasUnstagedChanges] = useState(false); + const [graphType, setGraphType] = useState(selectedGraph); const getSelectedTime = useCallback( () => TimeItems.find( @@ -112,6 +114,7 @@ function NewWidget({ yAxisUnit, widgetId: query.get('widgetId') || '', dashboardId, + graphType, }); }, [ saveSettingOfPanel, @@ -125,6 +128,7 @@ function NewWidget({ yAxisUnit, query, dashboardId, + graphType, ]); const onClickDiscardHandler = useCallback(() => { @@ -140,7 +144,7 @@ function NewWidget({ query: selectedWidget?.query, selectedTime: selectedTime.enum, widgetId: selectedWidget?.id || '', - graphType: selectedGraph, + graphType, globalSelectedInterval, variables: getDashboardVariables(), }); @@ -149,11 +153,18 @@ function NewWidget({ selectedWidget?.query, selectedTime.enum, selectedWidget?.id, - selectedGraph, getQueryResults, globalSelectedInterval, + graphType, ]); + const setGraphHandler = (type: ITEMS): void => { + const params = new URLSearchParams(search); + params.set('graphType', type); + history.push({ search: params.toString() }); + setGraphType(type); + }; + useEffect(() => { getQueryResult(); }, [getQueryResult]); @@ -173,13 +184,14 @@ function NewWidget({ ) => void) => // eslint-disable-next-line sonarjs/cognitive-complexity async (dispatch: Dispatch): Promise => { try { const dashboard = store.getState(); - const search = new URLSearchParams(history.location.search); const selectedDashboard = dashboard.dashboards.dashboards.find( (e) => e.uuid === uuid, @@ -105,7 +106,7 @@ export const SaveDashboard = ({ title: updatedTitle, timePreferance: updatedtimePreferance, yAxisUnit: updatedYAxisUnit, - panelTypes: search.get('graphType') as Widgets['panelTypes'], + panelTypes: graphType, queryData: { ...selectedWidget.queryData, }, @@ -151,4 +152,5 @@ export interface SaveDashboardProps { widgetId: Widgets['id']; dashboardId: string; yAxisUnit: Widgets['yAxisUnit']; + graphType: ITEMS; }