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

fixes edit mode callback bug in Saved Object Panels #420

Merged
merged 4 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
32 changes: 9 additions & 23 deletions public/components/custom_panels/custom_panel_view_so.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,14 @@ import { PanelGridSO } from './panel_modules/panel_grid/panel_grid_so';
import { VisaulizationFlyoutSO } from './panel_modules/visualization_flyout/visualization_flyout_so';
import {
clonePanel,
createPanel,
deletePanels,
fetchPanel,
newPanelTemplate,
selectPanel,
setPanel,
setPanelEt,
setPanelId,
setPanelSt,
updatePanel,
} from './redux/panel_slice';
import PPLService from '../../services/requests/ppl';
import DSLService from '../../services/requests/dsl';

/*
* "CustomPanelsView" module used to render an Observability Dashboard
Expand Down Expand Up @@ -277,21 +274,10 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
};

// toggle between panel edit mode

const startEdit = () => {
setIsEditing(true);
};

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

const cancelEdit = () => {
console.log('cancelEdits');
dispatch(fetchPanel(panelId));
setIsEditing(false);
const editPanel = (editType: string) => {
setIsEditing(!isEditing);
if (editType === 'cancel') dispatch(fetchPanel(panelId));
setEditActionType(editType);
};

const closeFlyout = () => {
Expand Down Expand Up @@ -407,14 +393,14 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
data-test-subj="cancelPanelButton"
iconType="cross"
color="danger"
onClick={cancelEdit}
onClick={() => editPanel('cancel')}
>
Cancel
</EuiButton>
);

const saveButton = (
<EuiButton data-test-subj="savePanelButton" iconType="save" onClick={applyEdits}>
<EuiButton data-test-subj="savePanelButton" iconType="save" onClick={() => editPanel('save')}>
Save
</EuiButton>
);
Expand All @@ -423,7 +409,7 @@ export const CustomPanelViewSO = (props: CustomPanelViewProps) => {
<EuiButton
data-test-subj="editPanelButton"
iconType="pencil"
onClick={startEdit}
onClick={() => editPanel('edit')}
disabled={editDisabled}
>
Edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,17 +153,14 @@ export const PanelGridSO = (props: PanelGridProps) => {
};

// 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]
);
const saveVisualizationLayouts = async (panelID: string, visualizationParams: any) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is this change doing/what bug?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Saving after edit in SOPanels still has drag/drop control on visualizations
  • Resize and drag visualization workflow post edit and save doesn't work in SOpanels, when a user hits the edit followed by save button, before response is made by the callback.

const newVisualizations = updateLayout(panel.visualizations, visualizationParams);
const updateRes = await coreRefs.savedObjectsClient?.update('observability-panel', panelID, {
...panel,
visualizations: newVisualizations,
});
setPanelVisualizations(updateRes?.attributes?.visualizations || []);
};

// Update layout whenever user edit gets completed
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ import {
EuiToolTip,
ShortDate,
} from '@elastic/eui';
import _, { isError } from 'lodash';
import _ from 'lodash';
import React, { useEffect, useState } from 'react';
import { v4 as uuidv4 } from 'uuid';
import { useDispatch, useSelector } from 'react-redux';
import { FlyoutContainers } from '../../../common/flyout_containers';
import {
Expand All @@ -46,23 +45,17 @@ import {
import { convertDateTime } from '../../helpers/utils';
import PPLService from '../../../../services/requests/ppl';
import { CoreStart } from '../../../../../../../src/core/public';
import { CUSTOM_PANELS_API_PREFIX } from '../../../../../common/constants/custom_panels';
import {
BoxType,
PplResponse,
PPLResponse,
SavedVisualizationType,
VisualizationType,
VizContainerError,
} from '../../../../../common/types/custom_panels';
import './visualization_flyout.scss';
import { uiSettingsService } from '../../../../../common/utils';
import { ILegacyScopedClusterClient } from '../../../../../../../src/core/server';
import { replaceVizInPanel, selectPanel } from '../../redux/panel_slice';
import { SavedObjectsActions } from '../../../../services/saved_objects/saved_object_client/saved_objects_actions';
import {
ObservabilitySavedObject,
ObservabilitySavedVisualization,
} from '../../../../services/saved_objects/saved_object_client/types';
import { ObservabilitySavedVisualization } from '../../../../services/saved_objects/saved_object_client/types';
import { SAVED_VISUALIZATION } from '../../../../../common/constants/explorer';

/*
Expand Down Expand Up @@ -128,7 +121,7 @@ export const VisaulizationFlyoutSO = ({
const [newVisualizationTimeField, setNewVisualizationTimeField] = useState('');
const [previewMetaData, setPreviewMetaData] = useState<SavedVisualizationType>();
const [pplQuery, setPPLQuery] = useState('');
const [previewData, setPreviewData] = useState<PplResponse>({} as PplResponse);
const [previewData, setPreviewData] = useState<PPLResponse>({} as PPLResponse);
const [previewArea, setPreviewArea] = useState(<></>);
const [previewLoading, setPreviewLoading] = useState(false);
const [isPreviewError, setIsPreviewError] = useState({} as VizContainerError);
Expand Down Expand Up @@ -189,43 +182,11 @@ export const VisaulizationFlyoutSO = ({
if (!isInputValid()) return;

if (isFlyoutReplacement) {
// http
// .post(`${CUSTOM_PANELS_API_PREFIX}/visualizations/replace`, {
// body: JSON.stringify({
// panelId,
// savedVisualizationId: selectValue,
// oldVisualizationId: replaceVisualizationId,
// }),
// })
// .then(async (res) => {
// setPanelVisualizations(res.visualizations);
// setToast(`Visualization ${newVisualizationTitle} successfully added!`, 'success');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the updated Toast is merged, these setToast should be re-instated wherever we see them in PRs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pjfitzgibbons does your code re-instate the toast? If so we should get this once it is merged

Copy link
Member Author

@ps48 ps48 Apr 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the toast reinstatement should go here: #415

// })
// .catch((err) => {
// setToast(`Error in adding ${newVisualizationTitle} visualization to the panel`, 'danger');
ps48 marked this conversation as resolved.
Show resolved Hide resolved
// console.error(err);
// });
dispatch(replaceVizInPanel(panel, replaceVisualizationId, selectValue));
} else {
const visualizationsWithNewPanel = addVisualizationPanel({
savedVisualizationId: selectValue,
});

// http
// .post(`${CUSTOM_PANELS_API_PREFIX}/visualizations`, {
// body: JSON.stringify({
// panelId,
// savedVisualizationId: selectValue,
// }),
// })
// .then(async (res) => {
// setPanelVisualizations(res.visualizations);
// setToast(`Visualization ${newVisualizationTitle} successfully added!`, 'success');
ps48 marked this conversation as resolved.
Show resolved Hide resolved
// })
// .catch((err) => {
// setToast(`Error in adding ${newVisualizationTitle} visualization to the panel`, 'danger');
ps48 marked this conversation as resolved.
Show resolved Hide resolved
// console.error(err);
// });
}
closeFlyout();
};
Expand Down