Просмотр исходного кода

Fix replicas / migration list search

Searching the replicas list by item title can filter out the desired
result if the "notes" field is used.
Sergiu Miclea 3 лет назад
Родитель
Сommit
ab22aa1a8b

+ 10 - 5
src/components/smart/MigrationsPage/MigrationsPage.tsx

@@ -174,16 +174,18 @@ class MigrationsPage extends React.Component<{ history: any }, State> {
     });
   }
 
-  searchText(item: MigrationItem, text?: string) {
+  searchText(item: MigrationItem, text: string) {
     let result = false;
-    if (item.instances[0].toLowerCase().indexOf(text || "") > -1) {
+    if (item.instances[0].toLowerCase().indexOf(text) > -1) {
+      return true;
+    }
+    if (item.notes.toLowerCase().indexOf(text) > -1) {
       return true;
     }
     if (item.destination_environment) {
       Object.keys(item.destination_environment).forEach(prop => {
         if (
-          item.destination_environment[prop] &&
-          item.destination_environment[prop].toLowerCase &&
+          item.destination_environment[prop]?.toLowerCase &&
           item.destination_environment[prop].toLowerCase().indexOf(text) > -1
         ) {
           result = true;
@@ -200,7 +202,10 @@ class MigrationsPage extends React.Component<{ history: any }, State> {
   ) {
     if (
       (filterStatus !== "all" && item.last_execution_status !== filterStatus) ||
-      !this.searchText(item, filterText)
+      !this.searchText(
+        item,
+        (filterText?.toLowerCase && filterText.toLowerCase()) || ""
+      )
     ) {
       return false;
     }

+ 10 - 5
src/components/smart/ReplicasPage/ReplicasPage.tsx

@@ -302,16 +302,18 @@ class ReplicasPage extends React.Component<{ history: any }, State> {
     }, SCHEDULE_POLL_TIMEOUT);
   }
 
-  searchText(item: ReplicaItem, text?: string | null) {
+  searchText(item: ReplicaItem, text: string) {
     let result = false;
-    if (item.instances[0].toLowerCase().indexOf(text || "") > -1) {
+    if (item.instances[0].toLowerCase().indexOf(text) > -1) {
+      return true;
+    }
+    if (item.notes.toLowerCase().indexOf(text) > -1) {
       return true;
     }
     if (item.destination_environment) {
       Object.keys(item.destination_environment).forEach(prop => {
         if (
-          item.destination_environment[prop] &&
-          item.destination_environment[prop].toLowerCase &&
+          item.destination_environment[prop]?.toLowerCase &&
           item.destination_environment[prop].toLowerCase().indexOf(text) > -1
         ) {
           result = true;
@@ -328,7 +330,10 @@ class ReplicasPage extends React.Component<{ history: any }, State> {
   ) {
     if (
       (filterStatus !== "all" && item.last_execution_status !== filterStatus) ||
-      !this.searchText(item, filterText)
+      !this.searchText(
+        item,
+        (filterText?.toLowerCase && filterText.toLowerCase()) || ""
+      )
     ) {
       return false;
     }