Skip to content

Commit

Permalink
Merge pull request #2241 from upalatucci/hide-namespace-column
Browse files Browse the repository at this point in the history
CNV-50471: show/hide namespace bootablevolume column
  • Loading branch information
openshift-merge-bot[bot] authored Nov 4, 2024
2 parents 519d55e + df948aa commit 6d6b1e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 12 deletions.
17 changes: 13 additions & 4 deletions src/views/bootablevolumes/list/components/BootableVolumesRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@kubevirt-ui/kubevirt-api/containerized-data-importer/models';
import { V1beta1VirtualMachineClusterPreference } from '@kubevirt-ui/kubevirt-api/kubevirt';
import DeprecatedBadge from '@kubevirt-utils/components/badges/DeprecatedBadge/DeprecatedBadge';
import { ALL_NAMESPACES_SESSION_KEY } from '@kubevirt-utils/hooks/constants';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import {
getBootableVolumeGroupVersionKind,
Expand All @@ -23,7 +24,12 @@ import {
import { ANNOTATIONS } from '@kubevirt-utils/resources/template';
import { isDataSourceCloning } from '@kubevirt-utils/resources/template/hooks/useVmTemplateSource/utils';
import { NO_DATA_DASH } from '@kubevirt-utils/resources/vm/utils/constants';
import { ResourceLink, RowProps, TableData } from '@openshift-console/dynamic-plugin-sdk';
import {
ResourceLink,
RowProps,
TableData,
useActiveNamespace,
} from '@openshift-console/dynamic-plugin-sdk';
import { Label } from '@patternfly/react-core';
import { TableText, WrapModifier } from '@patternfly/react-table';

Expand All @@ -43,6 +49,7 @@ const BootableVolumesRow: FC<
>
> = ({ activeColumnIDs, obj, rowData: { dataImportCrons, preferences } }) => {
const { t } = useKubevirtTranslation();
const [namespace] = useActiveNamespace();

const bootableVolumeName = getName(obj);
const bootableVolumeNamespace = getNamespace(obj);
Expand All @@ -65,9 +72,11 @@ const BootableVolumesRow: FC<
{isDeprecated(bootableVolumeName) && <DeprecatedBadge />}
{obj.kind === DataSourceModel.kind && isCloning && <Label>{t('Clone in progress')}</Label>}
</TableData>
<TableData activeColumnIDs={activeColumnIDs} className="pf-m-width-20" id="namespace">
<ResourceLink kind="Namespace" name={bootableVolumeNamespace} />
</TableData>
{namespace === ALL_NAMESPACES_SESSION_KEY && (
<TableData activeColumnIDs={activeColumnIDs} className="pf-m-width-20" id="namespace">
<ResourceLink kind="Namespace" name={bootableVolumeNamespace} />
</TableData>
)}
<TableData activeColumnIDs={activeColumnIDs} className="pf-m-width-15" id="os">
{getPreferenceReadableOS(obj, preferences)}
</TableData>
Expand Down
26 changes: 18 additions & 8 deletions src/views/bootablevolumes/list/hooks/useBootableVolumesColumns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ import { useCallback, useMemo } from 'react';

import { DataSourceModelRef } from '@kubevirt-ui/kubevirt-api/console';
import { V1beta1VirtualMachineClusterPreference } from '@kubevirt-ui/kubevirt-api/kubevirt';
import { ALL_NAMESPACES_SESSION_KEY } from '@kubevirt-utils/hooks/constants';
import { useKubevirtTranslation } from '@kubevirt-utils/hooks/useKubevirtTranslation';
import useKubevirtUserSettingsTableColumns from '@kubevirt-utils/hooks/useKubevirtUserSettings/useKubevirtUserSettingsTableColumns';
import { columnSorting } from '@kubevirt-utils/utils/utils';
import { K8sResourceCommon, TableColumn } from '@openshift-console/dynamic-plugin-sdk';
import {
K8sResourceCommon,
TableColumn,
useActiveNamespace,
} from '@openshift-console/dynamic-plugin-sdk';
import { sortable } from '@patternfly/react-table';

import { BootableResource } from '../../utils/types';
Expand All @@ -17,6 +22,7 @@ const useBootableVolumesColumns = (
preferences: V1beta1VirtualMachineClusterPreference[],
): [TableColumn<K8sResourceCommon>[], TableColumn<K8sResourceCommon>[], boolean] => {
const { t } = useKubevirtTranslation();
const [namespace] = useActiveNamespace();
const { endIndex, startIndex } = pagination;

const sorting = useCallback(
Expand All @@ -33,13 +39,17 @@ const useBootableVolumesColumns = (
title: t('Name'),
transforms: [sortable],
},
{
id: 'namespace',
props: { className: 'pf-m-width-20' },
sort: (_, direction) => sorting(direction, 'metadata.namespace'),
title: t('Namespace'),
transforms: [sortable],
},
...(namespace === ALL_NAMESPACES_SESSION_KEY
? [
{
id: 'namespace',
props: { className: 'pf-m-width-20' },
sort: (_, direction) => sorting(direction, 'metadata.namespace'),
title: t('Namespace'),
transforms: [sortable],
},
]
: []),
{
id: 'os',
props: { className: 'pf-m-width-15' },
Expand Down

0 comments on commit 6d6b1e0

Please sign in to comment.