codeant-ai-for-open-source[bot] commented on code in PR #41490: URL: https://github.com/apache/superset/pull/41490#discussion_r3485753834
########## superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx: ########## @@ -0,0 +1,148 @@ +/** + * 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 { render, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { supersetTheme, ThemeProvider } from '@apache-superset/core/theme'; +import { Provider } from 'react-redux'; +import { configureStore } from '@reduxjs/toolkit'; +import { DatasourceType, SupersetClient } from '@superset-ui/core'; +import DeckMulti from './Multi'; + +// Capture the layers handed to the DeckGL container so we can inspect the +// per-feature colors that were resolved for each sublayer. +const mockLayerCapture: { layers: any[] } = { layers: [] }; Review Comment: **Suggestion:** Replace the `any[]` layer collection type with a concrete layer type (or a narrowed interface) so the captured layer data is strongly typed. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The custom rule forbids new or modified TypeScript/TSX code using `any`. This line declares `layers: any[]`, so the violation is present in the final file. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=3b4140aaa4b7450a873b777824f179cf&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=3b4140aaa4b7450a873b777824f179cf&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx **Line:** 29:29 **Comment:** *Custom Rule: Replace the `any[]` layer collection type with a concrete layer type (or a narrowed interface) so the captured layer data is strongly typed. 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. 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> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=73bf142e67f1a1418778548c84b92828f1e84bedcf918dece3e47a016c93aaf6&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=73bf142e67f1a1418778548c84b92828f1e84bedcf918dece3e47a016c93aaf6&reaction=dislike'>👎</a> ########## superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx: ########## @@ -0,0 +1,148 @@ +/** + * 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 { render, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { supersetTheme, ThemeProvider } from '@apache-superset/core/theme'; +import { Provider } from 'react-redux'; +import { configureStore } from '@reduxjs/toolkit'; +import { DatasourceType, SupersetClient } from '@superset-ui/core'; +import DeckMulti from './Multi'; + +// Capture the layers handed to the DeckGL container so we can inspect the +// per-feature colors that were resolved for each sublayer. +const mockLayerCapture: { layers: any[] } = { layers: [] }; +jest.mock('../DeckGLContainer', () => ({ + DeckGLContainerStyledWrapper: ({ layers }: any) => { Review Comment: **Suggestion:** Replace the mocked component props `any` annotation with an explicit props type that defines the `layers` field shape. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> The file is new TSX test code and this callback parameter is explicitly annotated with `any`, which the rule disallows. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=c8b89fa447804126bc9c628e0c28db77&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=c8b89fa447804126bc9c628e0c28db77&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx **Line:** 31:31 **Comment:** *Custom Rule: Replace the mocked component props `any` annotation with an explicit props type that defines the `layers` field shape. 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. 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> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=9f4993d65d1c0c9968f21e5582075d898bb549a01772b428ab14465620a8b520&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=9f4993d65d1c0c9968f21e5582075d898bb549a01772b428ab14465620a8b520&reaction=dislike'>👎</a> ########## superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx: ########## @@ -0,0 +1,148 @@ +/** + * 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 { render, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { supersetTheme, ThemeProvider } from '@apache-superset/core/theme'; +import { Provider } from 'react-redux'; +import { configureStore } from '@reduxjs/toolkit'; +import { DatasourceType, SupersetClient } from '@superset-ui/core'; +import DeckMulti from './Multi'; + +// Capture the layers handed to the DeckGL container so we can inspect the +// per-feature colors that were resolved for each sublayer. +const mockLayerCapture: { layers: any[] } = { layers: [] }; +jest.mock('../DeckGLContainer', () => ({ + DeckGLContainerStyledWrapper: ({ layers }: any) => { + mockLayerCapture.layers = layers || []; + return <div data-test="deckgl-container">DeckGL Container Mock</div>; + }, +})); + +jest.mock('@superset-ui/core', () => ({ + ...jest.requireActual('@superset-ui/core'), + SupersetClient: { + get: jest.fn(), + }, +})); + +const mockStore = configureStore({ + reducer: { + dataMask: () => ({}), + }, +}); + +const renderWithProviders = (component: React.ReactElement) => + render( + <Provider store={mockStore}> + <ThemeProvider theme={supersetTheme}>{component}</ThemeProvider> + </Provider>, + ); + +const SCATTER_SLICE_ID = 1; + +const props = { + formData: { + datasource: '1__table', + viz_type: 'deck_multi', + deck_slices: [SCATTER_SLICE_ID], + autozoom: false, + map_style: 'mapbox://styles/mapbox/light-v9', + }, + payload: { + data: { + slices: [ + { + slice_id: SCATTER_SLICE_ID, + form_data: { + viz_type: 'deck_scatter', + datasource: '1__table', + slice_id: SCATTER_SLICE_ID, + // categorical color configuration coming from the saved scatter chart + color_scheme_type: 'categorical_palette', + color_scheme: 'supersetColors', + dimension: 'category', + }, + }, + ], + features: { + deck_scatter: [], + }, + mapboxApiKey: 'test-key', + }, + }, + setControlValue: jest.fn(), + viewport: { longitude: 0, latitude: 0, zoom: 1 }, + onAddFilter: jest.fn(), + height: 600, + width: 800, + datasource: { + id: 1, + type: DatasourceType.Table, + name: 'test_datasource', + columns: [], + metrics: [], + columnFormats: {}, + currencyFormats: {}, + verboseMap: {}, + }, + onSelect: jest.fn(), +}; + +beforeEach(() => { + jest.clearAllMocks(); + mockLayerCapture.layers = []; + // The scatter sublayer query returns features tagged with a category column. + (SupersetClient.get as jest.Mock).mockResolvedValue({ + json: { + data: { + features: [ + { position: [0, 0], radius: 1, cat_color: 'A' }, + { position: [1, 1], radius: 1, cat_color: 'B' }, + ], + }, + }, + }); +}); + +test('applies categorical scatterplot colors to sublayers in the multi chart', async () => { + renderWithProviders(<DeckMulti {...props} />); + + await waitFor(() => { + expect(mockLayerCapture.layers.length).toBeGreaterThan(0); + }); + + const scatterLayer = mockLayerCapture.layers.find((layer: any) => + layer?.id?.startsWith('scatter-layer-'), + ); + expect(scatterLayer).toBeDefined(); + + const { data } = scatterLayer.props; + expect(data).toHaveLength(2); + + // Both points must carry a resolved RGBA color... + data.forEach((d: any) => { Review Comment: **Suggestion:** Replace the `any` annotation in the `forEach` callback with a concrete feature/data-point type that includes the `color` field used in assertions. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This new TSX test code annotates a callback parameter with `any`, which is explicitly prohibited by the custom rule. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=1072aa39d6894893b877b3a661b43ad9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=1072aa39d6894893b877b3a661b43ad9&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx **Line:** 139:139 **Comment:** *Custom Rule: Replace the `any` annotation in the `forEach` callback with a concrete feature/data-point type that includes the `color` field used in assertions. 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. 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> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=4455fad5aabf206e821b89afa9c0337a31c37e4f564e34ca169ea323b5bffbd3&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=4455fad5aabf206e821b89afa9c0337a31c37e4f564e34ca169ea323b5bffbd3&reaction=dislike'>👎</a> ########## superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx: ########## @@ -0,0 +1,148 @@ +/** + * 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 { render, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import { supersetTheme, ThemeProvider } from '@apache-superset/core/theme'; +import { Provider } from 'react-redux'; +import { configureStore } from '@reduxjs/toolkit'; +import { DatasourceType, SupersetClient } from '@superset-ui/core'; +import DeckMulti from './Multi'; + +// Capture the layers handed to the DeckGL container so we can inspect the +// per-feature colors that were resolved for each sublayer. +const mockLayerCapture: { layers: any[] } = { layers: [] }; +jest.mock('../DeckGLContainer', () => ({ + DeckGLContainerStyledWrapper: ({ layers }: any) => { + mockLayerCapture.layers = layers || []; + return <div data-test="deckgl-container">DeckGL Container Mock</div>; + }, +})); + +jest.mock('@superset-ui/core', () => ({ + ...jest.requireActual('@superset-ui/core'), + SupersetClient: { + get: jest.fn(), + }, +})); + +const mockStore = configureStore({ + reducer: { + dataMask: () => ({}), + }, +}); + +const renderWithProviders = (component: React.ReactElement) => + render( + <Provider store={mockStore}> + <ThemeProvider theme={supersetTheme}>{component}</ThemeProvider> + </Provider>, + ); + +const SCATTER_SLICE_ID = 1; + +const props = { + formData: { + datasource: '1__table', + viz_type: 'deck_multi', + deck_slices: [SCATTER_SLICE_ID], + autozoom: false, + map_style: 'mapbox://styles/mapbox/light-v9', + }, + payload: { + data: { + slices: [ + { + slice_id: SCATTER_SLICE_ID, + form_data: { + viz_type: 'deck_scatter', + datasource: '1__table', + slice_id: SCATTER_SLICE_ID, + // categorical color configuration coming from the saved scatter chart + color_scheme_type: 'categorical_palette', + color_scheme: 'supersetColors', + dimension: 'category', + }, + }, + ], + features: { + deck_scatter: [], + }, + mapboxApiKey: 'test-key', + }, + }, + setControlValue: jest.fn(), + viewport: { longitude: 0, latitude: 0, zoom: 1 }, + onAddFilter: jest.fn(), + height: 600, + width: 800, + datasource: { + id: 1, + type: DatasourceType.Table, + name: 'test_datasource', + columns: [], + metrics: [], + columnFormats: {}, + currencyFormats: {}, + verboseMap: {}, + }, + onSelect: jest.fn(), +}; + +beforeEach(() => { + jest.clearAllMocks(); + mockLayerCapture.layers = []; + // The scatter sublayer query returns features tagged with a category column. + (SupersetClient.get as jest.Mock).mockResolvedValue({ + json: { + data: { + features: [ + { position: [0, 0], radius: 1, cat_color: 'A' }, + { position: [1, 1], radius: 1, cat_color: 'B' }, + ], + }, + }, + }); +}); + +test('applies categorical scatterplot colors to sublayers in the multi chart', async () => { + renderWithProviders(<DeckMulti {...props} />); + + await waitFor(() => { + expect(mockLayerCapture.layers.length).toBeGreaterThan(0); + }); + + const scatterLayer = mockLayerCapture.layers.find((layer: any) => Review Comment: **Suggestion:** Use a concrete layer type (or a narrowed structural type) for the `find` callback parameter instead of `any`. [custom_rule] **Severity Level:** Minor ⚠️ <details> <summary><b>Why it matters? 🤔 </b></summary> This is modified TypeScript test code using `any` in a callback parameter, which directly violates the stated TypeScript/TSX `any` rule. </details> [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9af548b85f6647b1b16cf112f709ab4f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9af548b85f6647b1b16cf112f709ab4f&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset-frontend/plugins/preset-chart-deckgl/src/Multi/Multi.color.test.tsx **Line:** 130:130 **Comment:** *Custom Rule: Use a concrete layer type (or a narrowed structural type) for the `find` callback parameter instead of `any`. 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. 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> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=4451dabcbcfdc019920abab5724d7bd4c258508bc1969e9058fc92ff9e293626&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41490&comment_hash=4451dabcbcfdc019920abab5724d7bd4c258508bc1969e9058fc92ff9e293626&reaction=dislike'>👎</a> -- 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]
