mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
feat: upgrade react-select and make multi-select sortable (#9628)
* feat: upgrade react-select v1.3.0 to v3.1.0 Upgrade `react-select`, replace `react-virtualized-select` with a custom solution implemented with `react-window`. Future plans include deprecate `react-virtualized` used in other places, too. Migrate all react-select related components to `src/Components/Select`. * Fix new list view * Fix tests * Address PR comments * Fix a flacky Cypress test * Adjust styles for Select in CRUD ListView * Fix loadOptions for owners select in chart PropertiesModal TODO: add typing support for AsyncSelect props. * Address PR comments; allow isMulti in SelectControl, too * Clean up NaN in table filter values * Fix flacky test
This commit is contained in:
@@ -28,7 +28,8 @@ import {
|
||||
} from 'react-bootstrap';
|
||||
// @ts-ignore
|
||||
import Dialog from 'react-bootstrap-dialog';
|
||||
import { Async as SelectAsync, Option } from 'react-select';
|
||||
import { OptionsType } from 'react-select/src/types';
|
||||
import { AsyncSelect } from 'src/components/Select';
|
||||
import rison from 'rison';
|
||||
import { t } from '@superset-ui/translation';
|
||||
import { SupersetClient, Json } from '@superset-ui/connection';
|
||||
@@ -48,6 +49,11 @@ type InternalProps = {
|
||||
onSave: (chart: Chart) => void;
|
||||
};
|
||||
|
||||
type OwnerOption = {
|
||||
label: string;
|
||||
value: number;
|
||||
};
|
||||
|
||||
export type WrapperProps = InternalProps & {
|
||||
show: boolean;
|
||||
animation?: boolean; // for the modal
|
||||
@@ -78,7 +84,7 @@ function PropertiesModal({ slice, onHide, onSave }: InternalProps) {
|
||||
const [cacheTimeout, setCacheTimeout] = useState(
|
||||
slice.cache_timeout != null ? slice.cache_timeout : '',
|
||||
);
|
||||
const [owners, setOwners] = useState<Option[] | null>(null);
|
||||
const [owners, setOwners] = useState<OptionsType<OwnerOption> | null>(null);
|
||||
|
||||
function showError({ error, statusText }: any) {
|
||||
errorDialog.current.show({
|
||||
@@ -120,15 +126,14 @@ function PropertiesModal({ slice, onHide, onSave }: InternalProps) {
|
||||
}).then(
|
||||
response => {
|
||||
const { result } = response.json as Json;
|
||||
const options = result.map((item: any) => ({
|
||||
return result.map((item: any) => ({
|
||||
value: item.value,
|
||||
label: item.text,
|
||||
}));
|
||||
return { options };
|
||||
},
|
||||
badResponse => {
|
||||
getClientErrorObject(badResponse).then(showError);
|
||||
return { options: [] };
|
||||
return [];
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -239,14 +244,16 @@ function PropertiesModal({ slice, onHide, onSave }: InternalProps) {
|
||||
<label className="control-label" htmlFor="owners">
|
||||
{t('Owners')}
|
||||
</label>
|
||||
<SelectAsync
|
||||
multi
|
||||
<AsyncSelect
|
||||
isMulti
|
||||
name="owners"
|
||||
value={owners || []}
|
||||
loadOptions={loadOptions}
|
||||
defaultOptions // load options on render
|
||||
cacheOptions
|
||||
onChange={setOwners}
|
||||
disabled={!owners}
|
||||
filterOption={() => true} // options are filtered at the api
|
||||
filterOption={null} // options are filtered at the api
|
||||
/>
|
||||
<p className="help-block">
|
||||
{t(
|
||||
|
||||
Reference in New Issue
Block a user