Skip to content

Commit c05ff79

Browse files
committed
add resizable column feature to workload table
1 parent ced28ea commit c05ff79

5 files changed

Lines changed: 32 additions & 13 deletions

File tree

frontend/public/components/daemon-set.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ const EnvironmentTab: FC<EnvironmentTabProps> = (props) => (
114114
);
115115

116116
export const DaemonSetsList: FC<DaemonSetsListProps> = ({ data, loaded, ...props }) => {
117-
const columns = useWorkloadColumns<DaemonSetKind>();
117+
const { columns, resetAllColumnWidths } = useWorkloadColumns<DaemonSetKind>(DaemonSetModel);
118118

119119
return (
120120
<Suspense fallback={<LoadingBox />}>
@@ -126,6 +126,8 @@ export const DaemonSetsList: FC<DaemonSetsListProps> = ({ data, loaded, ...props
126126
columns={columns}
127127
getDataViewRows={getDataViewRows}
128128
hideColumnManagement={true}
129+
isResizable
130+
resetAllColumnWidths={resetAllColumnWidths}
129131
/>
130132
</Suspense>
131133
);

frontend/public/components/deployment-config.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,9 @@ export const DeploymentConfigsList: FC<DeploymentConfigsListProps> = ({
306306
loaded,
307307
...props
308308
}) => {
309-
const columns = useWorkloadColumns<DeploymentConfigKind>();
309+
const { columns, resetAllColumnWidths } = useWorkloadColumns<DeploymentConfigKind>(
310+
DeploymentConfigModel,
311+
);
310312

311313
return (
312314
<Suspense fallback={<LoadingBox />}>
@@ -318,6 +320,8 @@ export const DeploymentConfigsList: FC<DeploymentConfigsListProps> = ({
318320
columns={columns}
319321
getDataViewRows={getDataViewRows}
320322
hideColumnManagement={true}
323+
isResizable
324+
resetAllColumnWidths={resetAllColumnWidths}
321325
/>
322326
</Suspense>
323327
);

frontend/public/components/deployment.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ const getDataViewRows: GetDataViewRows<DeploymentKind> = (data, columns) => {
226226
};
227227

228228
export const DeploymentsList: FC<DeploymentsListProps> = ({ data, loaded, ...props }) => {
229-
const columns = useWorkloadColumns<DeploymentKind>();
229+
const { columns, resetAllColumnWidths } = useWorkloadColumns<DeploymentKind>(DeploymentModel);
230230

231231
return (
232232
<Suspense fallback={<LoadingBox />}>
@@ -237,6 +237,8 @@ export const DeploymentsList: FC<DeploymentsListProps> = ({ data, loaded, ...pro
237237
loaded={loaded}
238238
columns={columns}
239239
getDataViewRows={getDataViewRows}
240+
isResizable
241+
resetAllColumnWidths={resetAllColumnWidths}
240242
/>
241243
</Suspense>
242244
);

frontend/public/components/stateful-set.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ const EnvironmentTab: FC<EnvironmentTabProps> = (props) => (
7474
);
7575

7676
const StatefulSetsList: FC<StatefulSetsListProps> = ({ data, loaded, ...props }) => {
77-
const columns = useWorkloadColumns();
77+
const { columns, resetAllColumnWidths } = useWorkloadColumns<K8sResourceKind>(StatefulSetModel);
7878

7979
return (
8080
<Suspense fallback={<LoadingBox />}>
@@ -88,6 +88,8 @@ const StatefulSetsList: FC<StatefulSetsListProps> = ({ data, loaded, ...props })
8888
getWorkloadDataViewRows(dvData, dvColumns, StatefulSetModel)
8989
}
9090
hideColumnManagement={true}
91+
isResizable
92+
resetAllColumnWidths={resetAllColumnWidths}
9193
/>
9294
</Suspense>
9395
);

frontend/public/components/workload-table.tsx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import type { FC } from 'react';
22
import {
33
actionsCellProps,
4-
cellIsStickyProps,
54
getNameCellProps,
5+
nameCellProps,
66
} from '@console/app/src/components/data-view/ConsoleDataView';
77
import {
88
ConsoleDataViewColumn,
99
ConsoleDataViewRow,
1010
} from '@console/app/src/components/data-view/types';
11-
import { K8sModel } from '@console/dynamic-plugin-sdk/src/api/common-types';
11+
import { useColumnWidthSettings } from '@console/app/src/components/data-view/useResizableColumnProps';
12+
import type { K8sModel } from '@console/dynamic-plugin-sdk/src/api/common-types';
1213
import { RowProps, TableColumn } from '@console/dynamic-plugin-sdk/src/extensions/console-types';
1314
import { getGroupVersionKindForModel } from '@console/dynamic-plugin-sdk/src/utils/k8s/k8s-ref';
1415
import LazyActionMenu, {
@@ -159,23 +160,29 @@ export const getWorkloadDataViewRows = <T extends K8sResourceKind>(
159160
});
160161
};
161162

162-
export const useWorkloadColumns = <T extends K8sResourceKind>(): TableColumn<T>[] => {
163+
export const useWorkloadColumns = <T extends K8sResourceKind>(
164+
model: K8sModel,
165+
): { columns: TableColumn<T>[]; resetAllColumnWidths: () => void } => {
163166
const { t } = useTranslation();
167+
const { getResizableProps, resetAllColumnWidths } = useColumnWidthSettings(model);
168+
164169
const columns = useMemo(() => {
165170
return [
166171
{
167172
title: t('public~Name'),
168173
id: tableColumnInfo[0].id,
169174
sort: 'metadata.name',
175+
resizableProps: getResizableProps(tableColumnInfo[0].id),
170176
props: {
171-
...cellIsStickyProps,
177+
...nameCellProps,
172178
modifier: 'nowrap',
173179
},
174180
},
175181
{
176182
title: t('public~Namespace'),
177183
id: tableColumnInfo[1].id,
178184
sort: 'metadata.namespace',
185+
resizableProps: getResizableProps(tableColumnInfo[1].id),
179186
props: {
180187
modifier: 'nowrap',
181188
},
@@ -184,6 +191,7 @@ export const useWorkloadColumns = <T extends K8sResourceKind>(): TableColumn<T>[
184191
title: t('public~Status'),
185192
id: tableColumnInfo[2].id,
186193
sort: 'status.replicas',
194+
resizableProps: getResizableProps(tableColumnInfo[2].id),
187195
props: {
188196
modifier: 'nowrap',
189197
},
@@ -192,30 +200,31 @@ export const useWorkloadColumns = <T extends K8sResourceKind>(): TableColumn<T>[
192200
title: t('public~Labels'),
193201
id: tableColumnInfo[3].id,
194202
sort: 'metadata.labels',
203+
resizableProps: getResizableProps(tableColumnInfo[3].id),
195204
props: {
196205
modifier: 'nowrap',
197-
width: 20,
198206
},
199207
},
200208
{
201209
title: t('public~Pod selector'),
202210
id: tableColumnInfo[4].id,
203211
sort: 'spec.selector',
212+
resizableProps: getResizableProps(tableColumnInfo[4].id),
204213
props: {
205214
modifier: 'nowrap',
206-
width: 20,
207215
},
208216
},
209217
{
210218
title: '',
211219
id: tableColumnInfo[5].id,
212220
props: {
213-
...cellIsStickyProps,
221+
...actionsCellProps,
214222
},
215223
},
216224
];
217-
}, [t]);
218-
return columns;
225+
}, [t, getResizableProps]);
226+
227+
return { columns, resetAllColumnWidths };
219228
};
220229

221230
type ReplicasCountProps = {

0 commit comments

Comments
 (0)