Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

frontend: Fix default sorting column for the ResourceTable #1685

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions frontend/src/components/common/Resource/ResourceTable.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -135,3 +150,9 @@ NameSearch.args = {
resourceTableArgs: podData,
search: 'mypod3',
};

export const WithHiddenCols = TemplateWithFilter.bind({});
WithHiddenCols.args = {
resourceTableArgs: withHiddenCols,
search: '',
};
14 changes: 10 additions & 4 deletions frontend/src/components/common/Resource/ResourceTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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'),
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ exports[`Storyshots Resource/ListView One Hidden Column 1`] = `
>
Age
<button
aria-label="sort swap"
aria-label="sort up"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-hvz71z-MuiButtonBase-root-MuiIconButton-root"
tabindex="0"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,171 @@ exports[`Storyshots ResourceTable No Filter 1`] = `
</div>
</div>
`;

exports[`Storyshots ResourceTable With Hidden Cols 1`] = `
<div>
<div
class="MuiPaper-root MuiPaper-outlined MuiPaper-rounded MuiTableContainer-root makeStyles-tableContainer css-h2cton-MuiPaper-root-MuiTableContainer-root"
>
<table
class="MuiTable-root makeStyles-table makeStyles-table css-vzt8dn-MuiTable-root"
>
<thead
class="MuiTableHead-root css-15wwp11-MuiTableHead-root"
>
<tr
class="MuiTableRow-root MuiTableRow-head css-73w7uv-MuiTableRow-root"
>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-sizeSmall makeStyles-headerCell makeStyles-sortCell css-1ciaiyl-MuiTableCell-root"
scope="col"
>
Name
<button
aria-label="sort swap"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-hvz71z-MuiButtonBase-root-MuiIconButton-root"
tabindex="0"
type="button"
>
<span />
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
</th>
<th
class="MuiTableCell-root MuiTableCell-head MuiTableCell-sizeSmall makeStyles-headerCell makeStyles-sortCell css-1ciaiyl-MuiTableCell-root"
scope="col"
style="text-align: right;"
>
Age
<button
aria-label="sort up"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-hvz71z-MuiButtonBase-root-MuiIconButton-root"
tabindex="0"
type="button"
>
<span />
<span
class="MuiTouchRipple-root css-8je8zh-MuiTouchRipple-root"
/>
</button>
</th>
</tr>
</thead>
<tbody
class="MuiTableBody-root css-apqrd9-MuiTableBody-root"
>
<tr
class="MuiTableRow-root css-73w7uv-MuiTableRow-root"
>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
<a
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
mypod0
</a>
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
style="text-align: right;"
>
<p
aria-label="2021-12-15T14:57:13.000Z"
class="MuiTypography-root MuiTypography-body1 makeStyles-noWrap makeStyles-display css-1ezega9-MuiTypography-root"
data-mui-internal-clone-element="true"
>
3mo
<span />
</p>
</td>
</tr>
<tr
class="MuiTableRow-root css-73w7uv-MuiTableRow-root"
>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
<a
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
mypod1
</a>
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
style="text-align: right;"
>
<p
aria-label="2021-12-15T14:57:13.000Z"
class="MuiTypography-root MuiTypography-body1 makeStyles-noWrap makeStyles-display css-1ezega9-MuiTypography-root"
data-mui-internal-clone-element="true"
>
3mo
<span />
</p>
</td>
</tr>
<tr
class="MuiTableRow-root css-73w7uv-MuiTableRow-root"
>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
<a
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
mypod2
</a>
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
style="text-align: right;"
>
<p
aria-label="2021-12-15T14:57:13.000Z"
class="MuiTypography-root MuiTypography-body1 makeStyles-noWrap makeStyles-display css-1ezega9-MuiTypography-root"
data-mui-internal-clone-element="true"
>
3mo
<span />
</p>
</td>
</tr>
<tr
class="MuiTableRow-root css-73w7uv-MuiTableRow-root"
>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
<a
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
mypod3
</a>
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
style="text-align: right;"
>
<p
aria-label="2021-12-15T14:57:13.000Z"
class="MuiTypography-root MuiTypography-body1 makeStyles-noWrap makeStyles-display css-1ezega9-MuiTypography-root"
data-mui-internal-clone-element="true"
>
3mo
<span />
</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ exports[`Storyshots Namespace/DetailsView Active 1`] = `
>
Age
<button
aria-label="sort swap"
aria-label="sort up"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-hvz71z-MuiButtonBase-root-MuiIconButton-root"
tabindex="0"
type="button"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ exports[`Storyshots node/List Nodes 1`] = `
>
Age
<button
aria-label="sort swap"
aria-label="sort up"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-hvz71z-MuiButtonBase-root-MuiIconButton-root"
tabindex="0"
type="button"
Expand All @@ -186,7 +186,7 @@ exports[`Storyshots node/List Nodes 1`] = `
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
my-linux-node
my-windows-node
</a>
</td>
<td
Expand Down Expand Up @@ -223,7 +223,7 @@ exports[`Storyshots node/List Nodes 1`] = `
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
10.2.3.4
1.2.3.4
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
Expand All @@ -233,14 +233,14 @@ exports[`Storyshots node/List Nodes 1`] = `
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
v1.23.12
v1.26.3
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
style="text-align: right;"
>
<p
aria-label="2023-06-30T11:49:44.000Z"
aria-label="2023-07-13T23:28:40.000Z"
class="MuiTypography-root MuiTypography-body1 makeStyles-noWrap makeStyles-display css-1ezega9-MuiTypography-root"
data-mui-internal-clone-element="true"
>
Expand All @@ -259,7 +259,7 @@ exports[`Storyshots node/List Nodes 1`] = `
class="MuiTypography-root MuiTypography-inherit MuiLink-root MuiLink-underlineHover css-srrjpp-MuiTypography-root-MuiLink-root"
href="/"
>
my-windows-node
my-linux-node
</a>
</td>
<td
Expand Down Expand Up @@ -296,7 +296,7 @@ exports[`Storyshots node/List Nodes 1`] = `
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
1.2.3.4
10.2.3.4
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
Expand All @@ -306,14 +306,14 @@ exports[`Storyshots node/List Nodes 1`] = `
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
>
v1.26.3
v1.23.12
</td>
<td
class="MuiTableCell-root MuiTableCell-body MuiTableCell-sizeSmall css-1k1onho-MuiTableCell-root"
style="text-align: right;"
>
<p
aria-label="2023-07-13T23:28:40.000Z"
aria-label="2023-06-30T11:49:44.000Z"
class="MuiTypography-root MuiTypography-body1 makeStyles-noWrap makeStyles-display css-1ezega9-MuiTypography-root"
data-mui-internal-clone-element="true"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ exports[`Storyshots Pod/PodListView Items 1`] = `
>
Age
<button
aria-label="sort swap"
aria-label="sort up"
class="MuiButtonBase-root MuiIconButton-root MuiIconButton-sizeSmall css-hvz71z-MuiButtonBase-root-MuiIconButton-root"
tabindex="0"
type="button"
Expand Down
Loading
Loading