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 { ReactWrapper } from 'enzyme';
|
||||
|
||||
import { ImportResourceName } from 'src/views/CRUD/types';
|
||||
import ImportModelsModal, { StyledIcon } from 'src/components/ImportModal';
|
||||
import Modal from 'src/common/components/Modal';
|
||||
|
||||
@ -29,8 +30,8 @@ const mockStore = configureStore([thunk]);
|
||||
const store = mockStore({});
|
||||
|
||||
const requiredProps = {
|
||||
resourceName: 'model',
|
||||
resourceLabel: 'model',
|
||||
resourceName: 'database' as ImportResourceName,
|
||||
resourceLabel: 'database',
|
||||
icon: <StyledIcon name="database" />,
|
||||
passwordsNeededMessage: 'Passwords are needed',
|
||||
addDangerToast: () => {},
|
||||
@ -61,8 +62,8 @@ describe('ImportModelsModal', () => {
|
||||
expect(wrapper.find(Modal)).toExist();
|
||||
});
|
||||
|
||||
it('renders "Import model" header', () => {
|
||||
expect(wrapper.find('h4').text()).toEqual('Import model');
|
||||
it('renders "Import database" header', () => {
|
||||
expect(wrapper.find('h4').text()).toEqual('Import database');
|
||||
});
|
||||
|
||||
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 Modal from 'src/common/components/Modal';
|
||||
import { useImportResource } from 'src/views/CRUD/hooks';
|
||||
import { ImportResourceName } from 'src/views/CRUD/types';
|
||||
|
||||
export const StyledIcon = styled(Icon)`
|
||||
margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0;
|
||||
@ -97,7 +98,7 @@ const StyledInputContainer = styled.div`
|
||||
`;
|
||||
|
||||
export interface ImportModelsModalProps {
|
||||
resourceName: string;
|
||||
resourceName: ImportResourceName;
|
||||
resourceLabel: string;
|
||||
icon: React.ReactNode;
|
||||
passwordsNeededMessage: string;
|
||||
@ -145,7 +146,7 @@ const ImportModelsModal: FunctionComponent<ImportModelsModalProps> = ({
|
||||
const {
|
||||
state: { passwordsNeeded },
|
||||
importResource,
|
||||
} = useImportResource<any>(resourceName, resourceLabel, handleErrorMsg);
|
||||
} = useImportResource(resourceName, resourceLabel, handleErrorMsg);
|
||||
|
||||
useEffect(() => {
|
||||
setPasswordFields(passwordsNeeded);
|
||||
|
@ -26,7 +26,7 @@ import { FilterValue } from 'src/components/ListView/types';
|
||||
import Chart, { Slice } from 'src/types/Chart';
|
||||
import copyTextToClipboard from 'src/utils/copy';
|
||||
import { getClientErrorObject } from 'src/utils/getClientErrorObject';
|
||||
import { FavoriteStatus } from './types';
|
||||
import { FavoriteStatus, ImportResourceName } from './types';
|
||||
|
||||
interface ListViewResourceState<D extends object = any> {
|
||||
loading: boolean;
|
||||
@ -313,22 +313,22 @@ export function useSingleViewResource<D extends object = any>(
|
||||
};
|
||||
}
|
||||
|
||||
interface ImportResourceState<D extends object = any> {
|
||||
interface ImportResourceState {
|
||||
loading: boolean;
|
||||
passwordsNeeded: string[];
|
||||
}
|
||||
|
||||
export function useImportResource<D extends object = any>(
|
||||
resourceName: string,
|
||||
export function useImportResource(
|
||||
resourceName: ImportResourceName,
|
||||
resourceLabel: string, // resourceLabel for translations
|
||||
handleErrorMsg: (errorMsg: string) => void,
|
||||
) {
|
||||
const [state, setState] = useState<ImportResourceState<D>>({
|
||||
const [state, setState] = useState<ImportResourceState>({
|
||||
loading: false,
|
||||
passwordsNeeded: [],
|
||||
});
|
||||
|
||||
function updateState(update: Partial<ImportResourceState<D>>) {
|
||||
function updateState(update: Partial<ImportResourceState>) {
|
||||
setState(currentState => ({ ...currentState, ...update }));
|
||||
}
|
||||
|
||||
|
@ -111,3 +111,5 @@ export enum QueryObjectColumns {
|
||||
tmp_table_name = 'tmp_table_name',
|
||||
tracking_url = 'tracking_url',
|
||||
}
|
||||
|
||||
export type ImportResourceName = 'chart' | 'dashboard' | 'database' | 'dataset';
|
||||
|
Loading…
Reference in New Issue
Block a user