zhaoyongjie commented on code in PR #21351: URL: https://github.com/apache/superset/pull/21351#discussion_r989745658
########## superset-frontend/src/components/Chart/DrillDetail/DrillDetailMenuItems.tsx: ########## @@ -0,0 +1,230 @@ +/** + * 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, { ReactNode, useCallback, useMemo, useState } from 'react'; +import { + Behavior, + BinaryQueryObjectFilterClause, + css, + getChartMetadataRegistry, + QueryFormData, + styled, + SupersetTheme, + t, +} from '@superset-ui/core'; +import { Menu } from 'src/components/Menu'; +import Icons from 'src/components/Icons'; +import { Tooltip } from 'src/components/Tooltip'; +import DrillDetailModal from './DrillDetailModal'; + +const DisabledMenuItemTooltip = ({ title }: { title: ReactNode }) => ( + <Tooltip title={title} placement="top"> + <Icons.InfoCircleOutlined + data-test="tooltip-trigger" + css={(theme: SupersetTheme) => css` + color: ${theme.colors.text.label}; + margin-left: ${theme.gridUnit * 2}px; + &.anticon { + font-size: unset; + .anticon { + line-height: unset; + vertical-align: unset; + } + } + `} + /> + </Tooltip> +); + +const DisabledMenuItem = ({ children, ...props }: { children: ReactNode }) => ( + <Menu.Item disabled {...props}> + <div + css={css` + white-space: normal; + max-width: 160px; + `} + > + {children} + </div> + </Menu.Item> +); + +const Filter = styled.span` + ${({ theme }) => ` + font-weight: ${theme.typography.weights.bold}; + color: ${theme.colors.primary.base}; + `} +`; + +export type DrillDetailMenuItemsProps = { + chartId: number; + formData: QueryFormData; + filters?: BinaryQueryObjectFilterClause[]; + isContextMenu?: boolean; + onSelection?: () => void; + onClick?: (event: MouseEvent) => void; +}; + +const DrillDetailMenuItems = ({ + chartId, + formData, + filters = [], + isContextMenu = false, + onSelection = () => null, + onClick = () => null, + ...props +}: DrillDetailMenuItemsProps) => { + const [modalFilters, setFilters] = useState<BinaryQueryObjectFilterClause[]>( + [], + ); + + const [showModal, setShowModal] = useState(false); + const openModal = useCallback( + (filters, event) => { + onClick(event); + onSelection(); + setFilters(filters); + setShowModal(true); + }, + [onClick, onSelection], + ); + + const closeModal = useCallback(() => { + setShowModal(false); + }, []); + + // Check for Behavior.DRILL_TO_DETAIL to tell if plugin handles the `contextmenu` + // event for dimensions. If it doesn't, tell the user that drill to detail by + // dimension is not supported. If it does, and the `contextmenu` handler didn't + // pass any filters, tell the user that they didn't select a dimension. + const handlesDimensionContextMenu = useMemo( + () => + getChartMetadataRegistry() + .get(formData.viz_type) + ?.behaviors.find(behavior => behavior === Behavior.DRILL_TO_DETAIL), + [formData.viz_type], + ); + + // Check chart plugin metadata to see if chart's current configuration lacks + // aggregations, in which case Drill to Detail should be disabled. + const noAggregations = useMemo( + () => + getChartMetadataRegistry() + .get(formData.viz_type) + ?.noAggregations?.(formData) ?? false, + [formData], + ); + + const drillToDetail = noAggregations ? ( Review Comment: it's a `menu` component, should we rename it to `menu` or `drillToDetailMenu`? -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org