Skip to content

Commit 7a6a813

Browse files
committed
Update links for drawer view
1 parent c5a4336 commit 7a6a813

File tree

12 files changed

+141
-35
lines changed

12 files changed

+141
-35
lines changed

plugins/kiali/src/components/DetailDescription/DetailDescription.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { kialiStyle } from '../../styles/StyleUtils';
1111
import { AppWorkload } from '../../types/App';
1212
import * as H from '../../types/Health';
1313
import { HealthSubItem } from '../../types/Health';
14+
import { DRAWER } from '../../types/types';
1415
import { Workload } from '../../types/Workload';
1516
import { renderTrafficStatus } from '../Health/HealthDetails';
1617
import { MissingSidecar } from '../MissingSidecar/MissingSidecar';
@@ -24,6 +25,7 @@ type Props = {
2425
services?: string[];
2526
waypointWorkloads?: Workload[];
2627
workloads?: AppWorkload[];
28+
view?: string;
2729
};
2830

2931
const iconStyle = kialiStyle({
@@ -79,6 +81,10 @@ export const DetailDescription: React.FC<Props> = (props: Props) => {
7981
href = `${href}?clusterName=${props.cluster}`;
8082
}
8183

84+
if (props.view === DRAWER) {
85+
href = `#application/${namespace}_${appName}`;
86+
}
87+
8288
const link = <Link to={href}>{appName}</Link>;
8389

8490
return (
@@ -102,6 +108,9 @@ export const DetailDescription: React.FC<Props> = (props: Props) => {
102108
href = `${href}?clusterName=${props.cluster}`;
103109
}
104110

111+
if (props.view === DRAWER) {
112+
href = `#service/${namespace}_${serviceName}`;
113+
}
105114
const link = <Link to={href}>{serviceName}</Link>;
106115

107116
return (
@@ -177,6 +186,10 @@ export const DetailDescription: React.FC<Props> = (props: Props) => {
177186
href = `${href}?clusterName=${props.cluster}`;
178187
}
179188

189+
if (props.view === DRAWER) {
190+
href = `#workload/${props.namespace}_${workload.workloadName}`;
191+
}
192+
180193
const link = <Link to={href}>{workload.workloadName}</Link>;
181194

182195
return (
@@ -225,6 +238,10 @@ export const DetailDescription: React.FC<Props> = (props: Props) => {
225238
href = `${href}?clusterName=${props.cluster}`;
226239
}
227240

241+
if (props.view === DRAWER) {
242+
href = `#workload/${props.namespace}_${workload.workloadName}`;
243+
}
244+
228245
const link = <Link to={href}>{workload.workloadName}</Link>;
229246

230247
return (

plugins/kiali/src/components/Drawers/AppDetailsDrawer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { AppInfo } from '../../pages/AppDetails/AppInfo';
1111
import { kialiApiRef } from '../../services/Api';
1212
import { App, AppQuery } from '../../types/App';
1313
import { AppHealth } from '../../types/Health';
14-
import { ENTITY } from '../../types/types';
14+
import { DRAWER } from '../../types/types';
1515

1616
type Props = {
1717
namespace: string;
@@ -68,7 +68,7 @@ export const AppDetailsDrawer = (props: Props) => {
6868
return (
6969
<>
7070
{appItem && (
71-
<AppInfo app={appItem} duration={60} health={health} view={ENTITY} />
71+
<AppInfo app={appItem} duration={60} health={health} view={DRAWER} />
7272
)}
7373
</>
7474
);

plugins/kiali/src/components/Drawers/ServiceDetailsDrawer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ServiceInfo } from '../../pages/ServiceDetails/ServiceInfo';
1010
import { kialiApiRef } from '../../services/Api';
1111
import { Validations } from '../../types/IstioObjects';
1212
import { ServiceDetailsInfo } from '../../types/ServiceInfo';
13-
import { ENTITY } from '../../types/types';
13+
import { DRAWER } from '../../types/types';
1414

1515
type Props = {
1616
namespace: string;
@@ -63,7 +63,7 @@ export const ServiceDetailsDrawer = (props: Props) => {
6363
k8sGateways={[]}
6464
peerAuthentications={[]}
6565
istioAPIEnabled
66-
view={ENTITY}
66+
view={DRAWER}
6767
/>
6868
)}
6969
</>

plugins/kiali/src/components/Drawers/WorkloadDetailsDrawer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CircularProgress } from '@material-ui/core';
88
import { WorkloadInfo } from '../../pages/WorkloadDetails/WorkloadInfo';
99
import { kialiApiRef } from '../../services/Api';
1010
import { WorkloadHealth } from '../../types/Health';
11-
import { ENTITY } from '../../types/types';
11+
import { DRAWER } from '../../types/types';
1212
import { Workload, WorkloadQuery } from '../../types/Workload';
1313

1414
type Props = {
@@ -76,7 +76,7 @@ export const WorkloadDetailsDrawer = (props: Props) => {
7676
duration={60}
7777
namespace={props.namespace}
7878
health={health}
79-
view={ENTITY}
79+
view={DRAWER}
8080
/>
8181
)}
8282
</>

plugins/kiali/src/components/VirtualList/Renderers.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ const DrawerDiv = ({
120120
<div style={{ paddingBottom: '10px' }}>
121121
<IconButton
122122
key="dismiss"
123+
id="close_drawer"
123124
title="Close the drawer"
124125
onClick={() => toggleDrawer2(false)}
125126
color="inherit"
@@ -149,6 +150,7 @@ const DrawerDiv = ({
149150
<Button
150151
variant="contained"
151152
color="primary"
153+
id={`drawer_${namespace}_${name}`}
152154
onClick={() => toggleDrawer(true)}
153155
>
154156
{name}

plugins/kiali/src/dynamic/EntityKialiResourcesCard.tsx

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import * as React from 'react';
2+
import { useRef } from 'react';
3+
import { useLocation, useNavigate } from 'react-router-dom';
24

35
import {
46
CardTab,
@@ -20,8 +22,71 @@ const tabStyle: React.CSSProperties = {
2022
maxHeight: '400px',
2123
};
2224

25+
const tabs = ['workload', 'service', 'application'];
26+
2327
export const EntityKialiResourcesCard = () => {
2428
const { entity } = useEntity();
29+
const location = useLocation();
30+
const [element, setElement] = React.useState<string>();
31+
const prevElement = useRef(element);
32+
const [renderCount, setRenderCount] = React.useState(0);
33+
34+
const getInitValue = (): string => {
35+
const hash = location.hash.replace(/^#,?\s*/, '');
36+
const data = hash.split('/');
37+
38+
const close = document.getElementById('close_drawer');
39+
if (close) {
40+
close.click();
41+
}
42+
43+
if (data.length > 1 && data[1] !== element) {
44+
setElement(data[1]);
45+
}
46+
if (tabs.includes(data[0])) {
47+
return data[0];
48+
}
49+
return tabs[0];
50+
};
51+
const [value, setValue] = React.useState<string | number>(getInitValue());
52+
53+
const navigate = useNavigate();
54+
55+
const handleChange = (
56+
_: React.ChangeEvent<{}>,
57+
newValue: string | number,
58+
) => {
59+
setValue(newValue);
60+
navigate(`#${newValue}`);
61+
};
62+
63+
React.useEffect(() => {
64+
// This time out is needed to have rendered the context and be able to call the element to open the drawer
65+
const timeout = setTimeout(() => {
66+
setRenderCount(prevCount => prevCount + 1);
67+
}, 1000);
68+
return () => clearTimeout(timeout);
69+
}, []);
70+
71+
React.useEffect(() => {
72+
const val = getInitValue();
73+
if (val !== value) {
74+
setValue(val);
75+
setTimeout(() => {
76+
setRenderCount(prevCount => prevCount + 1);
77+
}, 1000);
78+
return;
79+
}
80+
81+
if (element && element !== prevElement.current && renderCount > 0) {
82+
const drawer = document.getElementById(`drawer_${element}`);
83+
if (drawer) {
84+
drawer.click();
85+
}
86+
prevElement.current = element;
87+
}
88+
}, [element, renderCount]);
89+
2590
return !entity ? (
2691
<EmptyState
2792
missing="data"
@@ -44,18 +109,22 @@ export const EntityKialiResourcesCard = () => {
44109
}
45110
/>
46111
) : (
47-
<TabbedCard title="Service Mesh Resources">
48-
<CardTab label="Workloads">
112+
<TabbedCard
113+
title="Service Mesh Resources"
114+
onChange={handleChange}
115+
value={value}
116+
>
117+
<CardTab label="Workloads" value="workload">
49118
<div style={tabStyle}>
50119
<WorkloadListPage view={DRAWER} entity={entity} />
51120
</div>
52121
</CardTab>
53-
<CardTab label="Services">
122+
<CardTab label="Services" value="service">
54123
<div style={tabStyle}>
55124
<ServiceListPage view={DRAWER} entity={entity} />
56125
</div>
57126
</CardTab>
58-
<CardTab label="Applications">
127+
<CardTab label="Applications" value="application">
59128
<div style={tabStyle}>
60129
<AppListPage view={DRAWER} entity={entity} />
61130
</div>

plugins/kiali/src/pages/AppDetails/AppDescription.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import * as H from '../../types/Health';
1414
type AppDescriptionProps = {
1515
app?: App;
1616
health?: H.Health;
17+
view?: string;
1718
};
1819

1920
const iconStyle = kialiStyle({
@@ -36,25 +37,29 @@ export const AppDescription: React.FC<AppDescriptionProps> = (
3637

3738
return props.app ? (
3839
<Card id="AppDescriptionCard" data-test="app-description-card">
39-
<CardHeader>
40-
<Typography variant="h6" style={{ margin: '10px' }}>
41-
<div key="service-icon" className={iconStyle}>
42-
<PFBadge badge={PFBadges.App} />
43-
</div>
40+
<CardHeader
41+
title={
42+
<>
43+
<Typography variant="h6" style={{ margin: '10px' }}>
44+
<div key="service-icon" className={iconStyle}>
45+
<PFBadge badge={PFBadges.App} />
46+
</div>
4447

45-
{props.app.name}
48+
{props.app.name}
4649

47-
<span className={healthIconStyle}>
48-
<HealthIndicator id={props.app.name} health={props.health} />
49-
</span>
50-
</Typography>
50+
<span className={healthIconStyle}>
51+
<HealthIndicator id={props.app.name} health={props.health} />
52+
</span>
53+
</Typography>
5154

52-
{props.app.cluster && isMultiCluster && (
53-
<div key="cluster-icon" style={{ paddingBottom: '0.5rem' }}>
54-
<PFBadge badge={PFBadges.Cluster} /> {props.app.cluster}
55-
</div>
56-
)}
57-
</CardHeader>
55+
{props.app.cluster && isMultiCluster && (
56+
<div key="cluster-icon" style={{ paddingBottom: '0.5rem' }}>
57+
<PFBadge badge={PFBadges.Cluster} /> {props.app.cluster}
58+
</div>
59+
)}
60+
</>
61+
}
62+
/>
5863
<CardContent>
5964
<Labels
6065
labels={appLabels}
@@ -67,6 +72,7 @@ export const AppDescription: React.FC<AppDescriptionProps> = (
6772
services={props.app ? props.app.serviceNames : []}
6873
health={props.health}
6974
cluster={props.app?.cluster}
75+
view={props.view}
7076
/>
7177
</CardContent>
7278
</Card>

plugins/kiali/src/pages/AppDetails/AppInfo.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Grid } from '@material-ui/core';
55
import { App } from '../../types/App';
66
import { DurationInSeconds } from '../../types/Common';
77
import { AppHealth } from '../../types/Health';
8-
import { ENTITY } from '../../types/types';
8+
import { DRAWER, ENTITY } from '../../types/types';
99
import { AppDescription } from './AppDescription';
1010

1111
type AppInfoProps = {
@@ -16,11 +16,15 @@ type AppInfoProps = {
1616
};
1717

1818
export const AppInfo = (appProps: AppInfoProps) => {
19-
const size = appProps.view === ENTITY ? 12 : 4;
19+
const size = appProps.view === ENTITY || appProps.view === DRAWER ? 12 : 4;
2020
return (
2121
<Grid container spacing={1} style={{ paddingTop: '20px' }}>
2222
<Grid key={`Card_${appProps.app?.name}`} item xs={size}>
23-
<AppDescription app={appProps.app} health={appProps.health} />
23+
<AppDescription
24+
app={appProps.app}
25+
health={appProps.health}
26+
view={appProps.view}
27+
/>
2428
</Grid>
2529
</Grid>
2630
);

plugins/kiali/src/pages/ServiceDetails/ServiceDescription.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import { ServiceDetailsInfo, WorkloadOverview } from '../../types/ServiceInfo';
2424
interface ServiceInfoDescriptionProps {
2525
namespace: string;
2626
serviceDetails?: ServiceDetailsInfo;
27+
view?: string;
2728
}
2829

2930
const resourceListStyle = kialiStyle({
@@ -235,6 +236,7 @@ export const ServiceDescription: React.FC<ServiceInfoDescriptionProps> = (
235236
workloads={workloads}
236237
health={props.serviceDetails?.health}
237238
cluster={props.serviceDetails?.cluster}
239+
view={props.view}
238240
/>
239241
</CardContent>
240242
</Card>

plugins/kiali/src/pages/ServiceDetails/ServiceInfo.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
} from '../../types/IstioObjects';
2323
import { ServiceId } from '../../types/ServiceId';
2424
import { ServiceDetailsInfo } from '../../types/ServiceInfo';
25-
import { ENTITY } from '../../types/types';
25+
import { DRAWER, ENTITY } from '../../types/types';
2626
import { ServiceDescription } from './ServiceDescription';
2727
import { ServiceNetwork } from './ServiceNetwork';
2828

@@ -112,7 +112,8 @@ export const ServiceInfo = (serviceProps: Props) => {
112112
),
113113
);
114114

115-
const size = serviceProps.view === ENTITY ? 12 : 4;
115+
const size =
116+
serviceProps.view === ENTITY || serviceProps.view === DRAWER ? 12 : 4;
116117
return (
117118
<>
118119
{serviceProps.serviceDetails && (
@@ -121,9 +122,10 @@ export const ServiceInfo = (serviceProps: Props) => {
121122
<ServiceDescription
122123
namespace={serviceProps.namespace}
123124
serviceDetails={serviceProps.serviceDetails}
125+
view={serviceProps.view}
124126
/>
125127
</Grid>
126-
{serviceProps.view !== ENTITY && (
128+
{serviceProps.view !== DRAWER && (
127129
<>
128130
<Grid key={`Card_${serviceProps.service}`} item xs={4}>
129131
<ServiceNetwork

0 commit comments

Comments
 (0)