Skip to content

Commit

Permalink
Retrieve VM template via jsonpath and accessor method
Browse files Browse the repository at this point in the history
Signed-off-by: Radoslaw Szwajkowski <[email protected]>
  • Loading branch information
rszwajko committed Sep 29, 2023
1 parent 8483bbf commit 703b6f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react';

import { EnumToTuple, ResourceFieldFactory } from '@kubev2v/common';
import { OpenshiftVM } from '@kubev2v/types';

import { ProviderVirtualMachinesList } from './components/ProviderVirtualMachinesList';
import { VmData } from './components';
Expand Down Expand Up @@ -37,8 +36,7 @@ const openShiftVmFieldsMetadataFactory: ResourceFieldFactory = (t) => [
},
{
resourceFieldId: 'template',
jsonPath: (data: VmData) =>
(data?.vm as OpenshiftVM)?.object?.metadata?.labels?.['vm.kubevirt.io/template'] ?? '',
jsonPath: "$.vm.object.metadata.labels['vm.kubevirt.io/template']",
label: t('Template'),
isVisible: true,
isIdentity: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@ import React from 'react';
import { TableCell } from 'src/modules/Providers/utils';

import { ResourceField, RowProps } from '@kubev2v/common';
import { OpenshiftVM } from '@kubev2v/types';
import { Td, Tr } from '@patternfly/react-table';

import { PowerStateCellRenderer } from './components/PowerStateCellRenderer';
import { getVmTemplate } from './utils/helpers/vmProps';
import { VMCellProps, VmData, VMNameCellRenderer } from './components';

const cellRenderers: Record<string, React.FC<VMCellProps>> = {
name: VMNameCellRenderer,
status: PowerStateCellRenderer,
template: ({ data }) => (
<TableCell>
{(data?.vm as OpenshiftVM)?.object?.metadata?.labels?.['vm.kubevirt.io/template'] ?? ''}
</TableCell>
),
template: ({ data }) => <TableCell>{getVmTemplate(data?.vm)}</TableCell>,
};

const renderTd = ({ resourceData, resourceFieldId, resourceFields }: RenderTdProps) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ProviderVirtualMachine } from '@kubev2v/types';

export const getVmTemplate = (vm: ProviderVirtualMachine): string | undefined =>
vm?.providerType === 'openshift'
? vm.object?.metadata?.labels?.['vm.kubevirt.io/template']
: undefined;

0 comments on commit 703b6f4

Please sign in to comment.