Skip to content
32 changes: 24 additions & 8 deletions frontend/packages/console-app/src/components/pdb/PDBList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import { useMemo, Suspense } from 'react';
import { useTranslation } from 'react-i18next';
import {
actionsCellProps,
cellIsStickyProps,
getNameCellProps,
ConsoleDataView,
nameCellProps,
} from '@console/app/src/components/data-view/ConsoleDataView';
import type { GetDataViewRows } from '@console/app/src/components/data-view/types';
import { useColumnWidthSettings } from '@console/app/src/components/data-view/useResizableColumnProps';
import type { TableColumn } from '@console/dynamic-plugin-sdk/src/extensions/console-types';
import { ResourceLink } from '@console/internal/components/utils/resource-link';
import { Selector } from '@console/internal/components/utils/selector';
Expand Down Expand Up @@ -74,23 +75,32 @@ const getDataViewRows: GetDataViewRows<PodDisruptionBudgetKind> = (data, columns
});
};

const usePDBColumns = (): TableColumn<PodDisruptionBudgetKind>[] => {
const usePDBColumns = (): {
columns: TableColumn<PodDisruptionBudgetKind>[];
resetAllColumnWidths: () => void;
} => {
const { t } = useTranslation();
const { getResizableProps, resetAllColumnWidths } = useColumnWidthSettings(
PodDisruptionBudgetModel,
);

const columns = useMemo(() => {
return [
{
title: t('console-app~Name'),
id: tableColumnInfo[0].id,
sort: 'metadata.name',
resizableProps: getResizableProps(tableColumnInfo[0].id),
props: {
...cellIsStickyProps,
...nameCellProps,
modifier: 'nowrap',
},
},
{
title: t('console-app~Namespace'),
id: tableColumnInfo[1].id,
sort: 'metadata.namespace',
resizableProps: getResizableProps(tableColumnInfo[1].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -99,15 +109,16 @@ const usePDBColumns = (): TableColumn<PodDisruptionBudgetKind>[] => {
title: t('console-app~Selector'),
id: tableColumnInfo[2].id,
sort: 'spec.selector',
resizableProps: getResizableProps(tableColumnInfo[2].id),
props: {
modifier: 'nowrap',
width: 20,
},
},
{
title: t('console-app~Availability'),
id: tableColumnInfo[3].id,
sort: 'spec.minAvailable',
resizableProps: getResizableProps(tableColumnInfo[3].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -116,6 +127,7 @@ const usePDBColumns = (): TableColumn<PodDisruptionBudgetKind>[] => {
title: t('console-app~Allowed disruptions'),
id: tableColumnInfo[4].id,
sort: 'status.disruptionsAllowed',
resizableProps: getResizableProps(tableColumnInfo[4].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -124,6 +136,7 @@ const usePDBColumns = (): TableColumn<PodDisruptionBudgetKind>[] => {
title: t('console-app~Created'),
id: tableColumnInfo[5].id,
sort: 'metadata.creationTimestamp',
resizableProps: getResizableProps(tableColumnInfo[5].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -132,16 +145,17 @@ const usePDBColumns = (): TableColumn<PodDisruptionBudgetKind>[] => {
title: '',
id: tableColumnInfo[6].id,
props: {
...cellIsStickyProps,
...actionsCellProps,
},
},
];
}, [t]);
return columns;
}, [t, getResizableProps]);

return { columns, resetAllColumnWidths };
};

const PodDisruptionBudgetList: FC<PodDisruptionBudgetsListProps> = ({ data, loaded, ...props }) => {
const columns = usePDBColumns();
const { columns, resetAllColumnWidths } = usePDBColumns();

return (
<Suspense fallback={<LoadingBox />}>
Expand All @@ -153,6 +167,8 @@ const PodDisruptionBudgetList: FC<PodDisruptionBudgetsListProps> = ({ data, load
columns={columns}
getDataViewRows={getDataViewRows}
hideColumnManagement
isResizable
resetAllColumnWidths={resetAllColumnWidths}
/>
</Suspense>
);
Expand Down
28 changes: 21 additions & 7 deletions frontend/public/components/configmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ import { ConfigMapKind, referenceForModel, TableColumn } from '../module/k8s';
import { getGroupVersionKindForModel } from '@console/dynamic-plugin-sdk/src/utils/k8s/k8s-ref';
import {
actionsCellProps,
cellIsStickyProps,
getNameCellProps,
ConsoleDataView,
nameCellProps,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { useColumnWidthSettings } from '@console/app/src/components/data-view/useResizableColumnProps';
import { GetDataViewRows } from '@console/app/src/components/data-view/types';
import { LoadingBox } from '@console/shared/src/components/loading';
import { sortResourceByValue } from './factory/Table/sort';
Expand Down Expand Up @@ -78,23 +79,30 @@ const getDataViewRows: GetDataViewRows<ConfigMapKind> = (data, columns) => {
});
};

const useConfigMapsColumns = (): TableColumn<ConfigMapKind>[] => {
const useConfigMapsColumns = (): {
columns: TableColumn<ConfigMapKind>[];
resetAllColumnWidths: () => void;
} => {
const { t } = useTranslation();
return useMemo(
const { getResizableProps, resetAllColumnWidths } = useColumnWidthSettings(ConfigMapModel);

const columns = useMemo(
() => [
{
title: t('public~Name'),
id: tableColumnInfo[0].id,
sort: 'metadata.name',
resizableProps: getResizableProps(tableColumnInfo[0].id),
props: {
...cellIsStickyProps,
...nameCellProps,
modifier: 'nowrap',
},
},
{
title: t('public~Namespace'),
id: tableColumnInfo[1].id,
sort: 'metadata.namespace',
resizableProps: getResizableProps(tableColumnInfo[1].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -103,6 +111,7 @@ const useConfigMapsColumns = (): TableColumn<ConfigMapKind>[] => {
title: t('public~Size'),
id: tableColumnInfo[2].id,
sort: (data, direction) => data.sort(sortResourceByValue(direction, sorts.dataSize)),
resizableProps: getResizableProps(tableColumnInfo[2].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -111,6 +120,7 @@ const useConfigMapsColumns = (): TableColumn<ConfigMapKind>[] => {
title: t('public~Created'),
id: tableColumnInfo[3].id,
sort: 'metadata.creationTimestamp',
resizableProps: getResizableProps(tableColumnInfo[3].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -119,16 +129,18 @@ const useConfigMapsColumns = (): TableColumn<ConfigMapKind>[] => {
title: '',
id: tableColumnInfo[4].id,
props: {
...cellIsStickyProps,
...actionsCellProps,
},
},
],
[t],
[t, getResizableProps],
);

return { columns, resetAllColumnWidths };
};

export const ConfigMaps: FC<ConfigMapsProps> = ({ data, loaded, ...props }) => {
const columns = useConfigMapsColumns();
const { columns, resetAllColumnWidths } = useConfigMapsColumns();

return (
<Suspense fallback={<LoadingBox />}>
Expand All @@ -140,6 +152,8 @@ export const ConfigMaps: FC<ConfigMapsProps> = ({ data, loaded, ...props }) => {
columns={columns}
getDataViewRows={getDataViewRows}
hideColumnManagement={true}
isResizable
resetAllColumnWidths={resetAllColumnWidths}
/>
</Suspense>
);
Expand Down
31 changes: 23 additions & 8 deletions frontend/public/components/cron-job.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ import { PodDisruptionBudgetField } from '@console/app/src/components/pdb/PodDis
import { DescriptionList, Grid, GridItem } from '@patternfly/react-core';
import {
actionsCellProps,
cellIsStickyProps,
getNameCellProps,
ConsoleDataView,
nameCellProps,
} from '@console/app/src/components/data-view/ConsoleDataView';
import { useColumnWidthSettings } from '@console/app/src/components/data-view/useResizableColumnProps';
import { GetDataViewRows } from '@console/app/src/components/data-view/types';
import { getGroupVersionKindForModel } from '@console/dynamic-plugin-sdk/src/utils/k8s/k8s-ref';
import { LoadingBox } from './utils/status-box';
Expand Down Expand Up @@ -302,23 +303,30 @@ export const CronJobJobsComponent: FC<CronJobJobsComponentProps> = ({ obj }) =>
</PaneBody>
);

const useCronJobsColumns = (): TableColumn<CronJobKind>[] => {
const useCronJobsColumns = (): {
columns: TableColumn<CronJobKind>[];
resetAllColumnWidths: () => void;
} => {
const { t } = useTranslation();
const columns: TableColumn<CronJobKind>[] = useMemo(() => {
const { getResizableProps, resetAllColumnWidths } = useColumnWidthSettings(CronJobModel);

const columns = useMemo(() => {
return [
{
title: t('public~Name'),
id: tableColumnInfo[0].id,
sort: 'metadata.name',
resizableProps: getResizableProps(tableColumnInfo[0].id),
props: {
...cellIsStickyProps,
...nameCellProps,
modifier: 'nowrap',
},
},
{
title: t('public~Namespace'),
id: tableColumnInfo[1].id,
sort: 'metadata.namespace',
resizableProps: getResizableProps(tableColumnInfo[1].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -327,6 +335,7 @@ const useCronJobsColumns = (): TableColumn<CronJobKind>[] => {
title: t('public~Schedule'),
id: tableColumnInfo[2].id,
sort: 'spec.schedule',
resizableProps: getResizableProps(tableColumnInfo[2].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -335,6 +344,7 @@ const useCronJobsColumns = (): TableColumn<CronJobKind>[] => {
title: t('public~Suspend'),
id: tableColumnInfo[3].id,
sort: 'spec.suspend',
resizableProps: getResizableProps(tableColumnInfo[3].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -343,6 +353,7 @@ const useCronJobsColumns = (): TableColumn<CronJobKind>[] => {
title: t('public~Concurrency policy'),
id: tableColumnInfo[4].id,
sort: 'spec.concurrencyPolicy',
resizableProps: getResizableProps(tableColumnInfo[4].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -351,6 +362,7 @@ const useCronJobsColumns = (): TableColumn<CronJobKind>[] => {
title: t('public~Starting deadline seconds'),
id: tableColumnInfo[5].id,
sort: 'spec.startingDeadlineSeconds',
resizableProps: getResizableProps(tableColumnInfo[5].id),
props: {
modifier: 'nowrap',
},
Expand All @@ -359,16 +371,17 @@ const useCronJobsColumns = (): TableColumn<CronJobKind>[] => {
title: '',
id: tableColumnInfo[6].id,
props: {
...cellIsStickyProps,
...actionsCellProps,
},
},
];
}, [t]);
return columns;
}, [t, getResizableProps]);

return { columns, resetAllColumnWidths };
};

export const CronJobsList: FC<CronJobsListProps> = ({ data, loaded, ...props }) => {
const columns = useCronJobsColumns();
const { columns, resetAllColumnWidths } = useCronJobsColumns();

return (
<Suspense fallback={<LoadingBox />}>
Expand All @@ -380,6 +393,8 @@ export const CronJobsList: FC<CronJobsListProps> = ({ data, loaded, ...props })
columns={columns}
getDataViewRows={getDataViewRows}
hideColumnManagement={true}
isResizable
resetAllColumnWidths={resetAllColumnWidths}
/>
</Suspense>
);
Expand Down
Loading