Skip to content

Commit db1e1d4

Browse files
committed
2 parents d2372f6 + 30a616b commit db1e1d4

File tree

3 files changed

+104
-35
lines changed

3 files changed

+104
-35
lines changed

dqops/src/main/frontend/src/components/IncidentsLayout/IncidentsTree.tsx

+59-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import { useActionDispatch } from '../../hooks/useActionDispatch';
88
import {
99
addFirstLevelTab,
1010
addSelectedConnection,
11-
getConnections
11+
getConnections,
12+
setActiveFirstLevelTab
1213
} from '../../redux/actions/incidents.actions';
1314
import { IRootState } from '../../redux/reducers';
1415
import { ROUTES } from '../../shared/routes';
@@ -17,7 +18,7 @@ import SvgIcon from '../SvgIcon';
1718

1819
const IncidentsTree = () => {
1920
const dispatch = useActionDispatch();
20-
const { connections, activeTab, selectedConnections } = useSelector(
21+
const { connections, activeTab, selectedConnections, tabs } = useSelector(
2122
(state: IRootState) => state.incidents
2223
);
2324
const selectedConnection =
@@ -58,6 +59,62 @@ const IncidentsTree = () => {
5859
history.push(url);
5960
};
6061

62+
const openCorrectTabFromUrl = () => {
63+
if (
64+
window.location.pathname === '/incidents' ||
65+
window.location.pathname === '/incidents/'
66+
) {
67+
return;
68+
}
69+
70+
const path = window.location.pathname.split('/');
71+
const connection = path[2];
72+
const selectedConnection = connections.find(
73+
(x) => x.connection === connection
74+
);
75+
76+
if (selectedConnection && !path[3]) {
77+
openFirstLevelTab(selectedConnection);
78+
} else if (path[3]) {
79+
const connection = path[2] || '';
80+
const year = Number(path[3]);
81+
const month = Number(path[4]);
82+
const incidentId = path[5] || '';
83+
84+
dispatch(
85+
addFirstLevelTab({
86+
url: ROUTES.INCIDENT_DETAIL(connection, year, month, incidentId),
87+
value: ROUTES.INCIDENT_DETAIL_VALUE(
88+
connection,
89+
year,
90+
month,
91+
incidentId
92+
),
93+
state: {},
94+
label: incidentId
95+
})
96+
);
97+
98+
dispatch(
99+
setActiveFirstLevelTab(
100+
ROUTES.INCIDENT_DETAIL(connection, year, month, incidentId)
101+
)
102+
);
103+
history.push(ROUTES.INCIDENT_DETAIL(connection, year, month, incidentId));
104+
}
105+
};
106+
107+
useEffect(() => {
108+
openCorrectTabFromUrl();
109+
}, [window.location.pathname, connections]);
110+
111+
// useEffect(() => {
112+
// if (activeTab) {
113+
// dispatch(setActiveFirstLevelTab(activeTab));
114+
// history.push(activeTab);
115+
// }
116+
// }, [activeTab]);
117+
61118
const openConnection = (connection: IncidentsPerConnectionModel) => {
62119
dispatch(
63120
addSelectedConnection({

dqops/src/main/frontend/src/components/IncidentsLayout/index.tsx

+34-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { ReactNode, useEffect, useMemo } from 'react';
1+
import React, { ReactNode, useMemo } from 'react';
22

33
import { useDispatch, useSelector } from 'react-redux';
44
import { useHistory } from 'react-router-dom';
@@ -12,7 +12,6 @@ import {
1212
} from '../../redux/actions/incidents.actions';
1313
import { IRootState } from '../../redux/reducers';
1414
import { ROUTES } from '../../shared/routes';
15-
import { urlencodeDecoder } from '../../utils';
1615
import ConfirmDialog from '../CustomTree/ConfirmDialog';
1716
import Header from '../Header';
1817
import PageTabs from '../PageTabs';
@@ -24,26 +23,34 @@ interface LayoutProps {
2423
}
2524

2625
const IncidentsLayout = ({ route }: LayoutProps) => {
27-
const { objectNotFound, setObjectNotFound } = useTree()
28-
26+
const { objectNotFound, setObjectNotFound } = useTree();
27+
2928
const { tabs: pageTabs, activeTab } = useSelector(
3029
(state: IRootState) => state.incidents
3130
);
32-
31+
3332
const dispatch = useDispatch();
3433
const history = useHistory();
3534

36-
3735
const handleChange = (tab: TabOption) => {
36+
if (tab.url === window.location.pathname) {
37+
return;
38+
}
3839
dispatch(setActiveFirstLevelTab(tab.value));
39-
history.push(urlencodeDecoder(tab?.url ?? ''));
40+
history.push(tab.value);
4041
};
4142

4243
const closeTab = (value: string) => {
44+
const tabIndex = pageTabs.findIndex((item) => item.url === value);
45+
dispatch(closeFirstLevelTab(value));
4346
if (pageTabs.length === 1) {
44-
history.push(`/incidents`)
47+
history.push(`/incidents`);
48+
return;
4549
}
46-
dispatch(closeFirstLevelTab(value));
50+
history.push(pageTabs[tabIndex - 1]?.url || pageTabs[0]?.url);
51+
dispatch(
52+
setActiveFirstLevelTab(pageTabs[tabIndex - 1]?.url || pageTabs[0]?.url)
53+
);
4754
};
4855

4956
const tabOptions = useMemo(() => {
@@ -56,21 +63,14 @@ const IncidentsLayout = ({ route }: LayoutProps) => {
5663
);
5764
}, [pageTabs]);
5865

59-
useEffect(() => {
60-
if (activeTab) {
61-
dispatch(setActiveFirstLevelTab(activeTab));
62-
history.push(activeTab);
63-
}
64-
}, [activeTab]);
65-
6666
const getComponent = () => {
6767
switch (route) {
6868
case ROUTES.PATTERNS.INCIDENT_DETAIL:
69-
return <IncidentDetail/>;
69+
return <IncidentDetail />;
7070
case ROUTES.PATTERNS.INCIDENTS:
71-
return <Incidents/>;
71+
return <Incidents />;
7272
case ROUTES.PATTERNS.INCIDENT_CONNECTION:
73-
return <IncidentConnection/>;
73+
return <IncidentConnection />;
7474
default:
7575
return null;
7676
}
@@ -105,17 +105,26 @@ const IncidentsLayout = ({ route }: LayoutProps) => {
105105
limit={7}
106106
/>
107107
<div className="bg-white border border-gray-300 flex-auto min-h-0 overflow-auto">
108-
{!!activeTab && activeTab !== '/incidents/new-tab' && <>{renderComponent}</>}
108+
{!!activeTab && activeTab !== '/incidents/new-tab' && (
109+
<>{renderComponent}</>
110+
)}
109111
</div>
110112
</div>
111113
</div>
112114
</div>
113115
<ConfirmDialog
114-
open={objectNotFound}
115-
onConfirm={() => new Promise(() => {dispatch(closeFirstLevelTab(activeTab)), setObjectNotFound(false)})}
116-
isCancelExcluded={true}
117-
onClose={() => {dispatch(closeFirstLevelTab(activeTab)), setObjectNotFound(false)}}
118-
message='The definition of this object was deleted in the DQOps user home. The tab will be closed.'/>
116+
open={objectNotFound}
117+
onConfirm={() =>
118+
new Promise(() => {
119+
dispatch(closeFirstLevelTab(activeTab)), setObjectNotFound(false);
120+
})
121+
}
122+
isCancelExcluded={true}
123+
onClose={() => {
124+
dispatch(closeFirstLevelTab(activeTab)), setObjectNotFound(false);
125+
}}
126+
message="The definition of this object was deleted in the DQOps user home. The tab will be closed."
127+
/>
119128
</div>
120129
);
121130
};

dqops/src/main/frontend/src/pages/IncidentConnection/index.tsx

+11-8
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,14 @@ export const IncidentConnection = () => {
154154
label: row.incidentId
155155
})
156156
);
157+
history.push(
158+
ROUTES.INCIDENT_DETAIL_VALUE(
159+
row.connection || '',
160+
row.year || 0,
161+
row.month || 0,
162+
row.incidentId || ''
163+
)
164+
);
157165
};
158166

159167
const handleSortChange = (
@@ -225,16 +233,11 @@ export const IncidentConnection = () => {
225233
/>
226234
),
227235
label: 'Table',
228-
className: 'text-left text-sm py-2 px-4 max-w-40 min-w-35 whitespace-normal break-all',
236+
className:
237+
'text-left text-sm py-2 px-4 max-w-40 min-w-35 whitespace-normal break-all',
229238
value: 'table',
230239
render: (value: string) => {
231-
return (
232-
<div
233-
className="cursor-pointer text-sm text-start"
234-
>
235-
{value}
236-
</div>
237-
);
240+
return <div className="cursor-pointer text-sm text-start">{value}</div>;
238241
}
239242
},
240243
{

0 commit comments

Comments
 (0)