bito-code-review[bot] commented on code in PR #38519: URL: https://github.com/apache/superset/pull/38519#discussion_r2910957292
########## superset-frontend/src/explore/components/controls/VerticalRadioControl.tsx: ########## @@ -0,0 +1,104 @@ +/** + * 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 { type ReactNode } from 'react'; +import { css, useTheme } from '@apache-superset/core/theme'; +import { JsonValue } from '@superset-ui/core'; +import { Radio } from '@superset-ui/core/components/Radio'; +import { Space } from '@superset-ui/core/components/Space'; +import { Tooltip } from '@superset-ui/core/components/Tooltip'; +import { Icons } from '@superset-ui/core/components/Icons'; +import ControlHeader from '../ControlHeader'; + +interface RadioOption { + value: JsonValue; + label: ReactNode; + disabled?: boolean; + tooltip?: string; +} + +type RadioOptionTuple = [JsonValue, ReactNode]; + +interface VerticalRadioControlProps { + value?: JsonValue; + label?: ReactNode; + description?: ReactNode; + hovered?: boolean; + options: (RadioOption | RadioOptionTuple)[]; + onChange: (value: JsonValue) => void; + validationErrors?: string[]; +} + +function normalizeOption(option: RadioOption | RadioOptionTuple): RadioOption { + if (Array.isArray(option)) { + return { value: option[0], label: option[1] }; + } + return option; +} + +export default function VerticalRadioControl({ + value: initialValue, + options, + onChange, + ...props +}: VerticalRadioControlProps) { + const theme = useTheme(); + const normalizedOptions = options.map(normalizeOption); + const currentValue = initialValue ?? normalizedOptions[0]?.value; + + return ( + <div + css={css` + .ant-radio-wrapper { + display: flex; + align-items: center; + } + `} + > + <ControlHeader {...props} /> + <Radio.Group + value={currentValue} + onChange={e => onChange(e.target.value)} + > + <Space direction="vertical"> + {normalizedOptions.map( + ({ value: val, label, disabled = false, tooltip }) => ( + <Radio key={JSON.stringify(val)} value={val} disabled={disabled}> Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Type Safety in Radio onChange</b></div> <div id="fix"> The Radio.Group onChange handler converts values to strings via e.target.value, but JsonValue can include numbers, booleans, or objects. This could cause type mismatches if non-string values are used. To ensure type safety, similar to RadioButtonControl, add an onClick handler to each Radio that calls onChange with the original val. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion <Radio.Group value={currentValue} > <Space direction="vertical"> {normalizedOptions.map( ({ value: val, label, disabled = false, tooltip }) => ( <Radio key={JSON.stringify(val)} value={val} disabled={disabled} onClick={() => onChange(val)}> ```` </div> </details> </div> <small><i>Code Review Run #f8b6ce</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them ########## superset-frontend/packages/superset-ui-core/src/chart/components/Matrixify/MatrixifyGridRenderer.tsx: ########## @@ -130,10 +130,12 @@ function MatrixifyGridRenderer({ // Determine layout parameters - only show headers/labels if layout is enabled const showRowLabels = - formData.matrixify_enable_vertical_layout === true && + formData.matrixify_mode_rows !== undefined && + formData.matrixify_mode_rows !== 'disabled' && (formData.matrixify_show_row_labels ?? true); const showColumnHeaders = - formData.matrixify_enable_horizontal_layout === true && + formData.matrixify_mode_columns !== undefined && + formData.matrixify_mode_columns !== 'disabled' && (formData.matrixify_show_column_headers ?? true); Review Comment: <div> <div id="suggestion"> <div id="issue"><b>Incorrect axis enablement logic</b></div> <div id="fix"> The logic for determining whether to show row labels and column headers is incorrect. It currently allows any mode value except 'disabled' to enable the layout, but should only enable for 'metrics' or 'dimensions' modes. This matches the `isAxisEnabled` helper function defined in the types file. While TypeScript typing reduces the risk, runtime invalid values could cause incorrect UI display. </div> <details> <summary> <b>Code suggestion</b> </summary> <blockquote>Check the AI-generated fix before applying</blockquote> <div id="code"> ````suggestion const showRowLabels = (formData.matrixify_mode_rows === 'metrics' || formData.matrixify_mode_rows === 'dimensions') && (formData.matrixify_show_row_labels ?? true); const showColumnHeaders = (formData.matrixify_mode_columns === 'metrics' || formData.matrixify_mode_columns === 'dimensions') && (formData.matrixify_show_column_headers ?? true); ```` </div> </details> </div> <small><i>Code Review Run #f8b6ce</i></small> </div> --- Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>) - [ ] Yes, avoid them -- 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]
