Skip to content

Commit

Permalink
fix: plugin - add deep checks to determine whether to redraw chart (#284
Browse files Browse the repository at this point in the history
)

It is currently necessary to do a deep equality check on the config object and the style object to determine whether a chart should be re-rendered/re-created.

[DHIS2-6597]
  • Loading branch information
neeilya authored and jenniferarnesen committed Apr 30, 2019
1 parent e76555c commit 4b8837e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion packages/plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@dhis2/data-visualizer-plugin",
"version": "32.0.3",
"version": "32.0.5",
"description": "DHIS2 Data Visualizer plugin",
"main": "./build/index.js",
"license": "BSD-3-Clause",
Expand Down
12 changes: 7 additions & 5 deletions packages/plugin/src/ChartPlugin.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';

import isEqual from 'lodash-es/isEqual';
import { createChart } from 'd2-charts-api';

import { apiFetchVisualization } from './api/visualization';
import {
apiFetchAnalytics,
Expand Down Expand Up @@ -32,18 +31,21 @@ class ChartPlugin extends Component {
}

componentDidUpdate(prevProps) {
if (this.props.config !== prevProps.config) {
if (!isEqual(this.props.config, prevProps.config)) {
this.renderChart();
return;
}

if (this.props.filters !== prevProps.filters) {
if (!isEqual(this.props.filters, prevProps.filters)) {
this.renderChart();
return;
}

// id set by DV app, style works in dashboards
if (this.props.id !== prevProps.id || !isEqual(this.props.style, prevProps.style)) {
if (
this.props.id !== prevProps.id ||
!isEqual(this.props.style, prevProps.style)
) {
this.recreateChart(0); // disable animation
return;
}
Expand Down

0 comments on commit 4b8837e

Please sign in to comment.