-
Notifications
You must be signed in to change notification settings - Fork 16.2k
refactor(word-cloud): convert rotation and color controls to React components (POC) #36275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rusackas
merged 7 commits into
apache:master
from
OrhanBC:refactor/convert-word-cloud-controls-to-react
Nov 28, 2025
+863
−22
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8a5c6a5
refactor(word-cloud): convert rotation control to React component
OrhanBC 0cc927b
fix(word-cloud): make rotation and color controls live-update
OrhanBC 296cc50
chore: run prettier
OrhanBC 990a2f8
refactor(word-cloud): convert color scheme control to React component
OrhanBC 3dead35
test(word-cloud): add tests for RotationControl and ControlPanel
BrandanBurgess ad2f3c3
chore: apply minor changes based on co-pilot and bito review
OrhanBC 089244a
refactor(word-cloud): address review feedback and add control tests
OrhanBC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
62 changes: 62 additions & 0 deletions
62
superset-frontend/plugins/plugin-chart-word-cloud/src/plugin/controls/ColorSchemeControl.tsx
This file contains hidden or 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,62 @@ | ||
| /** | ||
| * 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 { getCategoricalSchemeRegistry } from '@superset-ui/core'; | ||
| import InternalColorSchemeControl from './ColorSchemeControl/index'; | ||
| import { ColorSchemes } from './ColorSchemeControl/index'; | ||
| // NOTE: We copied the Explore ColorSchemeControl into this plugin to avoid | ||
| // pulling the entire frontend src tree into this package’s tsconfig (importing | ||
| // from src/ was dragging in fixtures, tests, and other plugins). Keep this copy | ||
| // in sync with upstream changes, and consider moving it into a shared package | ||
| // once the control-panel refactor settles so all consumers can reuse it. | ||
| import { ControlComponentProps } from '@superset-ui/chart-controls'; | ||
|
|
||
| type ColorSchemeControlWrapperProps = ControlComponentProps<string> & { | ||
| clearable?: boolean; | ||
| }; | ||
|
|
||
| export default function ColorSchemeControlWrapper({ | ||
| name = 'color_scheme', | ||
| value, | ||
| onChange, | ||
| clearable = true, | ||
| label, | ||
| description, | ||
| ...rest | ||
| }: ColorSchemeControlWrapperProps) { | ||
| const categoricalSchemeRegistry = getCategoricalSchemeRegistry(); | ||
| const choices = categoricalSchemeRegistry.keys().map(s => [s, s]); | ||
| const schemes = categoricalSchemeRegistry.getMap() as ColorSchemes; | ||
|
|
||
| return ( | ||
| <InternalColorSchemeControl | ||
| name={name} | ||
| value={value ?? ''} | ||
| onChange={onChange} | ||
| clearable={clearable} | ||
| choices={choices} | ||
| schemes={schemes} | ||
| hasCustomLabelsColor={false} | ||
| label={typeof label === 'string' ? label : undefined} | ||
| description={typeof description === 'string' ? description : undefined} | ||
| {...rest} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| ColorSchemeControlWrapper.displayName = 'ColorSchemeControlWrapper'; |
126 changes: 126 additions & 0 deletions
126
...ugins/plugin-chart-word-cloud/src/plugin/controls/ColorSchemeControl/ColorSchemeLabel.tsx
This file contains hidden or 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 '@apache-superset/core/ui'; | ||
| import { useRef, useState } from 'react'; | ||
| import { Tooltip } from '@superset-ui/core/components'; | ||
|
|
||
| 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 labelsColorRef = useRef<HTMLElement>(null); | ||
| const handleShowTooltip = () => { | ||
| const labelNameElement = labelNameRef.current; | ||
| const labelsColorElement = labelsColorRef.current; | ||
| if ( | ||
| labelNameElement && | ||
| labelsColorElement && | ||
| (labelNameElement.scrollWidth > labelNameElement.offsetWidth || | ||
| labelNameElement.scrollHeight > labelNameElement.offsetHeight || | ||
| labelsColorElement.scrollWidth > labelsColorElement.offsetWidth || | ||
| labelsColorElement.scrollHeight > labelsColorElement.offsetHeight) | ||
| ) { | ||
| setShowTooltip(true); | ||
| } | ||
| }; | ||
| const handleHideTooltip = () => { | ||
| setShowTooltip(false); | ||
| }; | ||
|
|
||
| const colorsList = () => | ||
| colors.map((color: string, i: number) => ( | ||
| <span | ||
| data-test="color" | ||
| key={`${id}-${i}`} | ||
| css={(theme: { sizeUnit: number }) => css` | ||
| padding-left: ${theme.sizeUnit / 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} | ||
| open={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.sizeUnit * 2}px; | ||
| text-overflow: ellipsis; | ||
| overflow: hidden; | ||
| white-space: nowrap; | ||
| `} | ||
| > | ||
| {label} | ||
| </span> | ||
| <span | ||
| ref={labelsColorRef} | ||
| css={(theme: SupersetTheme) => css` | ||
| flex: 100%; | ||
| text-overflow: ellipsis; | ||
| overflow: hidden; | ||
| white-space: nowrap; | ||
| padding-right: ${theme.sizeUnit}px; | ||
| `} | ||
| > | ||
| {colorsList()} | ||
| </span> | ||
| </span> | ||
| </Tooltip> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes me wonder something about our general pattern here.
In this instance, we're all good, I think, since the props/values for this component is always going to have the same options for the dropdown, and will always be visible (since it's always relevant to the component).
But, let's say we're adding a React control for something more dynamic... like the "Radius" control in the Pie chart. That one should only be rendered/displayed if the "Donut" checkbox is checked. So, let's say you set the radius control to a value, uncheck "Donut" and then check "Donut" again. Would the value persist? If not, maybe we should consider adding a "hide" prop that removes input visibility without un-rendering it.
Also, there's a likelihood that SOME controls will have dynamic values passed in as props (based on other controls in the control panel). In those cases more than this one, we'll probably want to memoize more. Memoization doesn't seem necessary so much in this particular control, but I'm wondering if we should just memoize things anyway, to establish a pattern for copypasting our way through all control migrations. Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m leaning towards not using a blanket memoization approach. Looking at the codebase, React.memo is only used in 2 controls (FastVizSwitcher, ColumnConfigItem), both with clear performance needs. The implicit pattern seems to be: only memoize when there's a demonstrated need.
For controls with dynamic props and computed options, we should use useMemo/useCallback for those computed values, but not necessarily wrap the whole component in React.memo unless we see performance issues.
Let's keep this simple and address performance on a case-by-case basis as we encounter more complex controls during migration.