Skip to content

Commit

Permalink
fix: use measured height of dashboard item in view mode [DHIS2-8492] (#…
Browse files Browse the repository at this point in the history
…674) (#730)

Fixes issue where reloading a dashboard can cause a map item to cut off the bottom of the map. This may happen if you open the dashboard, then click on the same dashboard item chip to reload the dashboard.

Fixes https://jira.dhis2.org/browse/DHIS2-8492
  • Loading branch information
jenniferarnesen authored Apr 27, 2020
1 parent 288e13c commit d1f6200
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/components/Item/VisualizationItem/Item.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import memoizeOne from '../../../modules/memoizeOne';
import { colors } from '@dhis2/ui-core';
import { getVisualizationConfig } from './plugin';
import LoadingMask from './LoadingMask';
import { ITEM_CONTENT_PADDING_BOTTOM } from '../../ItemGrid/ItemGrid';

const styles = {
icon: {
Expand Down Expand Up @@ -169,13 +170,19 @@ export class Item extends Component {
);
}

const calculatedHeight =
this.props.item.originalHeight -
this.headerRef.current.clientHeight -
HEADER_MARGIN_HEIGHT -
ITEM_CONTENT_PADDING_BOTTOM;

const props = {
...this.props,
visualization,
style: this.memoizedGetContentStyle(
this.props.item.originalHeight,
this.headerRef.current.clientHeight,
this.contentRef ? this.contentRef.offsetHeight : null
calculatedHeight,
this.contentRef ? this.contentRef.offsetHeight : null,
this.props.editMode
),
};

Expand Down Expand Up @@ -285,13 +292,12 @@ export class Item extends Component {
this.props.visualization
);

getContentStyle = (originalHeight, headerHeight, measuredHeight) => {
const calculatedHeight =
originalHeight - headerHeight - HEADER_MARGIN_HEIGHT;
getContentStyle = (calculatedHeight, measuredHeight, editMode) => {
const height = editMode
? measuredHeight || calculatedHeight
: calculatedHeight;

return {
height: measuredHeight || calculatedHeight,
};
return { height };
};

render() {
Expand Down
2 changes: 2 additions & 0 deletions src/components/ItemGrid/ItemGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import ProgressiveLoadingContainer from '../Item/ProgressiveLoadingContainer';
// Component

const EXPANDED_HEIGHT = 17;
// this is set in the .dashboard-item-content css
export const ITEM_CONTENT_PADDING_BOTTOM = 4;

export class ItemGrid extends Component {
state = {
Expand Down

0 comments on commit d1f6200

Please sign in to comment.