|
1 | 1 | import React, { useState } from 'react';
|
2 | 2 | import { useSelector } from 'react-redux';
|
3 | 3 | import { useHistory } from 'react-router-dom';
|
| 4 | +import { useActionDispatch } from '../../../hooks/useActionDispatch'; |
| 5 | +import { setActiveFirstLevelUrl } from '../../../redux/actions/source.actions'; |
4 | 6 | import { IRootState } from '../../../redux/reducers';
|
| 7 | +import { getFirstLevelActiveTab } from '../../../redux/selectors'; |
5 | 8 | import { ConnectionApiClient } from '../../../services/apiClient';
|
6 |
| -import { CheckTypes, ROUTES } from "../../../shared/routes"; |
| 9 | +import { CheckTypes, ROUTES } from '../../../shared/routes'; |
7 | 10 | import { useDecodedParams } from '../../../utils';
|
8 | 11 | import Button from '../../Button';
|
9 |
| -import AddSchemaDialog from "../../CustomTree/AddSchemaDialog"; |
| 12 | +import AddSchemaDialog from '../../CustomTree/AddSchemaDialog'; |
10 | 13 | import ConfirmDialog from './ConfirmDialog';
|
11 | 14 |
|
12 | 15 | interface IConnectionActionGroupProps {
|
13 | 16 | isDisabled?: boolean;
|
14 | 17 | onUpdate?: () => void;
|
15 | 18 | isUpdating?: boolean;
|
16 | 19 | isUpdated?: boolean;
|
17 |
| - onImport?: () => void; |
18 | 20 | }
|
19 | 21 |
|
20 | 22 | const ConnectionActionGroup = ({
|
21 | 23 | isUpdated,
|
22 | 24 | isUpdating,
|
23 | 25 | isDisabled,
|
24 |
| - onUpdate, |
25 |
| - onImport |
| 26 | + onUpdate |
26 | 27 | }: IConnectionActionGroupProps) => {
|
27 |
| - const { connection: connectionName, checkTypes, tab }: { connection: any; checkTypes: any; tab: any } = useDecodedParams(); |
| 28 | + const { |
| 29 | + connection: connectionName, |
| 30 | + checkTypes, |
| 31 | + tab |
| 32 | + }: { connection: any; checkTypes: any; tab: any } = useDecodedParams(); |
28 | 33 | const isSourceScreen = checkTypes === CheckTypes.SOURCES;
|
29 | 34 | const [isOpen, setIsOpen] = useState(false);
|
30 | 35 | const history = useHistory();
|
31 | 36 | const [addSchemaDialogOpen, setAddSchemaDialogOpen] = useState(false);
|
32 | 37 | const { userProfile } = useSelector((state: IRootState) => state.job || {});
|
33 |
| - |
| 38 | + const dispatch = useActionDispatch(); |
| 39 | + const firstLevelActiveTab = useSelector(getFirstLevelActiveTab(checkTypes)); |
34 | 40 |
|
35 | 41 | const removeConnection = async () => {
|
36 |
| - await ConnectionApiClient.deleteConnection( |
37 |
| - connectionName ?? '' |
38 |
| - ); |
| 42 | + await ConnectionApiClient.deleteConnection(connectionName ?? ''); |
39 | 43 | };
|
40 |
| - const goToSchemas = (isImport = true) => { |
41 |
| - history.push(`${ROUTES.CONNECTION_DETAIL(checkTypes, connectionName, 'schemas')}${isImport ? '?import_schema=true' : ''}`) |
42 |
| - |
43 |
| - if (onImport) { |
44 |
| - onImport(); |
45 |
| - } |
| 44 | + const importMetaData = () => { |
| 45 | + dispatch( |
| 46 | + setActiveFirstLevelUrl( |
| 47 | + checkTypes, |
| 48 | + firstLevelActiveTab, |
| 49 | + ROUTES.CONNECTION_DETAIL( |
| 50 | + checkTypes, |
| 51 | + connectionName || '', |
| 52 | + 'schemas?import_schema=true' |
| 53 | + ) |
| 54 | + ) |
| 55 | + ); |
| 56 | + history.push( |
| 57 | + `${ROUTES.CONNECTION_DETAIL( |
| 58 | + checkTypes, |
| 59 | + connectionName || '', |
| 60 | + 'schemas?import_schema=true' |
| 61 | + )}` |
| 62 | + ); |
46 | 63 | };
|
47 | 64 |
|
48 | 65 | return (
|
49 | 66 | <div className="flex space-x-4 items-center absolute right-2 top-2">
|
50 |
| - {isSourceScreen ? ( |
| 67 | + {isSourceScreen && ( |
51 | 68 | <>
|
52 | 69 | <Button
|
53 | 70 | className="!h-10"
|
54 |
| - variant={!(userProfile.can_manage_data_sources !== true) ? "outlined" : "contained"} |
55 |
| - color={!(userProfile.can_manage_data_sources !== true) ? 'primary' : 'secondary'} |
| 71 | + variant={ |
| 72 | + !(userProfile.can_manage_data_sources !== true) |
| 73 | + ? 'outlined' |
| 74 | + : 'contained' |
| 75 | + } |
| 76 | + color={ |
| 77 | + !(userProfile.can_manage_data_sources !== true) |
| 78 | + ? 'primary' |
| 79 | + : 'secondary' |
| 80 | + } |
56 | 81 | label="Add Schema"
|
57 | 82 | onClick={() => setAddSchemaDialogOpen(true)}
|
58 | 83 | disabled={userProfile.can_manage_data_sources !== true}
|
59 | 84 | />
|
60 | 85 | <Button
|
61 | 86 | className="!h-10"
|
62 |
| - variant={!(userProfile.can_manage_data_sources !== true) ? "outlined" : "contained"} |
63 |
| - color={!(userProfile.can_manage_data_sources !== true) ? 'primary' : 'secondary'} |
| 87 | + variant={ |
| 88 | + !(userProfile.can_manage_data_sources !== true) |
| 89 | + ? 'outlined' |
| 90 | + : 'contained' |
| 91 | + } |
| 92 | + color={ |
| 93 | + !(userProfile.can_manage_data_sources !== true) |
| 94 | + ? 'primary' |
| 95 | + : 'secondary' |
| 96 | + } |
64 | 97 | label="Delete Connection"
|
65 | 98 | onClick={() => setIsOpen(true)}
|
66 | 99 | disabled={userProfile.can_manage_data_sources !== true}
|
67 | 100 | />
|
68 |
| - <Button |
69 |
| - className="!h-10" |
70 |
| - label="Import metadata" |
71 |
| - color={!(userProfile.can_manage_data_sources !== true) ? 'primary' : 'secondary'} |
72 |
| - variant={!(userProfile.can_manage_data_sources !== true) ? "outlined" : "contained"} |
73 |
| - onClick={() => goToSchemas()} |
74 |
| - disabled={userProfile.can_manage_data_sources !== true} |
75 |
| - /> |
| 101 | + {!location.href.includes('schemas?import_schema=true') && |
| 102 | + (tab === 'schemas' ? ( |
| 103 | + <Button |
| 104 | + className="!h-10" |
| 105 | + label="Manage metadata" |
| 106 | + color={ |
| 107 | + !(userProfile.can_manage_data_sources !== true) |
| 108 | + ? 'primary' |
| 109 | + : 'secondary' |
| 110 | + } |
| 111 | + variant={ |
| 112 | + !(userProfile.can_manage_data_sources !== true) |
| 113 | + ? 'outlined' |
| 114 | + : 'contained' |
| 115 | + } |
| 116 | + onClick={importMetaData} |
| 117 | + disabled={userProfile.can_manage_data_sources !== true} |
| 118 | + /> |
| 119 | + ) : ( |
| 120 | + <Button |
| 121 | + className="!h-10" |
| 122 | + label="Import metadata" |
| 123 | + color={ |
| 124 | + !(userProfile.can_manage_data_sources !== true) |
| 125 | + ? 'primary' |
| 126 | + : 'secondary' |
| 127 | + } |
| 128 | + variant={ |
| 129 | + !(userProfile.can_manage_data_sources !== true) |
| 130 | + ? 'outlined' |
| 131 | + : 'contained' |
| 132 | + } |
| 133 | + onClick={() => importMetaData()} |
| 134 | + disabled={userProfile.can_manage_data_sources !== true} |
| 135 | + /> |
| 136 | + ))} |
76 | 137 | </>
|
77 |
| - ) : ( |
78 |
| - tab === 'schemas' ? ( |
79 |
| - <Button |
80 |
| - className="!h-10" |
81 |
| - label="Manage metadata" |
82 |
| - color={!(userProfile.can_manage_data_sources !== true) ? 'primary' : 'secondary'} |
83 |
| - variant={!(userProfile.can_manage_data_sources !== true) ? "outlined" : "contained"} |
84 |
| - onClick={() => goToSchemas()} |
85 |
| - disabled={userProfile.can_manage_data_sources !== true} |
86 |
| - /> |
87 |
| - ) : null |
88 | 138 | )}
|
89 | 139 |
|
90 | 140 | {onUpdate && (
|
91 | 141 | <Button
|
92 |
| - color={isUpdated && !isDisabled && !(userProfile.can_manage_data_sources !== true) ? 'primary' : 'secondary'} |
| 142 | + color={ |
| 143 | + isUpdated && |
| 144 | + !isDisabled && |
| 145 | + !(userProfile.can_manage_data_sources !== true) |
| 146 | + ? 'primary' |
| 147 | + : 'secondary' |
| 148 | + } |
93 | 149 | variant="contained"
|
94 | 150 | label="Save"
|
95 | 151 | className="w-40 !h-10"
|
96 | 152 | onClick={onUpdate}
|
97 | 153 | loading={isUpdating}
|
98 | 154 | disabled={isDisabled || userProfile.can_manage_data_sources !== true}
|
99 |
| - |
100 | 155 | />
|
101 | 156 | )}
|
102 | 157 | <ConfirmDialog
|
|
0 commit comments