rusackas commented on code in PR #37625:
URL: https://github.com/apache/superset/pull/37625#discussion_r2766055597
##########
superset-frontend/src/components/Datasource/utils/index.ts:
##########
@@ -16,44 +16,125 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { Children, cloneElement } from 'react';
+import {
+ Children,
+ cloneElement,
+ ReactNode,
+ ReactElement,
+ isValidElement,
+} from 'react';
import { nanoid } from 'nanoid';
import { SupersetClient } from '@superset-ui/core';
import { tn } from '@apache-superset/core/ui';
import rison from 'rison';
-export function recurseReactClone(children, type, propExtender) {
+// Type definitions
+
+interface ColumnMetadata {
+ id?: string | number;
+ column_name: string;
+ is_dttm?: boolean;
+ type?: string;
+ groupby?: boolean;
+ filterable?: boolean;
+ expression?: string;
+}
+
+interface ColumnChanges {
+ added: string[];
+ modified: string[];
+ removed: string[];
+ finalColumns: ColumnMetadata[];
+}
+
+interface DatasourceForSync {
+ type?: string;
+ datasource_type?: string;
+ database?: {
+ database_name?: string;
+ name?: string;
+ };
+ catalog?: string;
+ schema?: string;
+ table_name?: string;
+ normalize_columns?: boolean;
+ always_filter_main_dttm?: boolean;
+}
+
+interface SyncParams {
+ datasource_type?: string | null;
+ database_name?: string | null;
+ catalog_name?: string | null;
+ schema_name?: string | null;
+ table_name?: string | null;
+ normalize_columns?: boolean | null;
+ always_filter_main_dttm?: boolean | null;
+ [key: string]: string | boolean | null | undefined;
+}
+
+// React element type to match against in recurseReactClone
+interface ComponentType {
+ name: string;
+}
+
+export function recurseReactClone<T extends Record<string, unknown>>(
+ children: ReactNode,
+ type: ComponentType,
+ propExtender: (child: ReactElement<T>) => Record<string, unknown>,
+): ReactNode {
Review Comment:
The Record<string, unknown> constraint and return type are appropriate here
because:
1. The function is a generic utility that recursively clones React
elements and injects arbitrary extra props. The
propExtender callback returns new props to spread onto the cloned element
— these are inherently a bag of arbitrary key-value pairs.
2. Using Partial<T> as the return type of propExtender would be more
restrictive than needed. The propExtender might add props that aren't part of T
(like event handlers or data attributes injected from a parent). The whole
purpose is to extend the props beyond what the child originally has.
3. The constraint T extends Record<string, unknown> is the standard way to
say "T must be a props-like object." Narrowing this further would limit which
component types can be used with this utility, defeating its purpose.
The type is already as precise as it should be for a generic React child
cloning utility.
--
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]