codeant-ai-for-open-source[bot] commented on code in PR #39990: URL: https://github.com/apache/superset/pull/39990#discussion_r3213196682
########## superset-frontend/plugins/plugin-chart-echarts/src/Candlestick/transformProps.ts: ########## @@ -0,0 +1,177 @@ +/** + * 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 { + getMetricLabel, + getNumberFormatter, + getTimeFormatter, + getXAxisLabel, +} from '@superset-ui/core'; +import type { EChartsCoreOption, CandlestickSeriesOption } from 'echarts'; +import type { CallbackDataParams } from 'echarts/types/src/util/types'; +import { + CandlestickChartTransformedProps, + EchartsCandlestickChartProps, +} from './types'; +import { defaultGrid, defaultYAxis } from '../defaults'; +import { getColtypesMapping, sanitizeHtml } from '../utils/series'; +import { getDefaultTooltip } from '../utils/tooltip'; +import { Refs } from '../types'; + +export default function transformProps( + chartProps: EchartsCandlestickChartProps, +): CandlestickChartTransformedProps { + const { width, height, formData, queriesData, hooks } = chartProps; + const { data = [] } = queriesData[0]; + const { setDataMask = () => {} } = hooks; + const coltypeMapping = getColtypesMapping(queriesData[0]); + const refs: Refs = {} as Refs; + + const { + open: openMetric, + close: closeMetric, + low: lowMetric, + high: highMetric, + zoomable, + } = formData; + + const openLabel = getMetricLabel(openMetric); + const closeLabel = getMetricLabel(closeMetric); + const lowLabel = getMetricLabel(lowMetric); + const highLabel = getMetricLabel(highMetric); + const xAxisLabel = getXAxisLabel(chartProps.rawFormData) || '__timestamp'; + + const timeFormatter = getTimeFormatter('%Y-%m-%d %H:%M:%S'); + const numberFormatter = getNumberFormatter(); + + const transformedData = data + .map(datum => { + const time = datum[xAxisLabel]; + const o = datum[openLabel]; + const c = datum[closeLabel]; + const l = datum[lowLabel]; + const h = datum[highLabel]; + + if (o == null || c == null || l == null || h == null) { + return null; + } + + return [time, o, c, l, h]; + }) + .filter(Boolean) as [any, number, number, number, number][]; + + const series: CandlestickSeriesOption[] = [ + { + name: 'OHLC', + type: 'candlestick', + data: transformedData.map(row => row.slice(1)), + itemStyle: { + // International standard: Green for Up, Red for Down + color: '#14b143', + color0: '#ef232a', + borderColor: '#14b143', + borderColor0: '#ef232a', + }, + }, + ]; + + const echartOptions: EChartsCoreOption = { + grid: { + ...defaultGrid, + bottom: zoomable ? '15%' : '10%', + }, + xAxis: { + type: 'category', + data: transformedData.map(row => timeFormatter(row[0])), + scale: true, + boundaryGap: false, + axisLine: { onZero: false }, + splitLine: { show: false }, + min: 'dataMin', + max: 'dataMax', + }, + yAxis: { + ...defaultYAxis, + scale: true, + splitArea: { + show: true, + }, + axisLabel: { formatter: numberFormatter }, + }, + tooltip: { + ...getDefaultTooltip(refs), + trigger: 'axis', + axisPointer: { + type: 'cross', + }, + formatter: (params: CallbackDataParams[]) => { + const p = params[0]; + const [o, c, l, h] = p.value as number[]; + return ` + <div style="padding: 3px;"> + <p style="margin-bottom: 5px;"><strong>${sanitizeHtml(p.name)}</strong></p> + <div style="display: flex; justify-content: space-between;"> + <span style="margin-right: 10px;">Open:</span> + <strong>${numberFormatter(o)}</strong> + </div> + <div style="display: flex; justify-content: space-between;"> + <span style="margin-right: 10px;">Close:</span> + <strong>${numberFormatter(c)}</strong> + </div> + <div style="display: flex; justify-content: space-between;"> + <span style="margin-right: 10px;">Low:</span> + <strong>${numberFormatter(l)}</strong> + </div> + <div style="display: flex; justify-content: space-between;"> + <span style="margin-right: 10px;">High:</span> + <strong>${numberFormatter(h)}</strong> + </div> + </div> + `; + }, + }, + series, + dataZoom: zoomable + ? [ + { + type: 'inside', + start: 0, + end: 100, + }, + { + show: true, + type: 'slider', + top: '90%', + start: 0, + end: 100, + }, + ] + : [], + }; + + return { + formData, + width, + height, + echartOptions, + setDataMask, + refs, + coltypeMapping, + selectedValues: {}, + }; Review Comment: **🔴 Architect Review — CRITICAL** Candlestick transformProps returns props without required interaction fields (no groupby, labelMap, or onContextMenu), yet the chart class declares CrossFilterTransformedProps/ContextMenuTransformedProps and EchartsCandlestick uses allEventHandlers, which destructures groupby and calls groupby.length. This mismatch will cause a runtime error when rendering and prevents the advertised Interactive/Drill behaviors from working. **Suggestion:** Align transformProps with other interactive ECharts plugins (e.g. Pie/Gauge/BoxPlot): build and return groupby, labelMap, selectedValues (from filterState), emitCrossFilters, and onContextMenu (from hooks) alongside the existing fields, or remove the Interactive/Drill behaviors and allEventHandlers usage until the interaction contract is correctly implemented. [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt=This%20is%20an%20%2A%2AArchitect%20%2F%20Logical%20Review%2A%2A%20comment%20left%20during%20a%20code%20review.%20These%20reviews%20are%20first-class%2C%20important%20findings%20%E2%80%94%20not%20optional%20suggestions.%20Do%20NOT%20dismiss%20this%20as%20a%20%27big%20architectural%20change%27%20just%20because%20the%20title%20says%20architect%20review%3B%20most%20of%20these%20can%20be%20resolved%20with%20a%20small%2C%20localized%20fix%20once%20the%20intent%20is%20understood.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fplugins%2Fplugin-chart-echarts%2Fsrc%2FCandlestick%2FtransformProps.ts%0A%2A%2ALine%3A%2A%2A%20167%3A176%0A%2A%2AComment%3A%2A%2A%0A%09%2ACRITICAL%3A%20Candlestick%20transformProps%20returns%20props%20without%20required%20interaction%20fields%20%28no%20groupby%2C%20labelMap%2C%20or%20onContextMenu%29%2C%20yet%20the%20chart%20class%20declares%20CrossFilterTransformedProps%2FContextMenuTransformedPro ps%20and%20EchartsCandlestick%20uses%20allEventHandlers%2C%20which%20destructures%20groupby%20and%20calls%20groupby.length.%20This%20mismatch%20will%20cause%20a%20runtime%20error%20when%20rendering%20and%20prevents%20the%20advertised%20Interactive%2FDrill%20behaviors%20from%20working.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AIf%20a%20suggested%20approach%20is%20provided%20above%2C%20use%20it%20as%20the%20authoritative%20instruction.%20If%20no%20explicit%20code%20suggestion%20is%20given%2C%20you%20MUST%20still%20draft%20and%20apply%20your%20own%20minimal%2C%20localized%20fix%20%E2%80%94%20do%20not%20punt%20back%20with%20%27no%20suggestion%20provided%2C%20review%20manually%27.%20Keep%20the%20change%20as%20small%20as%20possible%3A%20add%20a%20guard%20clause%2C%20gate%20on%20a%20loading%20state%2C%20reorder%20an%20await%2 C%20wrap%20in%20a%20conditional%2C%20etc.%20Do%20not%20refactor%20surrounding%20code%20or%20expand%20scope%20beyond%20the%20finding.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt=This%20is%20an%20%2A%2AArchitect%20%2F%20Logical%20Review%2A%2A%20comment%20left%20during%20a%20code%20review.%20These%20reviews%20are%20first-class%2C%20important%20findings%20%E2%80%94%20not%20optional%20suggestions.%20Do%20NOT%20dismiss%20this%20as%20a%20%27big%20architectural%20change%27%20just%20because%20the%20title%20says%20architect%20review%3B%20most%20of%20these%20can%20be%20resolved%20with%20a%20small%2C%20localized%20fix%20once%20th e%20intent%20is%20understood.%0A%0A%2A%2APath%3A%2A%2A%20superset-frontend%2Fplugins%2Fplugin-chart-echarts%2Fsrc%2FCandlestick%2FtransformProps.ts%0A%2A%2ALine%3A%2A%2A%20167%3A176%0A%2A%2AComment%3A%2A%2A%0A%09%2ACRITICAL%3A%20Candlestick%20transformProps%20returns%20props%20without%20required%20interaction%20fields%20%28no%20groupby%2C%20labelMap%2C%20or%20onContextMenu%29%2C%20yet%20the%20chart%20class%20declares%20CrossFilterTransformedProps%2FContextMenuTransformedProps%20and%20EchartsCandlestick%20uses%20allEventHandlers%2C%20which%20destructures%20groupby%20and%20calls%20groupby.length.%20This%20mismatch%20will%20cause%20a%20runtime%20error%20when%20rendering%20and%20prevents%20the%20advertised%20Interactive%2FDrill%20behaviors%20from%20working.%0A%0AValidate%20the%20correctness%20of%20the%20flagged%20issue.%20If%20correct%2C%20How%20can%20I%20resolve%20this%3F%20If%20you%20propose%20a%20fix%2C%20implement%20it%20and%20please%20make%20it%20concise.%0AIf%20a%20suggested%20app roach%20is%20provided%20above%2C%20use%20it%20as%20the%20authoritative%20instruction.%20If%20no%20explicit%20code%20suggestion%20is%20given%2C%20you%20MUST%20still%20draft%20and%20apply%20your%20own%20minimal%2C%20localized%20fix%20%E2%80%94%20do%20not%20punt%20back%20with%20%27no%20suggestion%20provided%2C%20review%20manually%27.%20Keep%20the%20change%20as%20small%20as%20possible%3A%20add%20a%20guard%20clause%2C%20gate%20on%20a%20loading%20state%2C%20reorder%20an%20await%2C%20wrap%20in%20a%20conditional%2C%20etc.%20Do%20not%20refactor%20surrounding%20code%20or%20expand%20scope%20beyond%20the%20finding.%0AOnce%20fix%20is%20implemented%2C%20also%20check%20other%20comments%20on%20the%20same%20PR%2C%20and%20ask%20user%20if%20the%20user%20wants%20to%20fix%20the%20rest%20of%20the%20comments%20as%20well.%20if%20said%20yes%2C%20then%20fetch%20all%20the%20comments%20validate%20the%20correctness%20and%20implement%20a%20minimal%20fix%0A) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is an **Architect / Logical Review** comment left during a code review. These reviews are first-class, important findings — not optional suggestions. Do NOT dismiss this as a 'big architectural change' just because the title says architect review; most of these can be resolved with a small, localized fix once the intent is understood. **Path:** superset-frontend/plugins/plugin-chart-echarts/src/Candlestick/transformProps.ts **Line:** 167:176 **Comment:** *CRITICAL: Candlestick transformProps returns props without required interaction fields (no groupby, labelMap, or onContextMenu), yet the chart class declares CrossFilterTransformedProps/ContextMenuTransformedProps and EchartsCandlestick uses allEventHandlers, which destructures groupby and calls groupby.length. This mismatch will cause a runtime error when rendering and prevents the advertised Interactive/Drill behaviors from working. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. If a suggested approach is provided above, use it as the authoritative instruction. If no explicit code suggestion is given, you MUST still draft and apply your own minimal, localized fix — do not punt back with 'no suggestion provided, review manually'. Keep the change as small as possible: add a guard clause, gate on a loading state, reorder an await, wrap in a conditional, etc. Do not refactor surrounding code or expand scope beyond the finding. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> -- 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]
