Skip to content

Commit 2431c02

Browse files
Aleksy Lisowskipiotrczarnas
Aleksy Lisowski
authored andcommitted
Merged PR 2783: fixed 'import metadata button'
- fixed 'import metadata button' - deleted consolelog - not displaying button on screen 'schemas?import_schema=true'
2 parents 9508143 + 7b2b830 commit 2431c02

File tree

1 file changed

+97
-42
lines changed

1 file changed

+97
-42
lines changed

dqops/src/main/frontend/src/components/Connection/ConnectionView/ConnectionActionGroup.tsx

+97-42
Original file line numberDiff line numberDiff line change
@@ -1,102 +1,157 @@
11
import React, { useState } from 'react';
22
import { useSelector } from 'react-redux';
33
import { useHistory } from 'react-router-dom';
4+
import { useActionDispatch } from '../../../hooks/useActionDispatch';
5+
import { setActiveFirstLevelUrl } from '../../../redux/actions/source.actions';
46
import { IRootState } from '../../../redux/reducers';
7+
import { getFirstLevelActiveTab } from '../../../redux/selectors';
58
import { ConnectionApiClient } from '../../../services/apiClient';
6-
import { CheckTypes, ROUTES } from "../../../shared/routes";
9+
import { CheckTypes, ROUTES } from '../../../shared/routes';
710
import { useDecodedParams } from '../../../utils';
811
import Button from '../../Button';
9-
import AddSchemaDialog from "../../CustomTree/AddSchemaDialog";
12+
import AddSchemaDialog from '../../CustomTree/AddSchemaDialog';
1013
import ConfirmDialog from './ConfirmDialog';
1114

1215
interface IConnectionActionGroupProps {
1316
isDisabled?: boolean;
1417
onUpdate?: () => void;
1518
isUpdating?: boolean;
1619
isUpdated?: boolean;
17-
onImport?: () => void;
1820
}
1921

2022
const ConnectionActionGroup = ({
2123
isUpdated,
2224
isUpdating,
2325
isDisabled,
24-
onUpdate,
25-
onImport
26+
onUpdate
2627
}: 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();
2833
const isSourceScreen = checkTypes === CheckTypes.SOURCES;
2934
const [isOpen, setIsOpen] = useState(false);
3035
const history = useHistory();
3136
const [addSchemaDialogOpen, setAddSchemaDialogOpen] = useState(false);
3237
const { userProfile } = useSelector((state: IRootState) => state.job || {});
33-
38+
const dispatch = useActionDispatch();
39+
const firstLevelActiveTab = useSelector(getFirstLevelActiveTab(checkTypes));
3440

3541
const removeConnection = async () => {
36-
await ConnectionApiClient.deleteConnection(
37-
connectionName ?? ''
38-
);
42+
await ConnectionApiClient.deleteConnection(connectionName ?? '');
3943
};
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+
);
4663
};
4764

4865
return (
4966
<div className="flex space-x-4 items-center absolute right-2 top-2">
50-
{isSourceScreen ? (
67+
{isSourceScreen && (
5168
<>
5269
<Button
5370
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+
}
5681
label="Add Schema"
5782
onClick={() => setAddSchemaDialogOpen(true)}
5883
disabled={userProfile.can_manage_data_sources !== true}
5984
/>
6085
<Button
6186
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+
}
6497
label="Delete Connection"
6598
onClick={() => setIsOpen(true)}
6699
disabled={userProfile.can_manage_data_sources !== true}
67100
/>
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+
))}
76137
</>
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
88138
)}
89139

90140
{onUpdate && (
91141
<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+
}
93149
variant="contained"
94150
label="Save"
95151
className="w-40 !h-10"
96152
onClick={onUpdate}
97153
loading={isUpdating}
98154
disabled={isDisabled || userProfile.can_manage_data_sources !== true}
99-
100155
/>
101156
)}
102157
<ConfirmDialog

0 commit comments

Comments
 (0)