This repository has been archived by the owner on Jan 16, 2025. It is now read-only.
forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from katalon-studio/TO3-148
[TO3-148] Enhance reflect URL filter implementation
- Loading branch information
Showing
3 changed files
with
72 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
superset-frontend/src/katalon/KatalonSyncDashboardState.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { useDispatch, shallowEqual, useSelector } from 'react-redux'; | ||
import { useHistory } from 'react-router-dom'; | ||
import { | ||
useInitialization, | ||
useNativeFiltersDataMask, | ||
} from '../dashboard/components/nativeFilters/FilterBar/state'; | ||
import { hydrateDashboard } from '../dashboard/actions/hydrate'; | ||
import { useDashboard, useDashboardCharts } from '../hooks/apiResources'; | ||
|
||
function KatalonSyncDashboardState({ children }: any) { | ||
const dispatch = useDispatch(); | ||
const history = useHistory(); | ||
const dashboardId = useSelector<any, number>( | ||
({ dashboardInfo }) => dashboardInfo?.id, | ||
); | ||
const isInitialized = useInitialization(); | ||
const { result: dashboard } = useDashboard(dashboardId); | ||
const { result: charts } = useDashboardCharts(dashboardId); | ||
const currentFilters = useNativeFiltersDataMask(); | ||
const [previousFilters, setPreviousFilters] = useState(currentFilters); | ||
const [filtersFromParent, setFiltersFromParent] = useState(); | ||
|
||
// Send filters to parent | ||
useEffect(() => { | ||
const isApplyFiltersClicked = | ||
isInitialized && !shallowEqual(previousFilters, currentFilters); | ||
if (isApplyFiltersClicked) { | ||
window.parent.postMessage(JSON.stringify(currentFilters), '*'); | ||
} | ||
setPreviousFilters(currentFilters); | ||
}, [currentFilters]); | ||
|
||
// Receive filters from parent | ||
useEffect(() => { | ||
window.addEventListener('message', event => { | ||
if (event.data.raFilter) { | ||
const receivedFilters = JSON.parse(event.data.raFilter); | ||
setFiltersFromParent(receivedFilters); | ||
} | ||
}); | ||
}, []); | ||
|
||
// Send ready message to parent, so it can start sending filters | ||
useEffect(() => { | ||
if (isInitialized) { | ||
window.parent.postMessage('iframe ready', '*'); | ||
} | ||
}, [isInitialized]); | ||
|
||
// Hydrate dashboard with received filters | ||
useEffect(() => { | ||
if (isInitialized && filtersFromParent) { | ||
dispatch( | ||
hydrateDashboard({ | ||
history, | ||
dashboard, | ||
charts, | ||
activeTabs: undefined, | ||
dataMask: filtersFromParent, | ||
}), | ||
); | ||
} | ||
}, [filtersFromParent]); | ||
|
||
return <>{children}</>; | ||
} | ||
|
||
export default KatalonSyncDashboardState; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters