fix: remove -1,-1 from owners request in charts, dashboards list and propertiesModal (#9989)

This commit is contained in:
ʈᵃᵢ 2020-06-04 15:31:42 -07:00 committed by GitHub
parent 543a3ca6f2
commit 619fbc9557
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 17 deletions

View File

@ -16,7 +16,7 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import React, { useState, useRef } from 'react'; import React, { useState } from 'react';
import styled from '@superset-ui/style'; import styled from '@superset-ui/style';
import { withTheme } from 'emotion-theming'; import { withTheme } from 'emotion-theming';
@ -97,9 +97,6 @@ function SelectFilter({
}; };
const options = [clearFilterSelect, ...selects]; const options = [clearFilterSelect, ...selects];
const optionsCache: React.MutableRefObject<SelectOption[] | null> = useRef(
null,
);
const [selectedOption, setSelectedOption] = useState(clearFilterSelect); const [selectedOption, setSelectedOption] = useState(clearFilterSelect);
const onChange = (selected: SelectOption | null) => { const onChange = (selected: SelectOption | null) => {
@ -110,11 +107,8 @@ function SelectFilter({
setSelectedOption(selected); setSelectedOption(selected);
}; };
const fetchAndFormatSelects = async (inputValue: string) => { const fetchAndFormatSelects = async (inputValue: string) => {
// only include clear filter when filter value exists // only include clear filter when filter value does not exist
let result = inputValue ? [] : [clearFilterSelect]; let result = inputValue ? [] : [clearFilterSelect];
// only call fetch once
// TODO: allow real async search with `inputValue`
if (optionsCache.current) return optionsCache.current;
if (fetchSelects) { if (fetchSelects) {
const selectValues = await fetchSelects(inputValue); const selectValues = await fetchSelects(inputValue);
// update matching option at initial load // update matching option at initial load
@ -124,7 +118,6 @@ function SelectFilter({
} }
result = [...result, ...selectValues]; result = [...result, ...selectValues];
} }
optionsCache.current = result;
return result; return result;
}; };

View File

@ -122,8 +122,6 @@ function PropertiesModal({ slice, onHide, onSave }: InternalProps) {
const loadOptions = (input = '') => { const loadOptions = (input = '') => {
const query = rison.encode({ const query = rison.encode({
filter: input, filter: input,
page_index: -1,
page_size: -1,
}); });
return SupersetClient.get({ return SupersetClient.get({
endpoint: `/api/v1/chart/related/owners?q=${query}`, endpoint: `/api/v1/chart/related/owners?q=${query}`,

View File

@ -364,13 +364,17 @@ class ChartList extends React.PureComponent<Props, State> {
}); });
}; };
fetchOwners = async (filterValue = '', pageIndex = -1, pageSize = -1) => { fetchOwners = async (
filterValue = '',
pageIndex?: number,
pageSize?: number,
) => {
const resource = '/api/v1/chart/related/owners'; const resource = '/api/v1/chart/related/owners';
try { try {
const queryParams = rison.encode({ const queryParams = rison.encode({
page: pageIndex, ...(pageIndex ? { page: pageIndex } : {}),
page_size: pageSize, ...(pageSize ? { page_ize: pageSize } : {}),
...(filterValue ? { filter: filterValue } : {}), ...(filterValue ? { filter: filterValue } : {}),
}); });
const { json = {} } = await SupersetClient.get({ const { json = {} } = await SupersetClient.get({
@ -384,6 +388,7 @@ class ChartList extends React.PureComponent<Props, State> {
}), }),
); );
} catch (e) { } catch (e) {
console.error(e);
this.props.addDangerToast( this.props.addDangerToast(
t( t(
'An error occurred while fetching chart owner values: %s', 'An error occurred while fetching chart owner values: %s',

View File

@ -389,13 +389,17 @@ class DashboardList extends React.PureComponent<Props, State> {
}); });
}; };
fetchOwners = async (filterValue = '', pageIndex = -1, pageSize = -1) => { fetchOwners = async (
filterValue = '',
pageIndex?: number,
pageSize?: number,
) => {
const resource = '/api/v1/dashboard/related/owners'; const resource = '/api/v1/dashboard/related/owners';
try { try {
const queryParams = rison.encode({ const queryParams = rison.encode({
page: pageIndex, ...(pageIndex ? { page: pageIndex } : {}),
page_size: pageSize, ...(pageSize ? { page_ize: pageSize } : {}),
...(filterValue ? { filter: filterValue } : {}), ...(filterValue ? { filter: filterValue } : {}),
}); });
const { json = {} } = await SupersetClient.get({ const { json = {} } = await SupersetClient.get({
@ -409,6 +413,7 @@ class DashboardList extends React.PureComponent<Props, State> {
}), }),
); );
} catch (e) { } catch (e) {
console.error(e);
this.props.addDangerToast( this.props.addDangerToast(
t( t(
'An error occurred while fetching chart owner values: %s', 'An error occurred while fetching chart owner values: %s',