Skip to content

Commit

Permalink
fix: pass state to dynamic component
Browse files Browse the repository at this point in the history
  • Loading branch information
simcha90 committed Oct 27, 2021
1 parent e02ada3 commit 369afd4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import React, { FC, Suspense } from 'react';
import { JsonObject, t } from '@superset-ui/core';
import backgroundStyleOptions from 'src/dashboard/util/backgroundStyleOptions';
import cx from 'classnames';
import { useSelector } from 'react-redux';
import DragDroppable from '../dnd/DragDroppable';
import { COLUMN_TYPE, ROW_TYPE } from '../../util/componentTypes';
import WithPopoverMenu from '../menu/WithPopoverMenu';
Expand All @@ -33,6 +34,7 @@ import HoverMenu from '../menu/HoverMenu';
import DeleteComponentButton from '../DeleteComponentButton';
import BackgroundStyleDropdown from '../menu/BackgroundStyleDropdown';
import dashboardComponents from '../../../visualizations/presets/dashboardComponents';
import { RootState } from '../../types';

type FilterSummaryType = {
component: JsonObject;
Expand Down Expand Up @@ -97,6 +99,15 @@ const DynamicComponent: FC<FilterSummaryType> = ({

const { Component } = dashboardComponents.get(component.meta.componentKey);

const dashboardData = useSelector<RootState>(
({ nativeFilters, dataMask, charts, dashboardInfo }) => ({
nativeFilters,
dataMask,
charts,
dashboardInfo,
}),
);

return (
<DragDroppable
// @ts-ignore
Expand Down Expand Up @@ -155,7 +166,7 @@ const DynamicComponent: FC<FilterSummaryType> = ({
</HoverMenu>
)}
<Suspense fallback={<div>{t('Loading...')}</div>}>
<Component />
<Component dashboardData={dashboardData} />
</Suspense>
</div>
</ResizableContainer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
* under the License.
*/
import React from 'react';
import { JsonObject } from '@superset-ui/core';

// TODO: POC only component can be removed after PR approved
const TestComponent = () => <div>Test</div>;
const TestComponent = ({ dashboardData }: JsonObject) => (
<div>We have next keys: {Object.keys(dashboardData).join(', ')}</div>
);

export default TestComponent;

0 comments on commit 369afd4

Please sign in to comment.