Skip to content

Commit

Permalink
Bug 2177091: hide edit buttons on catalog drawer
Browse files Browse the repository at this point in the history
  • Loading branch information
upalatucci committed Mar 22, 2023
1 parent 2162413 commit ef551da
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/utils/components/HardwareDevices/HardwareDeviceTitle.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React, { FC } from 'react';

import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import { Button, DescriptionListTerm } from '@patternfly/react-core';
Expand All @@ -7,12 +7,20 @@ import { PencilAltIcon } from '@patternfly/react-icons';
type HardwareDeviceTitleProps = {
title: string;
canEdit: boolean;
hideEdit?: boolean;
onClick?: () => void;
};

const HardwareDeviceTitle: React.FC<HardwareDeviceTitleProps> = ({ title, canEdit, onClick }) => {
const HardwareDeviceTitle: FC<HardwareDeviceTitleProps> = ({
title,
canEdit,
hideEdit = false,
onClick,
}) => {
const { t } = useKubevirtTranslation();

if (hideEdit) return <DescriptionListTerm>{title}</DescriptionListTerm>;

return (
<DescriptionListTerm>
<Button
Expand Down
21 changes: 17 additions & 4 deletions src/utils/components/HardwareDevices/HardwareDevices.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as React from 'react';
import React, { FC } from 'react';

import { V1VirtualMachine, V1VirtualMachineInstance } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
Expand All @@ -21,10 +21,17 @@ type HardwareDevicesProps = {
vm: V1VirtualMachine;
onSubmit?: (vm: V1VirtualMachine) => Promise<void | V1VirtualMachine>;
canEdit?: boolean;
hideEdit?: boolean;
vmi?: V1VirtualMachineInstance;
};

const HardwareDevices: React.FC<HardwareDevicesProps> = ({ vm, vmi, onSubmit, canEdit = true }) => {
const HardwareDevices: FC<HardwareDevicesProps> = ({
vm,
vmi,
onSubmit,
canEdit = true,
hideEdit = false,
}) => {
const { t } = useKubevirtTranslation();
const { createModal } = useModal();

Expand Down Expand Up @@ -66,7 +73,12 @@ const HardwareDevices: React.FC<HardwareDevicesProps> = ({ vm, vmi, onSubmit, ca
return (
<DescriptionList>
<DescriptionListGroup>
<HardwareDeviceTitle title={t('GPU devices')} onClick={onEditGPU} canEdit={canEdit} />
<HardwareDeviceTitle
title={t('GPU devices')}
onClick={onEditGPU}
canEdit={canEdit}
hideEdit={hideEdit}
/>
<DescriptionListDescription>
<HardwareDevicesTable devices={gpus} />
</DescriptionListDescription>
Expand All @@ -77,12 +89,13 @@ const HardwareDevices: React.FC<HardwareDevicesProps> = ({ vm, vmi, onSubmit, ca
title={t('Host devices')}
onClick={onEditHostDevices}
canEdit={canEdit}
hideEdit={hideEdit}
/>
<DescriptionListDescription>
<HardwareDevicesTable devices={hostDevices} />
</DescriptionListDescription>
</DescriptionListGroup>
{canEdit && (
{canEdit && !hideEdit && (
<DescriptionListGroup>
<HardwareDevicesHeadlessMode vm={vm} vmi={vmi} onSubmit={onSubmit} />
</DescriptionListGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const TemplatesCatalogDrawerPanel: React.FC<TemplatesCatalogDrawerPanelPr
{` (${hardwareDevicesCount})`}
</DescriptionListTerm>
<DescriptionListDescription>
<HardwareDevices canEdit={false} vm={vmObject} />
<HardwareDevices hideEdit vm={vmObject} />
</DescriptionListDescription>
</DescriptionListGroup>
</DescriptionList>
Expand Down

0 comments on commit ef551da

Please sign in to comment.