diff --git a/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.stories.tsx b/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.stories.tsx new file mode 100644 index 0000000000000..ff5e14189767f --- /dev/null +++ b/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.stories.tsx @@ -0,0 +1,36 @@ +/** + * 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 TableControls, { TableControlsProps } from './DrillDetailTableControls'; + +export default { + title: 'DrillDetailTableControls', + component: TableControls, +}; + +export const InteractiveTableControls = (args: TableControlsProps) => ( + +); + +InteractiveTableControls.args = { + totalCount: 100, + filters: [ + { op: '>', col: 'tz_offset', val: 200 }, + { op: '==', col: 'platform', val: 'GB' }, + ], +}; diff --git a/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.test.tsx b/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.test.tsx index 0fd304be011b4..99276a5ca8123 100644 --- a/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.test.tsx +++ b/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.test.tsx @@ -101,7 +101,6 @@ test('should remove the filters on close', () => { expect(screen.getByText('platform')).toBeInTheDocument(); expect(screen.getByText('GB')).toBeInTheDocument(); - userEvent.click(screen.getByRole('img', { name: 'close' })); - + userEvent.click(screen.getByRole('button', { name: 'close' })); expect(setFilters).toHaveBeenCalledWith([]); }); diff --git a/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.tsx b/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.tsx index cdf74c6f67f2e..378f9e8099956 100644 --- a/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.tsx +++ b/superset-frontend/src/components/Chart/DrillDetail/DrillDetailTableControls.tsx @@ -18,7 +18,7 @@ */ import { useCallback, useMemo } from 'react'; -import { Tag } from 'antd'; +import { Tag } from 'src/components/Tags'; import { BinaryQueryObjectFilterClause, css, @@ -29,19 +29,21 @@ import { import RowCountLabel from 'src/explore/components/RowCountLabel'; import Icons from 'src/components/Icons'; +export type TableControlsProps = { + filters: BinaryQueryObjectFilterClause[]; + setFilters: (filters: BinaryQueryObjectFilterClause[]) => void; + totalCount?: number; + loading: boolean; + onReload: () => void; +}; + export default function TableControls({ filters, setFilters, totalCount, loading, onReload, -}: { - filters: BinaryQueryObjectFilterClause[]; - setFilters: (filters: BinaryQueryObjectFilterClause[]) => void; - totalCount?: number; - loading: boolean; - onReload: () => void; -}) { +}: TableControlsProps) { const theme = useTheme(); const filterMap: Record = useMemo( () => @@ -89,23 +91,16 @@ export default function TableControls({ css={css` display: flex; flex-wrap: wrap; - margin-bottom: -${theme.gridUnit * 4}px; `} > - {filterTags.map(({ colName, val }) => ( + {filterTags.map(({ colName, val }, index) => ( { const isLongTag = useMemo(() => name.length > MAX_DISPLAY_CHAR, [name]); const tagDisplay = isLongTag ? `${name.slice(0, MAX_DISPLAY_CHAR)}...` : name; - const handleClose = () => (index ? onDelete?.(index) : null); + const handleClose = () => (index !== undefined ? onDelete?.(index) : null); const whatRole = onClick ? (!id ? 'button' : 'link') : undefined; @@ -59,25 +61,32 @@ const Tag = ({ key={id} closable={editable} onClose={handleClose} - color="blue" closeIcon={editable ? CustomCloseIcon : undefined} + {...rest} > - {tagDisplay} + {children || tagDisplay} ) : ( - + + {' '} {id ? ( - {tagDisplay} + {children || tagDisplay} ) : ( - tagDisplay + children || tagDisplay )} diff --git a/superset-frontend/src/types/TagType.ts b/superset-frontend/src/types/TagType.ts index 0ea5f44d2d275..ef68b1c1acf1a 100644 --- a/superset-frontend/src/types/TagType.ts +++ b/superset-frontend/src/types/TagType.ts @@ -28,6 +28,7 @@ export interface TagType { name: string; index?: number | undefined; toolTipTitle?: string; + children?: React.ReactNode; } export default TagType;