mirror of
https://github.com/apache/superset.git
synced 2024-09-06 22:07:34 -04:00
chore: remove generic type (#12003)
* chore: remove generic type * Make resourceName type stricter * Fix type * Fix type * Fix lint
This commit is contained in:
parent
916f7e923a
commit
2769de3731
@ -22,6 +22,7 @@ import configureStore from 'redux-mock-store';
|
|||||||
import { styledMount as mount } from 'spec/helpers/theming';
|
import { styledMount as mount } from 'spec/helpers/theming';
|
||||||
import { ReactWrapper } from 'enzyme';
|
import { ReactWrapper } from 'enzyme';
|
||||||
|
|
||||||
|
import { ImportResourceName } from 'src/views/CRUD/types';
|
||||||
import ImportModelsModal, { StyledIcon } from 'src/components/ImportModal';
|
import ImportModelsModal, { StyledIcon } from 'src/components/ImportModal';
|
||||||
import Modal from 'src/common/components/Modal';
|
import Modal from 'src/common/components/Modal';
|
||||||
|
|
||||||
@ -29,8 +30,8 @@ const mockStore = configureStore([thunk]);
|
|||||||
const store = mockStore({});
|
const store = mockStore({});
|
||||||
|
|
||||||
const requiredProps = {
|
const requiredProps = {
|
||||||
resourceName: 'model',
|
resourceName: 'database' as ImportResourceName,
|
||||||
resourceLabel: 'model',
|
resourceLabel: 'database',
|
||||||
icon: <StyledIcon name="database" />,
|
icon: <StyledIcon name="database" />,
|
||||||
passwordsNeededMessage: 'Passwords are needed',
|
passwordsNeededMessage: 'Passwords are needed',
|
||||||
addDangerToast: () => {},
|
addDangerToast: () => {},
|
||||||
@ -61,8 +62,8 @@ describe('ImportModelsModal', () => {
|
|||||||
expect(wrapper.find(Modal)).toExist();
|
expect(wrapper.find(Modal)).toExist();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders "Import model" header', () => {
|
it('renders "Import database" header', () => {
|
||||||
expect(wrapper.find('h4').text()).toEqual('Import model');
|
expect(wrapper.find('h4').text()).toEqual('Import database');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders a label and a file input field', () => {
|
it('renders a label and a file input field', () => {
|
||||||
|
@ -22,6 +22,7 @@ import { styled, t } from '@superset-ui/core';
|
|||||||
import Icon from 'src//components/Icon';
|
import Icon from 'src//components/Icon';
|
||||||
import Modal from 'src/common/components/Modal';
|
import Modal from 'src/common/components/Modal';
|
||||||
import { useImportResource } from 'src/views/CRUD/hooks';
|
import { useImportResource } from 'src/views/CRUD/hooks';
|
||||||
|
import { ImportResourceName } from 'src/views/CRUD/types';
|
||||||
|
|
||||||
export const StyledIcon = styled(Icon)`
|
export const StyledIcon = styled(Icon)`
|
||||||
margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0;
|
margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0;
|
||||||
@ -97,7 +98,7 @@ const StyledInputContainer = styled.div`
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
export interface ImportModelsModalProps {
|
export interface ImportModelsModalProps {
|
||||||
resourceName: string;
|
resourceName: ImportResourceName;
|
||||||
resourceLabel: string;
|
resourceLabel: string;
|
||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
passwordsNeededMessage: string;
|
passwordsNeededMessage: string;
|
||||||
@ -145,7 +146,7 @@ const ImportModelsModal: FunctionComponent<ImportModelsModalProps> = ({
|
|||||||
const {
|
const {
|
||||||
state: { passwordsNeeded },
|
state: { passwordsNeeded },
|
||||||
importResource,
|
importResource,
|
||||||
} = useImportResource<any>(resourceName, resourceLabel, handleErrorMsg);
|
} = useImportResource(resourceName, resourceLabel, handleErrorMsg);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPasswordFields(passwordsNeeded);
|
setPasswordFields(passwordsNeeded);
|
||||||
|
@ -26,7 +26,7 @@ import { FilterValue } from 'src/components/ListView/types';
|
|||||||
import Chart, { Slice } from 'src/types/Chart';
|
import Chart, { Slice } from 'src/types/Chart';
|
||||||
import copyTextToClipboard from 'src/utils/copy';
|
import copyTextToClipboard from 'src/utils/copy';
|
||||||
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
|
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
|
||||||
import { FavoriteStatus } from './types';
|
import { FavoriteStatus, ImportResourceName } from './types';
|
||||||
|
|
||||||
interface ListViewResourceState<D extends object = any> {
|
interface ListViewResourceState<D extends object = any> {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
@ -313,22 +313,22 @@ export function useSingleViewResource<D extends object = any>(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportResourceState<D extends object = any> {
|
interface ImportResourceState {
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
passwordsNeeded: string[];
|
passwordsNeeded: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useImportResource<D extends object = any>(
|
export function useImportResource(
|
||||||
resourceName: string,
|
resourceName: ImportResourceName,
|
||||||
resourceLabel: string, // resourceLabel for translations
|
resourceLabel: string, // resourceLabel for translations
|
||||||
handleErrorMsg: (errorMsg: string) => void,
|
handleErrorMsg: (errorMsg: string) => void,
|
||||||
) {
|
) {
|
||||||
const [state, setState] = useState<ImportResourceState<D>>({
|
const [state, setState] = useState<ImportResourceState>({
|
||||||
loading: false,
|
loading: false,
|
||||||
passwordsNeeded: [],
|
passwordsNeeded: [],
|
||||||
});
|
});
|
||||||
|
|
||||||
function updateState(update: Partial<ImportResourceState<D>>) {
|
function updateState(update: Partial<ImportResourceState>) {
|
||||||
setState(currentState => ({ ...currentState, ...update }));
|
setState(currentState => ({ ...currentState, ...update }));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,3 +111,5 @@ export enum QueryObjectColumns {
|
|||||||
tmp_table_name = 'tmp_table_name',
|
tmp_table_name = 'tmp_table_name',
|
||||||
tracking_url = 'tracking_url',
|
tracking_url = 'tracking_url',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ImportResourceName = 'chart' | 'dashboard' | 'database' | 'dataset';
|
||||||
|
Loading…
Reference in New Issue
Block a user