Skip to content

Commit

Permalink
fix: avoid flashing when ou levels are used (DHIS2-17136)
Browse files Browse the repository at this point in the history
  • Loading branch information
edoardo committed Apr 26, 2024
1 parent 827ef37 commit 02b87bf
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/components/VisualizationPlugin/VisualizationPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const VisualizationPlugin = ({
onDrill,
}) => {
const engine = useDataEngine()
const [visualization, setVisualization] = useState(undefined)
const [visualization, setVisualization] = useState(null)
const [ouLevels, setOuLevels] = useState(undefined)
const [fetchResult, setFetchResult] = useState(null)
const [contextualMenuRef, setContextualMenuRef] = useState(undefined)
Expand Down Expand Up @@ -173,6 +173,7 @@ export const VisualizationPlugin = ({

useEffect(() => {
setFetchResult(null)
setVisualization(null)

// filter out disabled options
const disabledOptions = getDisabledOptions({
Expand All @@ -186,8 +187,6 @@ export const VisualizationPlugin = ({
(option) => delete filteredVisualization[option]
)

setVisualization(filteredVisualization)

const doFetchAll = async () => {
const { responses, extraOptions } = await doFetchData(
filteredVisualization,
Expand Down Expand Up @@ -254,6 +253,7 @@ export const VisualizationPlugin = ({
extraOptions,
})
setShowLegendKey(filteredVisualization.legend?.showKey)

onLoadingComplete()
}

Expand All @@ -264,7 +264,15 @@ export const VisualizationPlugin = ({
/* eslint-disable-next-line react-hooks/exhaustive-deps */
}, [originalVisualization, filters, forDashboard])

if (!fetchResult || !ouLevels) {
useEffect(() => {
if (fetchResult?.visualization && ouLevels) {
setVisualization(
convertOuLevelsToUids(ouLevels, fetchResult.visualization)
)
}
}, [fetchResult?.visualization, ouLevels])

if (!fetchResult || !visualization || !ouLevels) {
return null
}

Expand Down Expand Up @@ -406,10 +414,7 @@ export const VisualizationPlugin = ({
) {
return (
<PivotPlugin
visualization={convertOuLevelsToUids(
ouLevels,
fetchResult.visualization
)}
visualization={visualization}
responses={fetchResult.responses}
legendSets={legendSets}
onToggleContextualMenu={
Expand All @@ -422,10 +427,7 @@ export const VisualizationPlugin = ({
} else if (fetchResult.visualization.type === VIS_TYPE_OUTLIER_TABLE) {
return (
<OutlierTablePlugin
visualization={convertOuLevelsToUids(
ouLevels,
fetchResult.visualization
)}
visualization={visualization}
responses={fetchResult.responses}
filters={filters}
id={id}
Expand All @@ -436,10 +438,7 @@ export const VisualizationPlugin = ({
} else {
return (
<ChartPlugin
visualization={convertOuLevelsToUids(
ouLevels,
fetchResult.visualization
)}
visualization={visualization}
responses={fetchResult.responses}
extraOptions={fetchResult.extraOptions}
legendSets={legendSets}
Expand Down

0 comments on commit 02b87bf

Please sign in to comment.