-
Notifications
You must be signed in to change notification settings - Fork 14.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add label and tooltip for the color schemes control (#21040)
* Add tooltip * Remove title * Add license * Enhance E2E tests * Update tests * Lint and test fixes * Enhance layout
- Loading branch information
Showing
20 changed files
with
238 additions
and
46 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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
59 changes: 59 additions & 0 deletions
59
...set-frontend/src/explore/components/controls/ColorSchemeControl/ColorSchemeLabel.test.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,59 @@ | ||
/** | ||
* 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 from 'react'; | ||
import { render, screen, waitFor } from 'spec/helpers/testing-library'; | ||
import ColorSchemeLabel from './ColorSchemeLabel'; | ||
|
||
const defaultProps = { | ||
colors: [ | ||
'#000000', | ||
'#FFFFFF', | ||
'#CCCCCC', | ||
'#000000', | ||
'#FFFFFF', | ||
'#CCCCCC', | ||
'#000000', | ||
'#FFFFFF', | ||
'#CCCCCC', | ||
'#000000', | ||
'#FFFFFF', | ||
'#CCCCCC', | ||
], | ||
label: 'Superset Colors', | ||
id: 'colorScheme', | ||
}; | ||
|
||
const setup = (overrides?: Record<string, any>) => | ||
render(<ColorSchemeLabel {...defaultProps} {...overrides} />); | ||
|
||
test('should render', async () => { | ||
const { container } = setup(); | ||
await waitFor(() => expect(container).toBeVisible()); | ||
}); | ||
|
||
test('should render the label', () => { | ||
setup(); | ||
expect(screen.getByText('Superset Colors')).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the colors', () => { | ||
setup(); | ||
const allColors = screen.getAllByTestId('color'); | ||
expect(allColors).toHaveLength(12); | ||
}); |
126 changes: 126 additions & 0 deletions
126
superset-frontend/src/explore/components/controls/ColorSchemeControl/ColorSchemeLabel.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,126 @@ | ||
/** | ||
* 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 { css, SupersetTheme } from '@superset-ui/core'; | ||
import React, { useRef, useState } from 'react'; | ||
import { Tooltip } from 'src/components/Tooltip'; | ||
|
||
type ColorSchemeLabelProps = { | ||
colors: string[]; | ||
id: string; | ||
label: string; | ||
}; | ||
|
||
export default function ColorSchemeLabel(props: ColorSchemeLabelProps) { | ||
const { id, label, colors } = props; | ||
const [showTooltip, setShowTooltip] = useState<boolean>(false); | ||
const labelNameRef = useRef<HTMLElement>(null); | ||
const labelColorsRef = useRef<HTMLElement>(null); | ||
const handleShowTooltip = () => { | ||
const labelNameElement = labelNameRef.current; | ||
const labelColorsElement = labelColorsRef.current; | ||
if ( | ||
labelNameElement && | ||
labelColorsElement && | ||
(labelNameElement.scrollWidth > labelNameElement.offsetWidth || | ||
labelNameElement.scrollHeight > labelNameElement.offsetHeight || | ||
labelColorsElement.scrollWidth > labelColorsElement.offsetWidth || | ||
labelColorsElement.scrollHeight > labelColorsElement.offsetHeight) | ||
) { | ||
setShowTooltip(true); | ||
} | ||
}; | ||
const handleHideTooltip = () => { | ||
setShowTooltip(false); | ||
}; | ||
|
||
const colorsList = () => | ||
colors.map((color: string, i: number) => ( | ||
<span | ||
data-test="color" | ||
key={`${id}-${i}`} | ||
css={(theme: { gridUnit: number }) => css` | ||
padding-left: ${theme.gridUnit / 2}px; | ||
:before { | ||
content: ''; | ||
display: inline-block; | ||
background-color: ${color}; | ||
border: 1px solid ${color === 'white' ? 'black' : color}; | ||
width: 9px; | ||
height: 10px; | ||
} | ||
`} | ||
/> | ||
)); | ||
|
||
const tooltipContent = () => ( | ||
<> | ||
<span>{label}</span> | ||
<div>{colorsList()}</div> | ||
</> | ||
); | ||
|
||
return ( | ||
<Tooltip | ||
data-testid="tooltip" | ||
overlayClassName="color-scheme-tooltip" | ||
title={tooltipContent} | ||
key={id} | ||
visible={showTooltip} | ||
> | ||
<span | ||
className="color-scheme-option" | ||
onMouseEnter={handleShowTooltip} | ||
onMouseLeave={handleHideTooltip} | ||
css={css` | ||
display: flex; | ||
align-items: center; | ||
justify-content: flex-start; | ||
`} | ||
data-test={id} | ||
> | ||
<span | ||
className="color-scheme-label" | ||
ref={labelNameRef} | ||
css={(theme: SupersetTheme) => css` | ||
min-width: 125px; | ||
padding-right: ${theme.gridUnit * 2}px; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
`} | ||
> | ||
{label} | ||
</span> | ||
<span | ||
ref={labelColorsRef} | ||
css={(theme: SupersetTheme) => css` | ||
flex: 100%; | ||
text-overflow: ellipsis; | ||
overflow: hidden; | ||
white-space: nowrap; | ||
padding-right: ${theme.gridUnit}px; | ||
`} | ||
> | ||
{colorsList()} | ||
</span> | ||
</span> | ||
</Tooltip> | ||
); | ||
} |
Oops, something went wrong.