Copilot commented on code in PR #44967: URL: https://github.com/apache/superset/pull/44967#discussion_r4186889350
########## superset-frontend/src/explore/components/controls/ContourControl/ContourPopoverControl-unused-fields.test.tsx: ########## @@ -0,0 +1,56 @@ +/** + * 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, screen, userEvent } from 'spec/helpers/testing-library'; +import ContourPopoverControl from './ContourPopoverControl'; + +const color = { r: 255, g: 0, b: 255, a: 100 }; + +test('omits the unused upper threshold when saving an isoline', async () => { + const onSave = jest.fn(); + render( + <ContourPopoverControl + value={{ lowerThreshold: 4, color, strokeWidth: 2, zIndex: 10 }} + onSave={onSave} + />, + ); + + await userEvent.click(screen.getByRole('button', { name: 'Save' })); + + const saved = onSave.mock.calls[0][0]; + expect(saved.upperThreshold).toBeUndefined(); + expect(JSON.parse(JSON.stringify(saved))).not.toHaveProperty( + 'upperThreshold', + ); +}); Review Comment: These tests cover the regression for unused fields remaining `undefined`, but they don't assert that numeric coercion still happens for populated fields (the other half of `convertContourToNumeric` behavior). Consider adding an assertion that a string input (e.g., `lowerThreshold: '4'` or `strokeWidth: '2'`) is saved as a number, to guard against future changes that might skip conversion too broadly. ########## superset-frontend/src/explore/components/controls/ContourControl/ContourPopoverControl.tsx: ########## @@ -102,7 +102,9 @@ const convertContourToNumeric = (contour: ContourType) => { const formattedContour = { ...contour }; const numericKeys = ['lowerThreshold', 'upperThreshold', 'strokeWidth']; numericKeys.forEach(key => { - formattedContour[key] = Number(formattedContour[key]); + if (formattedContour[key] !== undefined) { + formattedContour[key] = Number(formattedContour[key]); + } }); return formattedContour; }; Review Comment: This guard preserves `undefined`, but `null` values will still be coerced to `0` (`Number(null) === 0`), which can unintentionally materialize an omitted field. If `null` is a possible value in the contour lifecycle (e.g., from persisted/rehydrated form data), consider skipping conversion for both `undefined` and `null` (e.g., a nullish check) so unused fields don't become `0`. -- 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]
