Skip to content

Commit

Permalink
[8.12] [Lens] fixed equality check for visualization (#172685) (#172790)
Browse files Browse the repository at this point in the history
# Backport

This will backport the following commits from `main` to `8.12`:
- [[Lens] fixed equality check for visualization
(#172685)](#172685)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Marta
Bondyra","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-12-07T09:31:38Z","message":"[Lens]
fixed equality check for visualization (#172685)\n\n##
Summary\r\n\r\nFixed an equality check bug for attributesChanged
calculation. It wasn't\r\ntaking into account that visualization can
also have references (to\r\ndataview for annotations) and a custom
isEqual
function.","sha":"9e41850a352a24446a0c49bacffccf93df2547fb","branchLabelMapping":{"^v8.13.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Visualizations","release_note:skip","Feature:Lens","v8.12.0","v8.13.0"],"number":172685,"url":"https://github.com/elastic/kibana/pull/172685","mergeCommit":{"message":"[Lens]
fixed equality check for visualization (#172685)\n\n##
Summary\r\n\r\nFixed an equality check bug for attributesChanged
calculation. It wasn't\r\ntaking into account that visualization can
also have references (to\r\ndataview for annotations) and a custom
isEqual
function.","sha":"9e41850a352a24446a0c49bacffccf93df2547fb"}},"sourceBranch":"main","suggestedTargetBranches":["8.12"],"targetPullRequestStates":[{"branch":"8.12","label":"v8.12.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.13.0","labelRegex":"^v8.13.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/172685","number":172685,"mergeCommit":{"message":"[Lens]
fixed equality check for visualization (#172685)\n\n##
Summary\r\n\r\nFixed an equality check bug for attributesChanged
calculation. It wasn't\r\ntaking into account that visualization can
also have references (to\r\ndataview for annotations) and a custom
isEqual function.","sha":"9e41850a352a24446a0c49bacffccf93df2547fb"}}]}]
BACKPORT-->

Co-authored-by: Marta Bondyra <[email protected]>
  • Loading branch information
kibanamachine and mbondyra authored Dec 7, 2023
1 parent d875875 commit ff04f68
Showing 1 changed file with 30 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ export function LensEditConfigurationFlyout({
const datasourceState = attributes.state.datasourceStates[datasourceId];
const activeVisualization = visualizationMap[attributes.visualizationType];
const activeDatasource = datasourceMap[datasourceId];
const { datasourceStates, visualization, isLoading } = useLensSelector((state) => state.lens);
const { datasourceStates, visualization, isLoading, annotationGroups } = useLensSelector(
(state) => state.lens
);
const framePublicAPI = useLensSelector((state) => selectFramePublicAPI(state, datasourceMap));
const suggestsLimitedColumns = activeDatasource?.suggestsLimitedColumns?.(datasourceState);

Expand Down Expand Up @@ -113,10 +115,33 @@ export function LensEditConfigurationFlyout({
: false;

const visualizationState = visualization.state;
return (
!isEqual(visualizationState, previousAttrs.state.visualization) || !datasourceStatesAreSame
);
}, [attributes.references, datasourceId, datasourceMap, datasourceStates, visualization.state]);
const customIsEqual = visualizationMap[previousAttrs.visualizationType]?.isEqual;
const visualizationStateIsEqual = customIsEqual
? (() => {
try {
return customIsEqual(
previousAttrs.state.visualization,
previousAttrs.references,
visualizationState,
attributes.references,
annotationGroups
);
} catch (err) {
return false;
}
})()
: isEqual(visualizationState, previousAttrs.state.visualization);

return !visualizationStateIsEqual || !datasourceStatesAreSame;
}, [
attributes.references,
datasourceId,
datasourceMap,
datasourceStates,
visualizationMap,
annotationGroups,
visualization.state,
]);

const onCancel = useCallback(() => {
const previousAttrs = previousAttributes.current;
Expand Down

0 comments on commit ff04f68

Please sign in to comment.