浏览代码

feature/14-code-cleanup

Azat Gataullin 5 年之前
父节点
当前提交
3c4c9c1ef9

+ 3 - 3
kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamAction.tsx

@@ -1,5 +1,5 @@
 import React from 'react';
-import CustomParamButton from './CustomParamButton';
+import CustomParamButton, { CustomParamButtonType } from './CustomParamButton';
 import { isFirstParam } from './CustomParams';
 
 interface Props {
@@ -17,8 +17,8 @@ const CustomParamAction: React.FC<Props> = ({
     <label className='label'>&nbsp;</label>
     {
       isFirstParam(index)
-        ? <CustomParamButton btnColor="is-success" btnIcon='fa-plus' onClick={onAdd} />
-        : <CustomParamButton btnColor="is-danger" btnIcon='fa-minus' onClick={() => onRemove(index)} />
+        ? <CustomParamButton className="is-success" type={CustomParamButtonType.plus} onClick={onAdd} />
+        : <CustomParamButton className="is-danger" type={CustomParamButtonType.minus} onClick={() => onRemove(index)} />
     }
   </>
 )

+ 11 - 6
kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamButton.tsx

@@ -1,19 +1,24 @@
 import React from 'react';
 
+export enum CustomParamButtonType {
+  plus = 'fa-plus',
+  minus = 'fa-minus',
+}
+
 interface Props {
   onClick: (event: React.MouseEvent<HTMLButtonElement>) => void,
-  btnColor: string;
-  btnIcon: string;
+  className: string;
+  type: CustomParamButtonType;
 }
 
 const CustomParamButton: React.FC<Props> = ({
   onClick,
-  btnColor,
-  btnIcon,
+  className,
+  type,
 }) => (
-  <button className={`button ${btnColor} is-outlined`} onClick={onClick}>
+  <button className={`button ${className} is-outlined`} onClick={onClick}>
     <span className="icon">
-      <i className={`fas fa-lg ${btnIcon}`}></i>
+      <i className={`fas fa-lg ${type}`}></i>
     </span>
   </button>
 )

+ 1 - 1
kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamSelect.tsx

@@ -24,7 +24,7 @@ const CustomParamSelect: React.FC<Props> = ({
   );
 
   const selectedMustBeUniq = (selected: string) => {
-    const values: any = getValues({ nest: true });
+    const values = getValues({ nest: true });
     const customParamsValues: TopicFormCustomParam = values.customParams;
 
     let valid = true;

+ 1 - 1
kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParamValue.tsx

@@ -20,7 +20,7 @@ const CustomParamValue: React.FC<Props> = ({
   const { register, unregister, errors, watch, setValue } = useFormContext();
   const selectInputName: string = `${index}[name]`;
   const valInputName: string    = `${index}[value]`;
-  const selectedParamName: any  = watch(selectInputName, name);
+  const selectedParamName = watch(selectInputName, name);
 
   React.useEffect(
     () => {

+ 4 - 4
kafka-ui-react-app/src/components/Topics/New/CustomParams/CustomParams.tsx

@@ -6,9 +6,9 @@ import CustomParamSelect from './CustomParamSelect';
 import CustomParamValue from './CustomParamValue';
 import CustomParamAction from './CustomParamAction';
 
-const DEF_INDEX = 'default';
+const DEFAULT_INDEX = 'default';
 export const INDEX_PREFIX = 'customParams';
-export const isFirstParam = (index: string) => (index === DEF_INDEX);
+export const isFirstParam = (index: string) => (index === DEFAULT_INDEX);
 
 interface Props {
   isSubmitting: boolean;
@@ -19,8 +19,8 @@ const CustomParams: React.FC<Props> = ({
 }) => {
 
   const [formCustomParams, setFormCustomParams] = React.useState<TopicFormCustomParams>({
-    byIndex: { [DEF_INDEX]: { name: '', value: '' } },
-    allIndexes: [DEF_INDEX],
+    byIndex: { [DEFAULT_INDEX]: { name: '', value: '' } },
+    allIndexes: [DEFAULT_INDEX],
   });
 
   const onAdd = (event: React.MouseEvent<HTMLButtonElement>) => {