You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2020/12/11 18:52:53 UTC
[incubator-superset] branch master updated: chore: remove generic
type (#12003)
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
The following commit(s) were added to refs/heads/master by this push:
new 2769de3 chore: remove generic type (#12003)
2769de3 is described below
commit 2769de3731bc932fcc486a6b0730bd69ce58f93b
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Fri Dec 11 10:52:26 2020 -0800
chore: remove generic type (#12003)
* chore: remove generic type
* Make resourceName type stricter
* Fix type
* Fix type
* Fix lint
---
.../src/components/ImportModal/ImportModal.test.tsx | 9 +++++----
superset-frontend/src/components/ImportModal/index.tsx | 5 +++--
superset-frontend/src/views/CRUD/hooks.ts | 12 ++++++------
superset-frontend/src/views/CRUD/types.ts | 2 ++
4 files changed, 16 insertions(+), 12 deletions(-)
diff --git a/superset-frontend/src/components/ImportModal/ImportModal.test.tsx b/superset-frontend/src/components/ImportModal/ImportModal.test.tsx
index 1e922b4..718d4d6 100644
--- a/superset-frontend/src/components/ImportModal/ImportModal.test.tsx
+++ b/superset-frontend/src/components/ImportModal/ImportModal.test.tsx
@@ -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', () => {
diff --git a/superset-frontend/src/components/ImportModal/index.tsx b/superset-frontend/src/components/ImportModal/index.tsx
index 1c26623..5b2d1ac 100644
--- a/superset-frontend/src/components/ImportModal/index.tsx
+++ b/superset-frontend/src/components/ImportModal/index.tsx
@@ -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);
diff --git a/superset-frontend/src/views/CRUD/hooks.ts b/superset-frontend/src/views/CRUD/hooks.ts
index dedcadd..794b2c4 100644
--- a/superset-frontend/src/views/CRUD/hooks.ts
+++ b/superset-frontend/src/views/CRUD/hooks.ts
@@ -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 }));
}
diff --git a/superset-frontend/src/views/CRUD/types.ts b/superset-frontend/src/views/CRUD/types.ts
index c83e42c..4a9a2c5 100644
--- a/superset-frontend/src/views/CRUD/types.ts
+++ b/superset-frontend/src/views/CRUD/types.ts
@@ -111,3 +111,5 @@ export enum QueryObjectColumns {
tmp_table_name = 'tmp_table_name',
tracking_url = 'tracking_url',
}
+
+export type ImportResourceName = 'chart' | 'dashboard' | 'database' | 'dataset';