瀏覽代碼

move generateHashCode to common utils

czhen 4 年之前
父節點
當前提交
f126b32b3f
共有 2 個文件被更改,包括 15 次插入14 次删除
  1. 2 14
      client/src/components/advancedSearch/Filter.tsx
  2. 13 0
      client/src/utils/Common.ts

+ 2 - 14
client/src/components/advancedSearch/Filter.tsx

@@ -10,19 +10,7 @@ import {
 import FilterListIcon from '@material-ui/icons/FilterList';
 import FilterListIcon from '@material-ui/icons/FilterList';
 import AdvancedDialog from './Dialog';
 import AdvancedDialog from './Dialog';
 import { FilterProps, Field } from './Types';
 import { FilterProps, Field } from './Types';
-
-const generateHashCode = (source: string) => {
-  var hash = 0,
-    i,
-    chr;
-  if (source.length === 0) return hash;
-  for (i = 0; i < source.length; i++) {
-    chr = source.charCodeAt(i);
-    hash = (hash << 5) - hash + chr;
-    hash |= 0; // Convert to 32bit integer
-  }
-  return hash.toString();
-};
+import { generateHashCode } from '../../utils/Common';
 
 
 const Filter = function Filter(props: FilterProps) {
 const Filter = function Filter(props: FilterProps) {
   const {
   const {
@@ -69,7 +57,7 @@ const Filter = function Filter(props: FilterProps) {
       }
       }
     }
     }
     setIsConditionsLegal(true);
     setIsConditionsLegal(true);
-    generateExpression(flatConditions, setFilterExpression);    
+    generateExpression(flatConditions, setFilterExpression);
   }, [flatConditions]);
   }, [flatConditions]);
 
 
   const setFilteredFlatConditions = (conditions: any[]) => {
   const setFilteredFlatConditions = (conditions: any[]) => {

+ 13 - 0
client/src/utils/Common.ts

@@ -44,3 +44,16 @@ export const findKeyValue = (
   obj: { key: string; value: string }[],
   obj: { key: string; value: string }[],
   key: string
   key: string
 ) => obj.find(v => v.key === key)?.value;
 ) => obj.find(v => v.key === key)?.value;
+
+export const generateHashCode = (source: string) => {
+  var hash = 0,
+    i,
+    chr;
+  if (source.length === 0) return hash;
+  for (i = 0; i < source.length; i++) {
+    chr = source.charCodeAt(i);
+    hash = (hash << 5) - hash + chr;
+    hash |= 0; // Convert to 32bit integer
+  }
+  return hash.toString();
+};