korbit-ai[bot] commented on code in PR #35222:
URL: https://github.com/apache/superset/pull/35222#discussion_r2365737648


##########
superset-frontend/src/components/MessageToasts/NotificationProvider.tsx:
##########
@@ -0,0 +1,96 @@
+/**
+ * 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 { notification as antdNotification } from 'antd';
+import { createContext, useContext, useMemo, ReactNode } from 'react';
+import type { NotificationInstance } from 'antd/es/notification/interface';
+
+export type NotificationType = 'success' | 'info' | 'warning' | 'error';
+
+export type NotificationPlacement =
+  | 'top'
+  | 'topLeft'
+  | 'topRight'
+  | 'bottom'
+  | 'bottomLeft'
+  | 'bottomRight';
+
+export interface NotificationArgsProps {
+  message: ReactNode;
+  description?: ReactNode;
+  btn?: ReactNode;
+  key?: string;
+  onClose?: () => void;
+  duration?: number | null;
+  icon?: ReactNode;
+  placement?: NotificationPlacement;
+  className?: string;
+  onClick?: () => void;
+  closeIcon?: boolean | ReactNode;
+  role?: 'alert' | 'status';
+}
+
+export type NotificationApi = NotificationInstance;
+
+export interface NotificationContextType {
+  api: NotificationApi;
+  success: (args: NotificationArgsProps) => void;
+  error: (args: NotificationArgsProps) => void;
+  warning: (args: NotificationArgsProps) => void;
+  info: (args: NotificationArgsProps) => void;
+  open: (args: NotificationArgsProps & { type?: NotificationType }) => void;
+  destroy: (key?: string) => void;
+}
+
+const NotificationContext = createContext<NotificationContextType | undefined>(
+  undefined,
+);
+
+export const NotificationProvider = ({ children }: { children: ReactNode }) => 
{
+  const [api, contextHolder] = antdNotification.useNotification();
+
+  const value = useMemo<NotificationContextType>(
+    () => ({
+      api,
+      success: args => api.success(args),
+      error: args => api.error(args),
+      warning: args => api.warning(args),
+      info: args => api.info(args),
+      open: args => api.open(args),
+      destroy: (key?: string) => api.destroy(key),
+    }),
+    [api],
+  );

Review Comment:
   ### Unnecessary function wrappers <sub>![category 
Design](https://img.shields.io/badge/Design-0d9488)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The implementation contains unnecessary wrapper functions that simply pass 
through arguments without adding any value.
   
   
   ###### Why this matters
   These wrapper functions add complexity without benefit and could impact 
performance by creating new function instances on each render.
   
   ###### Suggested change ∙ *Feature Preview*
   ```typescript
   const value = useMemo<NotificationContextType>(
     () => ({
       success: api.success,
       error: api.error,
       warning: api.warning,
       info: api.info,
       open: api.open,
       destroy: api.destroy,
     }),
     [api],
   );
   ```
   
   
   ###### Provide feedback to improve future suggestions
   [![Nice 
Catch](https://img.shields.io/badge/👍%20Nice%20Catch-71BC78)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/576f12c9-9fce-441e-8c1f-b61ac623cedf/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/576f12c9-9fce-441e-8c1f-b61ac623cedf?what_not_true=true)
  [![Not in 
Scope](https://img.shields.io/badge/👎%20Out%20of%20PR%20scope-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/576f12c9-9fce-441e-8c1f-b61ac623cedf?what_out_of_scope=true)
 [![Not in coding 
standard](https://img.shields.io/badge/👎%20Not%20in%20our%20standards-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/576f12c9-9fce-441e-8c1f-b61ac623cedf?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/576f12c9-9fce-441e-8c1f-b61ac623cedf)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:b7dd2dba-25f2-4a71-bf06-d3bd2abea673 -->
   
   
   [](b7dd2dba-25f2-4a71-bf06-d3bd2abea673)



-- 
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]

Reply via email to