vogievetsky commented on a change in pull request #7507: Fixed filter for 
status in task table
URL: https://github.com/apache/incubator-druid/pull/7507#discussion_r277062968
 
 

 ##########
 File path: web-console/src/utils/general.tsx
 ##########
 @@ -66,28 +66,48 @@ export function makeBooleanFilter(): FilterRender {
   };
 }
 
-export function customTableFilter(filter: Filter, clientSideFilter: boolean, 
value?: any): boolean | string {
-  if (clientSideFilter && value === undefined) {
-    return true;
+// ----------------------------
+
+interface NeedleAndMode {
+  needle: string;
+  mode: 'exact' | 'prefix';
+}
+
+function getNeedleAndMode(filter: Filter): NeedleAndMode {
+  const input = filter.value.toLowerCase();
+  if (input.startsWith(`"`) && input.endsWith(`"`)) {
+    return {
+      needle: input.slice(1, -1),
+      mode: 'exact'
+    };
   }
-  const targetValue = (clientSideFilter && String(value.toLowerCase())) || 
JSON.stringify(filter.id).toLowerCase();
-  let filterValue = filter.value.toLowerCase();
-  if (filterValue.startsWith(`"`) && filterValue.endsWith(`"`)) {
-    const exactString = filterValue.slice(1, -1);
-    if (clientSideFilter) {
-      return String(targetValue) === exactString;
-    } else {
-      return `${targetValue} = '${exactString}'`;
-    }
+  return {
+    needle: input.startsWith(`"`) ? input.substring(1) : input,
+    mode: 'prefix'
+  };
+}
+
+export function booleanCustomTableFilter(filter: Filter, value: any): boolean {
+  if (value === undefined) {
+    return true;
   }
-  if (filterValue.startsWith(`"`)) {
-    filterValue = filterValue.substring(1);
+  const haystack = String(value.toLowerCase());
+  const needleAndMode: NeedleAndMode = getNeedleAndMode(filter);
+  const needle = needleAndMode.needle;
+  if (needleAndMode.mode === 'exact') {
+    return needle === haystack;
   }
-  if (clientSideFilter) {
-    return targetValue.includes(filterValue);
-  } else {
-    return `${targetValue} LIKE '%${filterValue}%'`;
+  return haystack.includes(needle);
+}
+
+export function sqlQueryCustomTableFilter(filter: Filter): string {
+  const columnName = JSON.stringify(filter.id).toLowerCase();
+  const needleAndMode: NeedleAndMode = getNeedleAndMode(filter);
+  const needle = needleAndMode.needle;
+  if (needleAndMode.mode === 'exact') {
+    return `${columnName} = '${needle}'`;
   }
+  return `${columnName} LIKE '%${needle}%'`;
 
 Review comment:
   we want prefix.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to