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


##########
superset-frontend/src/features/roles/RoleListDuplicateModal.tsx:
##########
@@ -0,0 +1,69 @@
+/**
+ * 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 { t } from '@superset-ui/core';
+import { RoleObject } from 'src/pages/RolesList';
+import { useToasts } from 'src/components/MessageToasts/withToasts';
+import FormModal from 'src/components/Modal/FormModal';
+import { RoleNameField } from './RoleFormItems';
+import { BaseModalProps, RoleForm } from './types';
+import { createRole, updateRolePermissions } from './utils';
+
+export interface RoleListDuplicateModalProps extends BaseModalProps {
+  role: RoleObject;
+}
+
+function RoleListDuplicateModal({
+  role,
+  show,
+  onHide,
+  onSave,
+}: RoleListDuplicateModalProps) {
+  const { name, permission_ids } = role;
+  const { addDangerToast, addSuccessToast } = useToasts();
+
+  const handleFormSubmit = async (values: RoleForm) => {
+    try {
+      const { json: roleResponse } = await createRole(values.roleName);
+
+      if (permission_ids.length > 0) {
+        await updateRolePermissions(roleResponse.id, permission_ids);
+      }
+      addSuccessToast(t('Role was successfully duplicated!'));
+    } catch (err) {
+      addDangerToast(t('Error while duplicating role!'));
+      throw err;
+    }
+  };
+
+  return (
+    <FormModal
+      show={show}
+      onHide={onHide}
+      title={t('Duplicate role %(name)s', { name })}
+      onSave={onSave}
+      formSubmitHandler={handleFormSubmit}
+      requiredFields={['roleName']}
+      initialValues={{}}

Review Comment:
   ### Unclear Empty Object Initialization <sub>![category 
Readability](https://img.shields.io/badge/Readability-0284c7)</sub>
   
   <details>
     <summary>Tell me more</summary>
   
   ###### What is the issue?
   The FormModal component receives an empty object as initialValues without 
explanation of what values could be initialized.
   
   ###### Why this matters
   Empty objects without context or typing make it unclear what data structure 
is expected, making the code harder to understand and maintain.
   
   ###### Suggested change ∙ *Feature Preview*
   ```typescript
   const defaultFormValues: RoleForm = { roleName: '' };
   ...
   initialValues={defaultFormValues}
   ```
   
   
   ###### 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/559cbefe-3a72-4f6a-a2f7-9c364840fe66/upvote)
 
[![Incorrect](https://img.shields.io/badge/👎%20Incorrect-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/559cbefe-3a72-4f6a-a2f7-9c364840fe66?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/559cbefe-3a72-4f6a-a2f7-9c364840fe66?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/559cbefe-3a72-4f6a-a2f7-9c364840fe66?what_not_in_standard=true)
 
[![Other](https://img.shields.io/badge/👎%20Other-white)](https://app.korbit.ai/feedback/aa91ff46-6083-4491-9416-b83dd1994b51/559cbefe-3a72-4f6a-a2f7-9c364840fe66)
   </details>
   
   <sub>
   
   💬 Looking for more details? Reply to this comment to chat with Korbit.
   </sub>
   
   <!--- korbi internal id:79ed14e8-d3f7-4200-947d-a2652cb63387 -->
   
   [](79ed14e8-d3f7-4200-947d-a2652cb63387)



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

Reply via email to