msyavuz commented on code in PR #34876: URL: https://github.com/apache/superset/pull/34876#discussion_r2321273993
########## 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: Agreed, maybe we can specify the usage and call it something like `mergeThemeConfigs`? ########## 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: I gave this some thought as well but I don't think this couples echarts with core that much. Having options for each viz library in the theme config without abstractions is simple enough and if we make the theme extendible it seems to solve our issues. Suppose we make the theme itself extendible and use keys like echartsOptionsOverrides etc. If user wants to create a viz plugin they just need to extend the theme with their own keys like d3ChartsOptions and merge the options there just like Max did here with Echarts. That looks like a simple and straightforward flow to me. -- 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: notifications-unsubscr...@superset.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org For additional commands, e-mail: notifications-h...@superset.apache.org