etr2460 commented on a change in pull request #16393:
URL: https://github.com/apache/superset/pull/16393#discussion_r697536808



##########
File path: superset-frontend/src/components/ListView/Filters/Select.tsx
##########
@@ -75,78 +61,53 @@ function SelectFilter({
   }
 
   const [selectedOption, setSelectedOption] = useState(initialOption);
-  const onChange = (selected: SelectOption | null) => {
-    if (selected === null) return;
+  const onChange = (selected: SelectOption) => {
     onSelect(
       selected.value === CLEAR_SELECT_FILTER_VALUE ? undefined : 
selected.value,
     );
     setSelectedOption(selected);
   };
 
-  const fetchAndFormatSelects = async (
-    inputValue: string,
-    loadedOptions: SelectOption[],
-    { page }: { page: number },
-  ) => {
-    // only include clear filter when filter value does not exist
-    let result = inputValue || page > 0 ? [] : [clearFilterSelect];
-    let hasMore = paginate;
-    if (fetchSelects) {
-      const selectValues = await fetchSelects(inputValue, page);
-      // update matching option at initial load
-      if (!selectValues.length) {
-        hasMore = false;
-      }
-      result = [...result, ...selectValues];
+  const fetchAndFormatSelects = useMemo(
+    () => async (inputValue: string, page: number, pageSize: number) => {
+      // only include clear filter when filter value does not exist
+      let result = inputValue || page > 0 ? [] : [clearFilterSelect];
+      if (fetchSelects) {
+        const selectValues = await fetchSelects(inputValue, page, pageSize);
+        const totalCount = selectValues.totalCount + result.length;
+        result = [...result, ...selectValues.data];
 
-      const matchingOption = result.find(x => x.value === initialValue);
+        const matchingOption = result.find(x => x.value === initialValue);
+        if (matchingOption) {
+          setSelectedOption(matchingOption);
+        }
 
-      if (matchingOption) {
-        setSelectedOption(matchingOption);
+        return {
+          data: result,
+          totalCount,
+        };
       }
-    }
-
-    return {
-      options: result,
-      hasMore,
-      additional: {
-        page: page + 1,
-      },
-    };
-  };
+      return {
+        data: [],
+        totalCount: 0,
+      };
+    },
+    [], // eslint-disable-line react-hooks/exhaustive-deps

Review comment:
       shouldn't we add in the dependencies here?

##########
File path: superset-frontend/src/components/ListView/Filters/Select.tsx
##########
@@ -75,78 +61,53 @@ function SelectFilter({
   }
 
   const [selectedOption, setSelectedOption] = useState(initialOption);
-  const onChange = (selected: SelectOption | null) => {
-    if (selected === null) return;
+  const onChange = (selected: SelectOption) => {
     onSelect(
       selected.value === CLEAR_SELECT_FILTER_VALUE ? undefined : 
selected.value,
     );
     setSelectedOption(selected);
   };
 
-  const fetchAndFormatSelects = async (
-    inputValue: string,
-    loadedOptions: SelectOption[],
-    { page }: { page: number },
-  ) => {
-    // only include clear filter when filter value does not exist
-    let result = inputValue || page > 0 ? [] : [clearFilterSelect];
-    let hasMore = paginate;
-    if (fetchSelects) {
-      const selectValues = await fetchSelects(inputValue, page);
-      // update matching option at initial load
-      if (!selectValues.length) {
-        hasMore = false;
-      }
-      result = [...result, ...selectValues];
+  const fetchAndFormatSelects = useMemo(
+    () => async (inputValue: string, page: number, pageSize: number) => {
+      // only include clear filter when filter value does not exist
+      let result = inputValue || page > 0 ? [] : [clearFilterSelect];
+      if (fetchSelects) {
+        const selectValues = await fetchSelects(inputValue, page, pageSize);
+        const totalCount = selectValues.totalCount + result.length;
+        result = [...result, ...selectValues.data];
 
-      const matchingOption = result.find(x => x.value === initialValue);
+        const matchingOption = result.find(x => x.value === initialValue);
+        if (matchingOption) {
+          setSelectedOption(matchingOption);
+        }
 
-      if (matchingOption) {
-        setSelectedOption(matchingOption);
+        return {
+          data: result,
+          totalCount,
+        };
       }
-    }
-
-    return {
-      options: result,
-      hasMore,
-      additional: {
-        page: page + 1,
-      },
-    };
-  };
+      return {
+        data: [],
+        totalCount: 0,
+      };
+    },
+    [], // eslint-disable-line react-hooks/exhaustive-deps
+  );
 
   return (
     <FilterContainer>
-      <FilterTitle>{Header}:</FilterTitle>
-      {fetchSelects ? (
-        <PaginatedSelect
-          data-test="filters-select"
-          defaultOptions
-          themeConfig={filterSelectTheme}
-          stylesConfig={filterSelectStyles}
-          // @ts-ignore
-          value={selectedOption}
-          // @ts-ignore
-          onChange={onChange}
-          // @ts-ignore
-          loadOptions={fetchAndFormatSelects}
-          placeholder={emptyLabel}
-          clearable={false}
-          additional={{
-            page: 0,
-          }}
-        />
-      ) : (
-        <Select
-          data-test="filters-select"
-          themeConfig={filterSelectTheme}
-          stylesConfig={filterSelectStyles}
-          value={selectedOption}
-          options={options}
-          onChange={onChange}
-          clearable={false}
-        />
-      )}
+      <Select
+        ariaLabel={typeof Header === 'string' ? Header : emptyLabel}

Review comment:
       since `Header` can be a react node too, this would mean we'd have a11y 
text of `None` for a custom rendered header. seems less than ideal

##########
File path: superset-frontend/src/components/ListView/Filters/index.tsx
##########
@@ -34,17 +34,13 @@ interface UIFiltersProps {
   updateFilterValue: (id: number, value: FilterValue['value']) => void;
 }
 
-const FilterWrapper = styled.div`
-  display: inline-block;
-`;
-
 function UIFilters({
   filters,
   internalFilters = [],
   updateFilterValue,
 }: UIFiltersProps) {
   return (
-    <FilterWrapper>
+    <>

Review comment:
       do we need this? i'm a bit rusty, but i _thought_ you could return an 
array as a react component too




-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



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

Reply via email to