mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
refactor: typing for explore Control and messageToasts (#11416)
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import React, { useState, useEffect, useRef, useCallback } from 'react';
|
||||
import {
|
||||
Modal,
|
||||
Row,
|
||||
@@ -31,18 +31,10 @@ import { OptionsType } from 'react-select/src/types';
|
||||
import { AsyncSelect } from 'src/components/Select';
|
||||
import rison from 'rison';
|
||||
import { t, SupersetClient } from '@superset-ui/core';
|
||||
import Chart from 'src/types/Chart';
|
||||
import Chart, { Slice } from 'src/types/Chart';
|
||||
import FormLabel from 'src/components/FormLabel';
|
||||
import getClientErrorObject from '../../utils/getClientErrorObject';
|
||||
|
||||
export type Slice = {
|
||||
id?: number;
|
||||
slice_id: number;
|
||||
slice_name: string;
|
||||
description: string | null;
|
||||
cache_timeout: number | null;
|
||||
};
|
||||
|
||||
type InternalProps = {
|
||||
slice: Slice;
|
||||
onHide: () => void;
|
||||
@@ -81,28 +73,31 @@ function PropertiesModal({ slice, onHide, onSave }: InternalProps) {
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchChartData() {
|
||||
try {
|
||||
const response = await SupersetClient.get({
|
||||
endpoint: `/api/v1/chart/${slice.slice_id}`,
|
||||
});
|
||||
const chart = response.json.result;
|
||||
setOwners(
|
||||
chart.owners.map((owner: any) => ({
|
||||
value: owner.id,
|
||||
label: `${owner.first_name} ${owner.last_name}`,
|
||||
})),
|
||||
);
|
||||
} catch (response) {
|
||||
const clientError = await getClientErrorObject(response);
|
||||
showError(clientError);
|
||||
}
|
||||
}
|
||||
const fetchChartData = useCallback(
|
||||
async function fetchChartData() {
|
||||
try {
|
||||
const response = await SupersetClient.get({
|
||||
endpoint: `/api/v1/chart/${slice.slice_id}`,
|
||||
});
|
||||
const chart = response.json.result;
|
||||
setOwners(
|
||||
chart.owners.map((owner: any) => ({
|
||||
value: owner.id,
|
||||
label: `${owner.first_name} ${owner.last_name}`,
|
||||
})),
|
||||
);
|
||||
} catch (response) {
|
||||
const clientError = await getClientErrorObject(response);
|
||||
showError(clientError);
|
||||
}
|
||||
},
|
||||
[slice.slice_id],
|
||||
);
|
||||
|
||||
// get the owners of this slice
|
||||
useEffect(() => {
|
||||
fetchChartData();
|
||||
}, []);
|
||||
}, [fetchChartData]);
|
||||
|
||||
const loadOptions = (input = '') => {
|
||||
const query = rison.encode({
|
||||
|
||||
Reference in New Issue
Block a user