Skip to content

Commit ad2219a

Browse files
authored
VirtualMachine launch link in search result (stolostron#3829)
* VirtualMachine launch link in search result Signed-off-by: zlayne <zlayne@redhat.com> * fix lint Signed-off-by: zlayne <zlayne@redhat.com> * update snapshot Signed-off-by: zlayne <zlayne@redhat.com> --------- Signed-off-by: zlayne <zlayne@redhat.com>
1 parent c274c08 commit ad2219a

File tree

3 files changed

+126
-1
lines changed

3 files changed

+126
-1
lines changed

frontend/src/routes/Search/__snapshots__/searchDefinitions.test.tsx.snap

+43
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,24 @@ exports[`Correctly returns CreateExternalLink from consoleURL 1`] = `
223223
</a>
224224
`;
225225

226+
exports[`Correctly returns CreateExternalVMLink 1`] = `
227+
<body>
228+
<div>
229+
<a
230+
aria-disabled="false"
231+
class="pf-c-button pf-m-link pf-m-inline"
232+
data-ouia-component-id="OUIA-Generated-Button-link-7"
233+
data-ouia-component-type="PF4/Button"
234+
data-ouia-safe="true"
235+
href="https://testCluster.com/k8s/ns/testVM/kubevirt.io~v1~VirtualMachine/testVM"
236+
target="_blank"
237+
>
238+
Launch
239+
</a>
240+
</div>
241+
</body>
242+
`;
243+
226244
exports[`Correctly returns CreateGlobalSearchDetailsLink managed cluster Application resource 1`] = `
227245
<body>
228246
<div>
@@ -2386,6 +2404,23 @@ Array [
23862404
"header": "Ready",
23872405
"sort": "ready",
23882406
},
2407+
Object {
2408+
"cell": <CreateExternalVMLink
2409+
item={
2410+
Object {
2411+
"cluster": "testCluster",
2412+
"created": "2021-01-01T00:00:00Z",
2413+
"kind": "Pod",
2414+
"label": "testLabel=label; testLabel1=label1",
2415+
"name": "testName",
2416+
"namespace": "testNamespace",
2417+
"selfLink": "/apigroup/cluster/name",
2418+
}
2419+
}
2420+
t={[Function]}
2421+
/>,
2422+
"header": "Console URL",
2423+
},
23892424
Object {
23902425
"cell": "in a month",
23912426
"header": "Created",
@@ -2431,6 +2466,14 @@ exports[`Correctly returns empty CreateApplicationTopologyLink 1`] = `
24312466

24322467
exports[`Correctly returns empty CreateExternalLink 1`] = `"-"`;
24332468

2469+
exports[`Correctly returns empty CreateExternalVMLink 1`] = `
2470+
<body>
2471+
<div>
2472+
-
2473+
</div>
2474+
</body>
2475+
`;
2476+
24342477
exports[`Correctly returns empty labels 1`] = `"-"`;
24352478

24362479
exports[`Correctly returns formatSearchbarSuggestions no timestamp 1`] = `"-"`;

frontend/src/routes/Search/searchDefinitions.test.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
CreateApplicationTopologyLink,
1212
CreateDetailsLink,
1313
CreateExternalLink,
14+
CreateExternalVMLink,
1415
CreateGlobalSearchDetailsLink,
1516
FormatLabels,
1617
FormatPolicyReportCategories,
@@ -625,3 +626,53 @@ test('Correctly returns url search params with 0 params', () => {
625626
const result = GetUrlSearchParam(item)
626627
expect(result).toMatchSnapshot()
627628
})
629+
630+
test('Correctly returns CreateExternalVMLink', () => {
631+
const item = {
632+
cluster: 'testCluster',
633+
name: 'testVM',
634+
namespace: 'testVM',
635+
}
636+
const { baseElement } = render(
637+
<RecoilRoot
638+
initializeState={(snapshot) => {
639+
snapshot.set(managedClusterInfosState, [
640+
{
641+
apiVersion: ManagedClusterInfoApiVersion,
642+
kind: ManagedClusterInfoKind,
643+
metadata: {
644+
name: 'testCluster',
645+
namespace: 'testCluster',
646+
},
647+
status: {
648+
consoleURL: 'https://testCluster.com',
649+
conditions: [],
650+
version: '1.17',
651+
},
652+
},
653+
])
654+
}}
655+
>
656+
<MemoryRouter>
657+
<CreateExternalVMLink item={item} t={t} />
658+
</MemoryRouter>
659+
</RecoilRoot>
660+
)
661+
expect(baseElement).toMatchSnapshot()
662+
})
663+
664+
test('Correctly returns empty CreateExternalVMLink', () => {
665+
const item = {
666+
cluster: 'testCluster',
667+
name: 'testVM',
668+
namespace: 'testVM',
669+
}
670+
const { baseElement } = render(
671+
<RecoilRoot>
672+
<MemoryRouter>
673+
<CreateExternalVMLink item={item} t={t} />
674+
</MemoryRouter>
675+
</RecoilRoot>
676+
)
677+
expect(baseElement).toMatchSnapshot()
678+
})

frontend/src/routes/Search/searchDefinitions.tsx

+32-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,16 @@ export const getSearchDefinitions: (t: TFunction, isGlobalHub?: boolean) => Reso
368368
]),
369369
},
370370
virtualmachine: {
371-
columns: AddDefaultColumns(t, [AddColumn('status', t('Status')), AddColumn('ready', t('Ready'))]),
371+
columns: AddDefaultColumns(t, [
372+
AddColumn('status', t('Status')),
373+
AddColumn('ready', t('Ready')),
374+
{
375+
header: t('Console URL'),
376+
cell: (item: any) => {
377+
return <CreateExternalVMLink item={item} t={t} />
378+
},
379+
},
380+
]),
372381
},
373382
}
374383
}
@@ -733,3 +742,25 @@ function AddColumn(key: string, localizedColumnName: string): SearchColumnDefini
733742
}
734743
}
735744
}
745+
746+
export function CreateExternalVMLink(props: { item: any; t: TFunction }) {
747+
const { item, t } = props
748+
const allClusters = useAllClusters(true)
749+
const vmCluster = item.cluster
750+
const clusterURL = allClusters.filter((c) => c.name === vmCluster)?.[0]?.consoleURL
751+
752+
if (clusterURL) {
753+
return (
754+
<AcmButton
755+
variant="link"
756+
component="a"
757+
target="_blank"
758+
isInline={true}
759+
href={`${clusterURL}/k8s/ns/${item.namespace}/kubevirt.io~v1~VirtualMachine/${item.name}`}
760+
>
761+
{t('Launch')}
762+
</AcmButton>
763+
)
764+
}
765+
return <>{'-'}</>
766+
}

0 commit comments

Comments
 (0)