diegomedina248 commented on code in PR #20910: URL: https://github.com/apache/superset/pull/20910#discussion_r934506442
########## superset-frontend/src/dashboard/components/gridComponents/ChartHolder.tsx: ########## @@ -0,0 +1,333 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React, { useState, useMemo, useCallback, useEffect } from 'react'; +import { ResizeCallback, ResizeStartCallback } from 're-resizable'; +import cx from 'classnames'; +import { useSelector } from 'react-redux'; + +import { LayoutItem, RootState } from 'src/dashboard/types'; +import AnchorLink from 'src/dashboard/components/AnchorLink'; +import Chart from 'src/dashboard/containers/Chart'; +import DeleteComponentButton from 'src/dashboard/components/DeleteComponentButton'; +import DragDroppable from 'src/dashboard/components/dnd/DragDroppable'; +import HoverMenu from 'src/dashboard/components/menu/HoverMenu'; +import ResizableContainer from 'src/dashboard/components/resizable/ResizableContainer'; +import getChartAndLabelComponentIdFromPath from 'src/dashboard/util/getChartAndLabelComponentIdFromPath'; +import useFilterFocusHighlightStyles from 'src/dashboard/util/useFilterFocusHighlightStyles'; +import { COLUMN_TYPE, ROW_TYPE } from 'src/dashboard/util/componentTypes'; +import { + GRID_BASE_UNIT, + GRID_GUTTER_SIZE, + GRID_MIN_COLUMN_COUNT, + GRID_MIN_ROW_UNITS, +} from 'src/dashboard/util/constants'; + +export const CHART_MARGIN = 32; + +interface ChartHolderProps { + id: string; + parentId: string; + dashboardId: number; + component: LayoutItem; + parentComponent: LayoutItem; + getComponentById?: (id?: string) => LayoutItem | undefined; + index: number; + depth: number; + editMode: boolean; + directPathLastUpdated?: number; + fullSizeChartId: number | null; + isComponentVisible: boolean; + + // grid related + availableColumnCount: number; + columnWidth: number; + onResizeStart: ResizeStartCallback; + onResize: ResizeCallback; + onResizeStop: ResizeCallback; + + // dnd + deleteComponent: (id: string, parentId: string) => void; + updateComponents: Function; + handleComponentDrop: (...args: unknown[]) => unknown; + setFullSizeChartId: (chartId: number | null) => void; + postAddSliceFromDashboard?: () => void; +} + +const ChartHolder: React.FC<ChartHolderProps> = ({ + id, + parentId, + component, + parentComponent, + index, + depth, + availableColumnCount, + columnWidth, + onResizeStart, + onResize, + onResizeStop, + editMode, + isComponentVisible, + dashboardId, + fullSizeChartId, + getComponentById = () => undefined, + deleteComponent, + updateComponents, + handleComponentDrop, + setFullSizeChartId, + postAddSliceFromDashboard, +}) => { + const { chartId } = component.meta; + const isFullSize = fullSizeChartId === chartId; + + const focusHighlightStyles = useFilterFocusHighlightStyles(chartId); + const dashboardState = useSelector( + (state: RootState) => state.dashboardState, + ); + const [extraControls, setExtraControls] = useState<Record<string, unknown>>( + {}, + ); + const [outlinedComponentId, setOutlinedComponentId] = useState<string>(); + const [outlinedColumnName, setOutlinedColumnName] = useState<string>(); + const [currentDirectPathLastUpdated, setCurrentDirectPathLastUpdated] = + useState(0); + + const directPathToChild = useMemo( + () => dashboardState?.directPathToChild ?? [], + [dashboardState], + ); + + const directPathLastUpdated = useMemo( + () => dashboardState?.directPathLastUpdated ?? 0, + [dashboardState], + ); + + const infoFromPath = useMemo( + () => getChartAndLabelComponentIdFromPath(directPathToChild) as any, Review Comment: We could, but we'd need to change the file that contains that function to typescript, and there's a couple of types around the filters that are not well defined. Plus, changing that file should follow with tests as well, and I didn't want to make this PR bigger, since it can be addressed as a follow up -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
