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

Add support for unsortable columns. #995

Merged
merged 2 commits into from
Dec 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
ColumnOptionKey,
renderBaselineStatus,
renderChromiumUsage,
renderHeaderCell,
CELL_DEFS,
calcColGroupSpans,
renderColgroups,
renderGroupsRow,
Expand Down Expand Up @@ -577,3 +579,37 @@ describe('didFeatureCrash', () => {
assert.isFalse(didFeatureCrash(metadata));
});
});

describe('renderHeaderCell', () => {
let container: HTMLElement;
beforeEach(() => {
container = document.createElement('tr');
});
it('renders a sortable header cell', async () => {
const result = renderHeaderCell(
{search: '/'},
ColumnKey.BaselineStatus,
'',
);
render(result, container);
const el = await fixture(container);
const th = el.querySelector('th');
expect(th).to.exist;
expect(th!.getAttribute('title')).to.equal('Click to sort');
expect(th!.getAttribute('class')).to.equal('sortable');
});
it('renders an unsortable header cell', async () => {
CELL_DEFS[ColumnKey.BaselineStatus].unsortable = true;
const result = renderHeaderCell(
{search: '/'},
ColumnKey.BaselineStatus,
'',
);
render(result, container);
const el = await fixture(container);
const th = el.querySelector('th');
expect(th).to.exist;
expect(th!.getAttribute('title')).to.not.equal('Click to sort');
expect(th!.getAttribute('class')).to.not.equal('sortable');
});
});
15 changes: 10 additions & 5 deletions frontend/src/static/js/components/webstatus-overview-cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type ColumnDefinition = {
group?: string;
headerHtml: TemplateResult;
cellRenderer: CellRenderer;
unsortable?: boolean;
options: {
browser?: components['parameters']['browserPathParam'];
channel?: components['parameters']['channelPathParam'];
Expand Down Expand Up @@ -493,11 +494,15 @@ export function renderHeaderCell(
}

const colDef = CELL_DEFS[column];
return html`
<th title="Click to sort">
<a href=${urlWithSort}> ${sortIndicator} ${colDef?.headerHtml} </a>
</th>
`;
if (colDef.unsortable) {
return html`<th>${colDef?.headerHtml}</th>`;
} else {
return html`
<th title="Click to sort" class="sortable">
<a href=${urlWithSort}> ${sortIndicator} ${colDef?.headerHtml} </a>
</th>
`;
}
}

export function renderFeatureCell(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export class WebstatusOverviewTable extends LitElement {
border-left: var(--default-border);
border-right: var(--default-border);
}
.header-row th:hover {
.header-row th.sortable:hover {
background: var(--table-header-hover-background);
}
.baseline-date-block {
Expand Down
Loading