Skip to content

Commit c5a4336

Browse files
committed
Update Renderer
1 parent 41f7ce6 commit c5a4336

File tree

1 file changed

+66
-59
lines changed

1 file changed

+66
-59
lines changed

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

Lines changed: 66 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,67 @@ export const actionRenderer = (
9999
);
100100
};
101101

102+
const DrawerDiv = ({
103+
name,
104+
namespace,
105+
config,
106+
}: {
107+
name: string;
108+
namespace: string;
109+
config: string;
110+
}) => {
111+
const [isOpen, toggleDrawer] = React.useState(false);
112+
113+
const DrawerContent = ({
114+
toggleDrawer2,
115+
}: {
116+
toggleDrawer2: (isOpen: boolean) => void;
117+
}) => {
118+
return (
119+
<div style={{ padding: '10px', minWidth: '400px' }}>
120+
<div style={{ paddingBottom: '10px' }}>
121+
<IconButton
122+
key="dismiss"
123+
title="Close the drawer"
124+
onClick={() => toggleDrawer2(false)}
125+
color="inherit"
126+
style={{ right: '0', position: 'absolute', top: '5px' }}
127+
>
128+
<Close />
129+
</IconButton>
130+
</div>
131+
<div />
132+
<div>
133+
{config === 'workloads' && (
134+
<WorkloadDetailsDrawer namespace={namespace} workload={name} />
135+
)}
136+
{config === 'services' && (
137+
<ServiceDetailsDrawer namespace={namespace} service={name} />
138+
)}
139+
{config === 'applications' && (
140+
<AppDetailsDrawer namespace={namespace} app={name} />
141+
)}
142+
</div>
143+
</div>
144+
);
145+
};
146+
147+
return (
148+
<>
149+
<Button
150+
variant="contained"
151+
color="primary"
152+
onClick={() => toggleDrawer(true)}
153+
>
154+
{name}
155+
</Button>
156+
<Drawer anchor="right" open={isOpen} onClose={() => toggleDrawer(false)}>
157+
<DrawerContent toggleDrawer2={toggleDrawer} />
158+
</Drawer>
159+
</>
160+
);
161+
};
162+
102163
export const item: Renderer<TResource> = (
103164
resource: TResource,
104165
config: Resource,
@@ -126,70 +187,16 @@ export const item: Renderer<TResource> = (
126187
}
127188

128189
if (view === DRAWER) {
129-
// eslint-disable-next-line react-hooks/rules-of-hooks
130-
const [isOpen, toggleDrawer] = React.useState(false);
131-
const DrawerContent = ({
132-
toggleDrawer2,
133-
}: {
134-
toggleDrawer2: (isOpen: boolean) => void;
135-
}) => {
136-
return (
137-
<div style={{ padding: '10px', minWidth: '400px' }}>
138-
<div style={{ paddingBottom: '10px' }}>
139-
<IconButton
140-
key="dismiss"
141-
title="Close the drawer"
142-
onClick={() => toggleDrawer2(false)}
143-
color="inherit"
144-
style={{ right: '0', position: 'absolute', top: '5px' }}
145-
>
146-
<Close />
147-
</IconButton>
148-
</div>
149-
<div />
150-
<div>
151-
{config.name === 'workloads' && (
152-
<WorkloadDetailsDrawer
153-
namespace={resource.namespace}
154-
workload={resource.name}
155-
/>
156-
)}
157-
{config.name === 'services' && (
158-
<ServiceDetailsDrawer
159-
namespace={resource.namespace}
160-
service={resource.name}
161-
/>
162-
)}
163-
{config.name === 'applications' && (
164-
<AppDetailsDrawer
165-
namespace={resource.namespace}
166-
app={resource.name}
167-
/>
168-
)}
169-
</div>
170-
</div>
171-
);
172-
};
173-
174190
return (
175191
<TableCell
176192
key={`VirtuaItem_Item_${resource.namespace}_${resource.name}`}
177193
style={{ verticalAlign: 'middle', whiteSpace: 'nowrap' }}
178194
>
179-
<Button
180-
variant="contained"
181-
color="primary"
182-
onClick={() => toggleDrawer(true)}
183-
>
184-
{resource.name}
185-
</Button>
186-
<Drawer
187-
anchor="right"
188-
open={isOpen}
189-
onClose={() => toggleDrawer(false)}
190-
>
191-
<DrawerContent toggleDrawer2={toggleDrawer} />
192-
</Drawer>
195+
<DrawerDiv
196+
name={resource.name}
197+
namespace={resource.namespace}
198+
config={config.name}
199+
/>
193200
</TableCell>
194201
);
195202
}

0 commit comments

Comments
 (0)