villebro commented on code in PR #34876: URL: https://github.com/apache/superset/pull/34876#discussion_r2320341868
########## superset-frontend/packages/superset-ui-core/src/utils/lodash.ts: ########## @@ -0,0 +1,52 @@ +/** + * 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 { mergeWith } from 'lodash'; + +/** + * Merges objects using lodash.mergeWith, but replaces arrays instead of concatenating them. + * This is useful for configuration objects where you want to completely override array values + * rather than merge them by index. + * + * @example + * const obj1 = { a: [1, 2], b: { c: 3 } }; + * const obj2 = { a: [4, 5], b: { d: 6 } }; + * mergeReplaceArrays(obj1, obj2); + * // Result: { a: [4, 5], b: { c: 3, d: 6 } } + * + * @example + * // ECharts configuration merging + * const baseConfig = { series: [{ type: 'line' }], grid: { left: '10%' } }; + * const overrides = { series: [{ type: 'bar' }], grid: { right: '10%' } }; + * mergeReplaceArrays(baseConfig, overrides); + * // Result: { series: [{ type: 'bar' }], grid: { left: '10%', right: '10%' } } + * + * @param sources - Objects to merge (rightmost wins for arrays, deep merge for objects) + * @returns Merged object with arrays replaced, not concatenated + */ +export function mergeReplaceArrays<T = any>(...sources: any[]): T { + const replaceArrays = (objValue: any, srcValue: any) => { + if (Array.isArray(srcValue)) { + return srcValue; // Replace arrays entirely + } + return undefined; // Let lodash handle object merging for non-arrays + }; + + return mergeWith({}, ...sources, replaceArrays); +} Review Comment: I think calling this utility `lodash` is confusing, as it collides with the actual `lodash` package name. Furthermore, this appears to be a very thin wrapper around `loads.mergeWith`. If we really need a util for this, I propose calling it something more generic that decouples it from the implementation. If we ever swap out `lodash` for something else, this name will no longer be accurate. ########## superset-frontend/packages/superset-ui-core/src/theme/types.ts: ########## @@ -127,6 +127,15 @@ export interface SupersetSpecificTokens { // Spinner-related brandSpinnerUrl?: string; brandSpinnerSvg?: string; + + // ECharts-related + /** Global ECharts configuration overrides applied to all chart types */ + echartsOptionsOverrides?: any; Review Comment: While ECharts is our main viz library, we do have others that may also need library-level overriding. Also, in the future we expect other viz extensions to pop up (e.g. D3 based), and for those this approach of overriding "the option" will not be the correct solution. So I wonder if we should instead leave this more generic, so that you can pass some type of mutator per library type, and that then applies the necessary changes? -- 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]
