Browse Source

change dialog hook name

tumao 4 years ago
parent
commit
3a008c620a

+ 26 - 3
client/src/hooks/ReleaseAndLoad.tsx → client/src/hooks/Dialog.tsx

@@ -1,4 +1,4 @@
-import { useContext } from 'react';
+import { ReactElement, useContext } from 'react';
 import { useTranslation } from 'react-i18next';
 import { Typography } from '@material-ui/core';
 import { rootContext } from '../context/Root';
@@ -8,11 +8,13 @@ import { StatusEnum } from '../components/status/Types';
 import { CollectionData } from '../pages/overview/collectionCard/Types';
 
 // handle release and load dialog
-export interface LoadAndReleaseHookProps {
+export interface LoadAndReleaseDialogHookProps {
   type: 'partition' | 'collection';
 }
 
-export const useLoadAndReleaseHook = (props: LoadAndReleaseHookProps) => {
+export const useLoadAndReleaseDialogHook = (
+  props: LoadAndReleaseDialogHookProps
+) => {
   const { type } = props;
   const { setDialog } = useContext(rootContext);
   const { t: dialogTrans } = useTranslation('dialog');
@@ -70,3 +72,24 @@ export const useLoadAndReleaseHook = (props: LoadAndReleaseHookProps) => {
     handleAction,
   };
 };
+
+export const useInsertDialogHook = () => {
+  const { setDialog } = useContext(rootContext);
+
+  const handleInsertDialog = (
+    // stepper container, contains all contents
+    component: ReactElement
+  ) => {
+    setDialog({
+      open: true,
+      type: 'custom',
+      params: {
+        component,
+      },
+    });
+  };
+
+  return {
+    handleInsertDialog,
+  };
+};

+ 0 - 23
client/src/hooks/Insert.tsx

@@ -1,23 +0,0 @@
-import { ReactElement, useContext } from 'react';
-import { rootContext } from '../context/Root';
-
-export const useInsertHook = () => {
-  const { setDialog } = useContext(rootContext);
-
-  const handleInsertDialog = (
-    // stepper container, contains all contents
-    component: ReactElement
-  ) => {
-    setDialog({
-      open: true,
-      type: 'custom',
-      params: {
-        component,
-      },
-    });
-  };
-
-  return {
-    handleInsertDialog,
-  };
-};

+ 18 - 10
client/src/pages/collections/Collections.tsx

@@ -19,10 +19,13 @@ import { rootContext } from '../../context/Root';
 import CreateCollection from './Create';
 import DeleteTemplate from '../../components/customDialog/DeleteDialogTemplate';
 import { CollectionHttp } from '../../http/Collection';
-import { useLoadAndReleaseHook } from '../../hooks/ReleaseAndLoad';
+import {
+  useInsertDialogHook,
+  useLoadAndReleaseDialogHook,
+} from '../../hooks/Dialog';
 import Highlighter from 'react-highlight-words';
 import { parseLocationSearch } from '../../utils/Format';
-// import InsertContainer from '../../components/insert/Container';
+import InsertContainer from '../../components/insert/Container';
 
 const useStyles = makeStyles((theme: Theme) => ({
   emptyWrapper: {
@@ -53,7 +56,8 @@ const { search = '' } = parseLocationSearch(window.location.search);
 
 const Collections = () => {
   useNavigationHook(ALL_ROUTER_TYPES.COLLECTIONS);
-  const { handleAction } = useLoadAndReleaseHook({ type: 'collection' });
+  const { handleAction } = useLoadAndReleaseDialogHook({ type: 'collection' });
+  const { handleInsertDialog } = useInsertDialogHook();
   const [collections, setCollections] = useState<CollectionView[]>([]);
   const [searchedCollections, setSearchedCollections] = useState<
     CollectionView[]
@@ -228,13 +232,17 @@ const Collections = () => {
     // {
     //   label: btnTrans('insert'),
     //   onClick: () => {
-    //     setDialog({
-    //       open: true,
-    //       type: 'custom',
-    //       params: {
-    //         component: <InsertContainer />,
-    //       },
-    //     });
+    //     const component = (
+    //       <InsertContainer
+    //         collections={[]}
+    //         selectedCollection={''}
+    //         partitions={[]}
+    //         selectedPartition={''}
+    //         schema={[]}
+    //         handleInsert={() => {}}
+    //       />
+    //     );
+    //     handleInsertDialog(component);
     //   },
     //   /**
     //    * insert validation:

+ 2 - 2
client/src/pages/overview/Overview.tsx

@@ -5,7 +5,7 @@ import EmptyCard from '../../components/cards/EmptyCard';
 import icons from '../../components/icons/Icons';
 import { StatusEnum } from '../../components/status/Types';
 import { rootContext } from '../../context/Root';
-import { useLoadAndReleaseHook } from '../../hooks/ReleaseAndLoad';
+import { useLoadAndReleaseDialogHook } from '../../hooks/Dialog';
 import { useNavigationHook } from '../../hooks/Navigation';
 import { CollectionHttp } from '../../http/Collection';
 import { ALL_ROUTER_TYPES } from '../../router/Types';
@@ -31,7 +31,7 @@ const useStyles = makeStyles((theme: Theme) => ({
 
 const Overview = () => {
   useNavigationHook(ALL_ROUTER_TYPES.OVERVIEW);
-  const { handleAction } = useLoadAndReleaseHook({ type: 'collection' });
+  const { handleAction } = useLoadAndReleaseDialogHook({ type: 'collection' });
   const classes = useStyles();
   const { t: overviewTrans } = useTranslation('overview');
   const { t: collectionTrans } = useTranslation('collection');