Ver código fonte

[frontend] Improvements and added 118n to default props

Nidhi Bhat G 1 ano atrás
pai
commit
129b43f030

+ 10 - 12
desktop/core/src/desktop/js/apps/storageBrowser/InputModal/InputModal.tsx

@@ -17,33 +17,32 @@ import React, { useState } from 'react';
 import Modal from 'cuix/dist/components/Modal';
 import { Input } from 'antd';
 
+import { i18nReact } from '../../../utils/i18nReact';
+
 import './InputModal.scss';
 
+//TODO: Add unit tests
 interface InputModalProps {
   cancelText?: string;
   inputLabel: string;
   submitText?: string;
   onClose: () => void;
-  onCreate: (value: string) => void;
+  onSubmit: (value: string) => void;
   showModal: boolean;
   title: string;
 }
 
-const defaultProps = {
-  cancelText: 'Cancel',
-  submitText: 'Submit'
-};
-
 const InputModal: React.FC<InputModalProps> = ({
-  cancelText,
   inputLabel,
-  submitText,
   onClose,
-  onCreate,
+  onSubmit,
   showModal,
-  title
+  title,
+  ...i18n
 }): JSX.Element => {
   const [value, setValue] = useState<string>('');
+  const { t } = i18nReact.useTranslation();
+  const { cancelText = t('Close'), submitText = t('Submit') } = i18n;
 
   return (
     <Modal
@@ -55,7 +54,7 @@ const InputModal: React.FC<InputModalProps> = ({
         onClose();
       }}
       onOk={() => {
-        onCreate(value);
+        onSubmit(value);
         setValue('');
         onClose();
       }}
@@ -74,5 +73,4 @@ const InputModal: React.FC<InputModalProps> = ({
   );
 };
 
-InputModal.defaultProps = defaultProps;
 export default InputModal;

+ 6 - 6
desktop/core/src/desktop/js/apps/storageBrowser/StorageBrowserPage/StorageBrowserTabContents/StorageBrowserTabContent.tsx

@@ -68,8 +68,8 @@ const StorageBrowserTabContent: React.FC<StorageBrowserTabContentProps> = ({
   const [sortOrder, setSortOrder] = useState<SortOrder>(SortOrder.NONE);
   //TODO: Add filter functionality
   const [filterData] = useState<string>('');
-  const [showNewFolderModal, setShowNewFolderModal] = useState<boolean>();
-  const [showNewFileModal, setShowNewFileModal] = useState<boolean>();
+  const [showNewFolderModal, setShowNewFolderModal] = useState<boolean>(false);
+  const [showNewFileModal, setShowNewFileModal] = useState<boolean>(false);
   const [refreshKey, setRefreshKey] = useState<number>(0);
 
   const { t } = i18nReact.useTranslation();
@@ -260,17 +260,17 @@ const StorageBrowserTabContent: React.FC<StorageBrowserTabContentProps> = ({
         <InputModal
           title={t('Create New Folder')}
           inputLabel={t('Enter Folder name here')}
-          okText={t('Create')}
+          submitText={t('Create')}
           showModal={showNewFolderModal}
-          onCreate={handleCreateNewFolder}
+          onSubmit={handleCreateNewFolder}
           onClose={() => setShowNewFolderModal(false)}
         />
         <InputModal
           title={t('Create New File')}
           inputLabel={t('Enter File name here')}
-          okText={t('Create')}
+          submitText={t('Create')}
           showModal={showNewFileModal}
-          onCreate={handleCreateNewFile}
+          onSubmit={handleCreateNewFile}
           onClose={() => setShowNewFileModal(false)}
         />
       </div>