feat: create hooks to redux component (#13487)

* created TypedSelector

* made changes

* made discussed changes
This commit is contained in:
AAfghahi
2021-03-12 14:03:56 -05:00
committed by GitHub
parent de0c6c9c56
commit a0e3754173
3 changed files with 54 additions and 13 deletions

View File

@@ -17,7 +17,6 @@
* under the License.
*/
import React, { FunctionComponent, useState, useEffect } from 'react';
import { useSelector } from 'react-redux';
import { styled, t, SupersetClient } from '@superset-ui/core';
import InfoTooltip from 'src/common/components/InfoTooltip';
import { useSingleViewResource } from 'src/views/CRUD/hooks';
@@ -30,6 +29,7 @@ import Button from 'src/components/Button';
import IndeterminateCheckbox from 'src/components/IndeterminateCheckbox';
import { JsonEditor } from 'src/components/AsyncAceEditor';
import { DatabaseObject } from './types';
import { useCommonConf } from './state';
interface DatabaseModalProps {
addDangerToast: (msg: string) => void;
@@ -40,17 +40,6 @@ interface DatabaseModalProps {
database?: DatabaseObject | null; // If included, will go into edit mode
}
// todo: define common type fully in types file
interface RootState {
common: {
conf: {
SQLALCHEMY_DOCS_URL: string;
SQLALCHEMY_DISPLAY_TEXT: string;
};
};
messageToast: Array<Object>;
}
const DEFAULT_TAB_KEY = '1';
const StyledIcon = styled(Icon)`
margin: auto ${({ theme }) => theme.gridUnit * 2}px auto 0;
@@ -143,7 +132,7 @@ const DatabaseModal: FunctionComponent<DatabaseModalProps> = ({
const [db, setDB] = useState<DatabaseObject | null>(null);
const [isHidden, setIsHidden] = useState<boolean>(true);
const [tabKey, setTabKey] = useState<string>(DEFAULT_TAB_KEY);
const conf = useSelector((state: RootState) => state.common.conf);
const conf = useCommonConf();
const isEditMode = database !== null;
const defaultExtra =