Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Panel] Fix panel resizing and date picker bugs #364

Merged
merged 5 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/components/custom_panels/custom_panel_view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ export const CustomPanelView = (props: CustomPanelViewProps) => {
timeProps.end,
recentlyUsedRanges
);
setStartTime(timeProps.start);
setEndTime(timeProps.end);
dispatch(updatePanel({ ...panel, timeRange: { from: timeProps.start, to: timeProps.end } }));

setRecentlyUsedRanges(updatedRanges.slice(0, 9));
Expand Down
27 changes: 16 additions & 11 deletions public/components/custom_panels/custom_panel_view_so.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/* // eslint-disable no-console */
/* eslint-disable react-hooks/exhaustive-deps */

import { useCallback } from 'react';
import {
EuiBreadcrumb,
EuiButton,
Expand Down Expand Up @@ -298,11 +299,11 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
setIsEditing(true);
};

const applyEdits = () => {
console.log('applyEdits', panel);
const applyEdits = useCallback(() => {
dispatch(updatePanel(panel));
setIsEditing(false);
};
setEditActionType('save');
}, [panel]);

const cancelEdit = () => {
console.log('cancelEdits');
Expand Down Expand Up @@ -374,7 +375,7 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
return;
};

const onRefreshFilters = (start: ShortDate, end: ShortDate) => {
const onRefreshFilters = async (start: ShortDate, end: ShortDate) => {
if (!isDateValid(convertDateTime(start), convertDateTime(end, false), setToast)) {
return;
}
Expand All @@ -384,13 +385,17 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
return;
}

const panelFilterBody = {
panelId,
query: pplFilterValue,
language: 'ppl',
to: end,
from: start,
};
await coreRefs.savedObjectsClient?.update('observability-panel', panelId, {
...panel,
timeRange: {
to: end,
from: start,
},
queryFilter: {
query: pplFilterValue,
language: 'ppl',
},
});

setOnRefresh(!onRefresh);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
*/
/* eslint-disable react-hooks/exhaustive-deps */

import _ from 'lodash';
import React, { useEffect, useState } from 'react';
import _, { forEach } from 'lodash';
import React, { useCallback, useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import { Layout, Layouts, Responsive, WidthProvider } from 'react-grid-layout';
import useObservable from 'react-use/lib/useObservable';
import { CoreStart } from '../../../../../../../src/core/public';
import { VisualizationContainer } from '../visualization_container';
import { VisualizationType } from '../../../../../common/types/custom_panels';
import { CUSTOM_PANELS_API_PREFIX } from '../../../../../common/constants/custom_panels';
import './panel_grid.scss';
import { mergeLayoutAndVisualizations } from '../../helpers/utils';
import { coreRefs } from '../../../../framework/core_refs';
import { selectPanel } from '../../redux/panel_slice';

// HOC container to provide dynamic width for Grid layout
const ResponsiveGridLayout = WidthProvider(Responsive);
Expand Down Expand Up @@ -73,6 +74,8 @@ export const PanelGridSO = (props: PanelGridProps) => {
showFlyout,
editActionType,
} = props;

const panel = useSelector(selectPanel);
const [currentLayout, setCurrentLayout] = useState<Layout[]>([]);
const [postEditLayout, setPostEditLayout] = useState<Layout[]>([]);
const [gridData, setGridData] = useState(panelVisualizations.map(() => <></>));
Expand Down Expand Up @@ -128,27 +131,40 @@ export const PanelGridSO = (props: PanelGridProps) => {
const newVisualizationList = _.reject(panelVisualizations, {
id: visualizationId,
});
console.log('removeVisualization', newVisualizationList);
mergeLayoutAndVisualizations(postEditLayout, newVisualizationList, setPanelVisualizations);
};

// Save Visualization Layouts when not in edit mode anymore (after users saves the panel)
const saveVisualizationLayouts = async (panelID: string, visualizationParams: any) => {
return http
.put(`${CUSTOM_PANELS_API_PREFIX}/visualizations/edit`, {
body: JSON.stringify({
panelId: panelID,
visualizationParams,
}),
})
.then(async (res) => {
setPanelVisualizations(res.visualizations);
})
.catch((err) => {
console.error(err);
const updateLayout = (visualizations, newLayouts) => {
const newVisualizations = [];
forEach(visualizations, (viz) => {
let newviz = { ...viz };
forEach(newLayouts, (nwlyt) => {
if (viz.id === nwlyt.i) {
newviz = {
...newviz,
...nwlyt,
};
return;
}
});
newVisualizations.push({ ...newviz });
});
return newVisualizations;
};

// Save Visualization Layouts when not in edit mode anymore (after users saves the panel)
const saveVisualizationLayouts = useCallback(
async (panelID: string, visualizationParams: any) => {
const newVisualizations = updateLayout(panel.visualizations, visualizationParams);
const updateRes = await coreRefs.savedObjectsClient?.update('observability-panel', panelID, {
...panel,
visualizations: newVisualizations,
});
setPanelVisualizations(updateRes?.attributes?.visualizations || []);
},
[panel]
);

// Update layout whenever user edit gets completed
useEffect(() => {
if (editMode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ exports[`<NoteTable /> spec renders the component 1`] = `
>
<a
class="euiButton euiButton--primary euiButton--fill"
href="#/notebooks/create"
href="#/create"
rel="noreferrer"
>
<span
Expand Down Expand Up @@ -429,7 +429,7 @@ exports[`<NoteTable /> spec renders the component 1`] = `
>
<a
class="euiLink euiLink--primary"
href="#/notebooks/id-0"
href="#/id-0"
rel="noreferrer"
>
path-0
Expand Down Expand Up @@ -504,7 +504,7 @@ exports[`<NoteTable /> spec renders the component 1`] = `
>
<a
class="euiLink euiLink--primary"
href="#/notebooks/id-1"
href="#/id-1"
rel="noreferrer"
>
path-1
Expand Down Expand Up @@ -579,7 +579,7 @@ exports[`<NoteTable /> spec renders the component 1`] = `
>
<a
class="euiLink euiLink--primary"
href="#/notebooks/id-2"
href="#/id-2"
rel="noreferrer"
>
path-2
Expand Down Expand Up @@ -654,7 +654,7 @@ exports[`<NoteTable /> spec renders the component 1`] = `
>
<a
class="euiLink euiLink--primary"
href="#/notebooks/id-3"
href="#/id-3"
rel="noreferrer"
>
path-3
Expand Down Expand Up @@ -729,7 +729,7 @@ exports[`<NoteTable /> spec renders the component 1`] = `
>
<a
class="euiLink euiLink--primary"
href="#/notebooks/id-4"
href="#/id-4"
rel="noreferrer"
>
path-4
Expand Down Expand Up @@ -1025,7 +1025,7 @@ exports[`<NoteTable /> spec renders the empty component 1`] = `
>
<a
class="euiButton euiButton--primary euiButton--fill"
href="#/notebooks/create"
href="#/create"
rel="noreferrer"
>
<span
Expand Down
Loading