diff --git a/frontend/src/components/common/Resource/ResourceTable.stories.tsx b/frontend/src/components/common/Resource/ResourceTable.stories.tsx index 7be8db05d7..219a571c8b 100644 --- a/frontend/src/components/common/Resource/ResourceTable.stories.tsx +++ b/frontend/src/components/common/Resource/ResourceTable.stories.tsx @@ -124,6 +124,21 @@ const podData: ResourceTableFromResourceClassProps = { resourceClass: MyPod as KubeObject, }; +const withHiddenCols: ResourceTableFromResourceClassProps = { + columns: [ + 'name', + 'namespace', + { + label: 'UID', + getter: (pod: Pod) => pod.metadata.uid, + show: false, + }, + 'age', + ], + resourceClass: MyPod as KubeObject, + hideColumns: ['namespace'], +}; + export const NoFilter = TemplateWithFilter.bind({}); NoFilter.args = { resourceTableArgs: podData, @@ -135,3 +150,9 @@ NameSearch.args = { resourceTableArgs: podData, search: 'mypod3', }; + +export const WithHiddenCols = TemplateWithFilter.bind({}); +WithHiddenCols.args = { + resourceTableArgs: withHiddenCols, + search: '', +}; diff --git a/frontend/src/components/common/Resource/ResourceTable.tsx b/frontend/src/components/common/Resource/ResourceTable.tsx index 7c74a0eb65..d24b63d8c6 100644 --- a/frontend/src/components/common/Resource/ResourceTable.tsx +++ b/frontend/src/components/common/Resource/ResourceTable.tsx @@ -148,8 +148,10 @@ function Table(props: ResourceTableProps) { }); } + let shouldSortOnAge = false; + const resourceCols: ResourceTableColumnWithDefaultShow[] = processedColumns - .map((col, index) => { + .map(col => { if (typeof col !== 'string') { return col; } @@ -171,9 +173,7 @@ function Table(props: ResourceTableProps) { }, }; case 'age': - if (sortingColumn === undefined) { - sortingColumn = index + 1; - } + shouldSortOnAge = defaultSortingColumn === undefined; return { id: 'age', label: t('translation|Age'), @@ -240,6 +240,12 @@ function Table(props: ResourceTableProps) { // Filter out columns that have show set to false. const cols = resourceCols.filter(col => col.show !== false); + + if (shouldSortOnAge) { + // Sorting column on SimpleTable starts at 1. + sortingColumn = cols.findIndex(col => col.id === 'age') + 1; + } + return [resourceCols, cols, sortingColumn]; }, [ columns, diff --git a/frontend/src/components/common/Resource/__snapshots__/ResourceListView.stories.storyshot b/frontend/src/components/common/Resource/__snapshots__/ResourceListView.stories.storyshot index 6930025a83..2c0034aaea 100644 --- a/frontend/src/components/common/Resource/__snapshots__/ResourceListView.stories.storyshot +++ b/frontend/src/components/common/Resource/__snapshots__/ResourceListView.stories.storyshot @@ -132,7 +132,7 @@ exports[`Storyshots Resource/ListView One Hidden Column 1`] = ` > Age