2022-09-14 22:05:21 +00:00
|
|
|
import { EVENT_REFRESH } from "@goauthentik/common/constants";
|
|
|
|
import { groupBy } from "@goauthentik/common/utils";
|
|
|
|
import { AKElement } from "@goauthentik/elements/Base";
|
|
|
|
import "@goauthentik/elements/EmptyState";
|
|
|
|
import "@goauthentik/elements/buttons/SpinnerButton";
|
|
|
|
import "@goauthentik/elements/chips/Chip";
|
|
|
|
import "@goauthentik/elements/chips/ChipGroup";
|
|
|
|
import { getURLParam, updateURLParams } from "@goauthentik/elements/router/RouteMatch";
|
|
|
|
import "@goauthentik/elements/table/TablePagination";
|
|
|
|
import { Pagination } from "@goauthentik/elements/table/TablePagination";
|
|
|
|
import "@goauthentik/elements/table/TableSearch";
|
2022-06-25 15:44:17 +00:00
|
|
|
|
2021-04-03 17:26:43 +00:00
|
|
|
import { t } from "@lingui/macro";
|
2021-09-21 09:31:37 +00:00
|
|
|
|
2022-12-22 16:31:06 +00:00
|
|
|
import { CSSResult, TemplateResult, css, html } from "lit";
|
2022-06-04 22:46:25 +00:00
|
|
|
import { property, state } from "lit/decorators.js";
|
2021-11-04 21:34:48 +00:00
|
|
|
import { ifDefined } from "lit/directives/if-defined.js";
|
2021-03-17 16:11:39 +00:00
|
|
|
|
2022-09-14 22:05:21 +00:00
|
|
|
import AKGlobal from "@goauthentik/common/styles/authentik.css";
|
2021-03-17 16:11:39 +00:00
|
|
|
import PFButton from "@patternfly/patternfly/components/Button/button.css";
|
|
|
|
import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css";
|
|
|
|
import PFPagination from "@patternfly/patternfly/components/Pagination/pagination.css";
|
2023-01-19 14:47:07 +00:00
|
|
|
import PFSwitch from "@patternfly/patternfly/components/Switch/switch.css";
|
2021-09-21 09:31:37 +00:00
|
|
|
import PFTable from "@patternfly/patternfly/components/Table/table.css";
|
|
|
|
import PFToolbar from "@patternfly/patternfly/components/Toolbar/toolbar.css";
|
|
|
|
import PFBullseye from "@patternfly/patternfly/layouts/Bullseye/bullseye.css";
|
|
|
|
import PFBase from "@patternfly/patternfly/patternfly-base.css";
|
2020-11-29 21:14:48 +00:00
|
|
|
|
2020-12-24 08:56:05 +00:00
|
|
|
export class TableColumn {
|
|
|
|
title: string;
|
|
|
|
orderBy?: string;
|
|
|
|
|
|
|
|
onClick?: () => void;
|
|
|
|
|
|
|
|
constructor(title: string, orderBy?: string) {
|
|
|
|
this.title = title;
|
|
|
|
this.orderBy = orderBy;
|
|
|
|
}
|
|
|
|
|
|
|
|
headerClickHandler(table: Table<unknown>): void {
|
|
|
|
if (!this.orderBy) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (table.order === this.orderBy) {
|
|
|
|
table.order = `-${this.orderBy}`;
|
|
|
|
} else {
|
|
|
|
table.order = this.orderBy;
|
|
|
|
}
|
|
|
|
table.fetch();
|
|
|
|
}
|
|
|
|
|
|
|
|
private getSortIndicator(table: Table<unknown>): string {
|
|
|
|
switch (table.order) {
|
2021-08-03 15:52:21 +00:00
|
|
|
case this.orderBy:
|
|
|
|
return "fa-long-arrow-alt-down";
|
|
|
|
case `-${this.orderBy}`:
|
|
|
|
return "fa-long-arrow-alt-up";
|
|
|
|
default:
|
|
|
|
return "fa-arrows-alt-v";
|
2020-12-24 08:56:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderSortable(table: Table<unknown>): TemplateResult {
|
2021-08-03 15:52:21 +00:00
|
|
|
return html` <button
|
|
|
|
class="pf-c-table__button"
|
|
|
|
@click=${() => this.headerClickHandler(table)}
|
|
|
|
>
|
|
|
|
<div class="pf-c-table__button-content">
|
|
|
|
<span class="pf-c-table__text">${this.title}</span>
|
|
|
|
<span class="pf-c-table__sort-indicator">
|
|
|
|
<i class="fas ${this.getSortIndicator(table)}"></i>
|
|
|
|
</span>
|
|
|
|
</div>
|
|
|
|
</button>`;
|
2020-12-24 08:56:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render(table: Table<unknown>): TemplateResult {
|
|
|
|
return html`<th
|
|
|
|
role="columnheader"
|
|
|
|
scope="col"
|
|
|
|
class="
|
|
|
|
${this.orderBy ? "pf-c-table__sort " : " "}
|
2021-08-03 15:52:21 +00:00
|
|
|
${table.order === this.orderBy || table.order === `-${this.orderBy}`
|
|
|
|
? "pf-m-selected "
|
|
|
|
: ""}
|
|
|
|
"
|
|
|
|
>
|
2021-04-03 17:26:43 +00:00
|
|
|
${this.orderBy ? this.renderSortable(table) : html`${this.title}`}
|
2020-12-24 08:56:05 +00:00
|
|
|
</th>`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 22:05:21 +00:00
|
|
|
export interface PaginatedResponse<T> {
|
|
|
|
pagination: Pagination;
|
|
|
|
|
|
|
|
results: Array<T>;
|
|
|
|
}
|
|
|
|
|
|
|
|
export abstract class Table<T> extends AKElement {
|
|
|
|
abstract apiEndpoint(page: number): Promise<PaginatedResponse<T>>;
|
2020-12-24 08:56:05 +00:00
|
|
|
abstract columns(): TableColumn[];
|
|
|
|
abstract row(item: T): TemplateResult[];
|
2020-12-12 18:39:09 +00:00
|
|
|
|
2021-02-03 20:18:31 +00:00
|
|
|
private isLoading = false;
|
|
|
|
|
2021-04-10 18:13:11 +00:00
|
|
|
searchEnabled(): boolean {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-12-12 18:39:09 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
renderExpanded(item: T): TemplateResult {
|
|
|
|
if (this.expandable) {
|
|
|
|
throw new Error("Expandable is enabled but renderExpanded is not overridden!");
|
|
|
|
}
|
|
|
|
return html``;
|
|
|
|
}
|
2020-11-29 21:14:48 +00:00
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ attribute: false })
|
2022-09-14 22:05:21 +00:00
|
|
|
data?: PaginatedResponse<T>;
|
2020-11-29 21:14:48 +00:00
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ type: Number })
|
2023-01-30 11:01:40 +00:00
|
|
|
page = getURLParam("tablePage", 1);
|
2020-11-29 21:14:48 +00:00
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ type: String })
|
2020-12-24 08:56:05 +00:00
|
|
|
order?: string;
|
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ type: String })
|
2021-11-26 11:04:46 +00:00
|
|
|
search: string = getURLParam("search", "");
|
2020-12-24 08:56:05 +00:00
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ type: Boolean })
|
2021-03-08 20:51:42 +00:00
|
|
|
checkbox = false;
|
|
|
|
|
2023-02-02 21:37:59 +00:00
|
|
|
@property({ type: Boolean })
|
|
|
|
radioSelect = false;
|
|
|
|
|
2021-08-05 08:15:31 +00:00
|
|
|
@property({ type: Boolean })
|
|
|
|
checkboxChip = false;
|
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ attribute: false })
|
2021-03-08 20:51:42 +00:00
|
|
|
selectedElements: T[] = [];
|
|
|
|
|
2021-08-12 19:14:51 +00:00
|
|
|
@property({ type: Boolean })
|
|
|
|
paginated = true;
|
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ type: Boolean })
|
2020-12-12 18:39:09 +00:00
|
|
|
expandable = false;
|
|
|
|
|
2021-08-03 15:52:21 +00:00
|
|
|
@property({ attribute: false })
|
2021-08-07 18:06:17 +00:00
|
|
|
expandedElements: T[] = [];
|
2020-12-12 18:39:09 +00:00
|
|
|
|
2022-06-04 22:46:25 +00:00
|
|
|
@state()
|
|
|
|
hasError?: Error;
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
static get styles(): CSSResult[] {
|
2021-08-03 15:52:21 +00:00
|
|
|
return [
|
|
|
|
PFBase,
|
|
|
|
PFTable,
|
|
|
|
PFBullseye,
|
|
|
|
PFButton,
|
2023-01-19 14:47:07 +00:00
|
|
|
PFSwitch,
|
2021-08-03 15:52:21 +00:00
|
|
|
PFToolbar,
|
|
|
|
PFDropdown,
|
|
|
|
PFPagination,
|
|
|
|
AKGlobal,
|
2022-12-22 16:31:06 +00:00
|
|
|
css`
|
2022-12-25 13:10:02 +00:00
|
|
|
.pf-c-table thead .pf-c-table__check {
|
|
|
|
min-width: 3rem;
|
|
|
|
}
|
2022-12-22 16:31:06 +00:00
|
|
|
.pf-c-table tbody .pf-c-table__check input {
|
|
|
|
margin-top: calc(var(--pf-c-table__check--input--MarginTop) + 1px);
|
|
|
|
}
|
|
|
|
`,
|
2021-08-03 15:52:21 +00:00
|
|
|
];
|
2020-11-29 21:14:48 +00:00
|
|
|
}
|
|
|
|
|
2020-12-05 21:08:42 +00:00
|
|
|
constructor() {
|
|
|
|
super();
|
2021-03-23 14:16:56 +00:00
|
|
|
this.addEventListener(EVENT_REFRESH, () => {
|
2020-12-05 21:08:42 +00:00
|
|
|
this.fetch();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-10-11 15:51:49 +00:00
|
|
|
public groupBy(items: T[]): [string, T[]][] {
|
|
|
|
return groupBy(items, () => {
|
|
|
|
return "";
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2021-12-02 18:34:17 +00:00
|
|
|
public async fetch(): Promise<void> {
|
2021-02-03 20:18:31 +00:00
|
|
|
if (this.isLoading) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.isLoading = true;
|
2022-05-23 18:07:56 +00:00
|
|
|
try {
|
|
|
|
this.data = await this.apiEndpoint(this.page);
|
2022-06-04 22:46:25 +00:00
|
|
|
this.hasError = undefined;
|
2022-05-23 18:07:56 +00:00
|
|
|
this.page = this.data.pagination.current;
|
|
|
|
const newSelected: T[] = [];
|
|
|
|
const newExpanded: T[] = [];
|
|
|
|
this.data.results.forEach((res) => {
|
|
|
|
const jsonRes = JSON.stringify(res);
|
|
|
|
// So because we're dealing with complex objects here, we can't use indexOf
|
|
|
|
// since it checks strict equality, and we also can't easily check in findIndex()
|
|
|
|
// Instead we default to comparing the JSON of both objects, which is quite slow
|
|
|
|
// Hence we check if the objects have `pk` attributes set (as most models do)
|
|
|
|
// and compare that instead, which will be much faster.
|
|
|
|
let comp = (item: T) => {
|
|
|
|
return JSON.stringify(item) === jsonRes;
|
|
|
|
};
|
2023-01-01 22:32:05 +00:00
|
|
|
if (Object.hasOwn(res as object, "pk")) {
|
2022-05-23 18:07:56 +00:00
|
|
|
comp = (item: T) => {
|
|
|
|
return (
|
|
|
|
(item as unknown as { pk: string | number }).pk ===
|
|
|
|
(res as unknown as { pk: string | number }).pk
|
|
|
|
);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectedIndex = this.selectedElements.findIndex(comp);
|
|
|
|
if (selectedIndex > -1) {
|
|
|
|
newSelected.push(res);
|
|
|
|
}
|
|
|
|
const expandedIndex = this.expandedElements.findIndex(comp);
|
|
|
|
if (expandedIndex > -1) {
|
|
|
|
newExpanded.push(res);
|
|
|
|
}
|
2021-08-03 15:52:21 +00:00
|
|
|
});
|
2022-05-23 18:07:56 +00:00
|
|
|
this.isLoading = false;
|
|
|
|
this.selectedElements = newSelected;
|
|
|
|
this.expandedElements = newExpanded;
|
2022-06-04 22:46:25 +00:00
|
|
|
} catch (ex) {
|
2022-05-23 18:07:56 +00:00
|
|
|
this.isLoading = false;
|
2022-06-04 22:46:25 +00:00
|
|
|
this.hasError = ex as Error;
|
2022-05-23 18:07:56 +00:00
|
|
|
}
|
2020-11-29 21:14:48 +00:00
|
|
|
}
|
|
|
|
|
2020-11-30 11:33:09 +00:00
|
|
|
private renderLoading(): TemplateResult {
|
|
|
|
return html`<tr role="row">
|
|
|
|
<td role="cell" colspan="25">
|
|
|
|
<div class="pf-l-bullseye">
|
2021-08-03 15:52:21 +00:00
|
|
|
<ak-empty-state ?loading="${true}" header=${t`Loading`}> </ak-empty-state>
|
2020-11-30 11:33:09 +00:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>`;
|
|
|
|
}
|
|
|
|
|
2020-12-12 18:39:09 +00:00
|
|
|
renderEmpty(inner?: TemplateResult): TemplateResult {
|
|
|
|
return html`<tbody role="rowgroup">
|
|
|
|
<tr role="row">
|
|
|
|
<td role="cell" colspan="8">
|
|
|
|
<div class="pf-l-bullseye">
|
2021-08-03 15:52:21 +00:00
|
|
|
${inner
|
|
|
|
? inner
|
|
|
|
: html`<ak-empty-state
|
|
|
|
header="${t`No objects found.`}"
|
|
|
|
></ak-empty-state>`}
|
2020-12-12 18:39:09 +00:00
|
|
|
</div>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>`;
|
|
|
|
}
|
|
|
|
|
2022-06-04 22:46:25 +00:00
|
|
|
renderError(): TemplateResult {
|
|
|
|
return html`<ak-empty-state header="${t`Failed to fetch objects.`}" icon="fa-times">
|
|
|
|
<div slot="body">${this.hasError?.toString()}</div>
|
|
|
|
</ak-empty-state>`;
|
|
|
|
}
|
|
|
|
|
2020-11-29 21:14:48 +00:00
|
|
|
private renderRows(): TemplateResult[] | undefined {
|
2022-06-04 22:46:25 +00:00
|
|
|
if (this.hasError) {
|
|
|
|
return [this.renderEmpty(this.renderError())];
|
|
|
|
}
|
2020-11-29 21:14:48 +00:00
|
|
|
if (!this.data) {
|
|
|
|
return;
|
|
|
|
}
|
2020-12-12 18:39:09 +00:00
|
|
|
if (this.data.pagination.count === 0) {
|
|
|
|
return [this.renderEmpty()];
|
|
|
|
}
|
2021-10-11 15:51:49 +00:00
|
|
|
const groupedResults = this.groupBy(this.data.results);
|
|
|
|
if (groupedResults.length === 1) {
|
|
|
|
return this.renderRowGroup(groupedResults[0][1]);
|
|
|
|
}
|
|
|
|
return groupedResults.map(([group, items]) => {
|
|
|
|
return html`<thead>
|
|
|
|
<tr role="row">
|
|
|
|
<th role="columnheader" scope="row" colspan="200">${group}</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
${this.renderRowGroup(items)}`;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
private renderRowGroup(items: T[]): TemplateResult[] {
|
|
|
|
return items.map((item) => {
|
2023-02-06 10:37:40 +00:00
|
|
|
const itemSelectHandler = (ev?: InputEvent | PointerEvent) => {
|
2023-02-02 21:37:59 +00:00
|
|
|
let checked = false;
|
2023-02-06 15:47:46 +00:00
|
|
|
if (ev instanceof InputEvent) {
|
|
|
|
checked = (ev.target as HTMLInputElement).checked;
|
|
|
|
} else if (ev instanceof PointerEvent) {
|
2023-02-02 21:37:59 +00:00
|
|
|
checked = this.selectedElements.indexOf(item) === -1;
|
|
|
|
}
|
|
|
|
if (checked) {
|
|
|
|
// Prevent double-adding the element to selected items
|
|
|
|
if (this.selectedElements.indexOf(item) !== -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Add item to selected
|
|
|
|
this.selectedElements.push(item);
|
|
|
|
} else {
|
|
|
|
// Get index of item and remove if selected
|
|
|
|
const index = this.selectedElements.indexOf(item);
|
|
|
|
if (index <= -1) return;
|
|
|
|
this.selectedElements.splice(index, 1);
|
|
|
|
}
|
|
|
|
this.requestUpdate();
|
|
|
|
// Unset select-all if selectedElements is empty
|
|
|
|
const selectAllCheckbox =
|
|
|
|
this.shadowRoot?.querySelector<HTMLInputElement>("[name=select-all]");
|
|
|
|
if (!selectAllCheckbox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (this.selectedElements.length < 1) {
|
|
|
|
selectAllCheckbox.checked = false;
|
|
|
|
this.requestUpdate();
|
|
|
|
}
|
|
|
|
};
|
2021-08-03 15:52:21 +00:00
|
|
|
return html`<tbody
|
|
|
|
role="rowgroup"
|
2021-08-07 18:06:17 +00:00
|
|
|
class="${this.expandedElements.indexOf(item) > -1 ? "pf-m-expanded" : ""}"
|
2021-08-03 15:52:21 +00:00
|
|
|
>
|
2023-02-02 21:37:59 +00:00
|
|
|
<tr
|
|
|
|
role="row"
|
|
|
|
class="${this.checkbox ? "pf-m-hoverable" : ""}"
|
2023-02-06 10:37:40 +00:00
|
|
|
@click=${itemSelectHandler}
|
2023-02-02 21:37:59 +00:00
|
|
|
>
|
2021-08-03 15:52:21 +00:00
|
|
|
${this.checkbox
|
|
|
|
? html`<td class="pf-c-table__check" role="cell">
|
2022-12-22 14:12:47 +00:00
|
|
|
<label
|
|
|
|
><input
|
|
|
|
type="checkbox"
|
|
|
|
.checked=${this.selectedElements.indexOf(item) >= 0}
|
2023-02-02 21:37:59 +00:00
|
|
|
@input=${itemSelectHandler}
|
2022-12-22 14:12:47 +00:00
|
|
|
/></label>
|
2021-08-03 15:52:21 +00:00
|
|
|
</td>`
|
|
|
|
: html``}
|
|
|
|
${this.expandable
|
|
|
|
? html`<td class="pf-c-table__toggle" role="cell">
|
|
|
|
<button
|
2021-08-07 18:06:17 +00:00
|
|
|
class="pf-c-button pf-m-plain ${this.expandedElements.indexOf(
|
|
|
|
item,
|
|
|
|
) > -1
|
2021-08-03 15:52:21 +00:00
|
|
|
? "pf-m-expanded"
|
|
|
|
: ""}"
|
|
|
|
@click=${() => {
|
2021-08-07 18:06:17 +00:00
|
|
|
const idx = this.expandedElements.indexOf(item);
|
|
|
|
if (idx <= -1) {
|
|
|
|
// Element is not expanded, add it
|
|
|
|
this.expandedElements.push(item);
|
|
|
|
} else {
|
|
|
|
// Element is expanded, remove it
|
|
|
|
this.expandedElements.splice(idx, 1);
|
|
|
|
}
|
2021-08-03 15:52:21 +00:00
|
|
|
this.requestUpdate();
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<div class="pf-c-table__toggle-icon">
|
|
|
|
<i class="fas fa-angle-down" aria-hidden="true"></i
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</td>`
|
|
|
|
: html``}
|
2020-12-12 18:39:09 +00:00
|
|
|
${this.row(item).map((col) => {
|
2021-02-03 20:18:31 +00:00
|
|
|
return html`<td role="cell">${col}</td>`;
|
|
|
|
})}
|
2020-12-12 18:39:09 +00:00
|
|
|
</tr>
|
2021-08-03 15:52:21 +00:00
|
|
|
<tr
|
2021-08-07 18:06:17 +00:00
|
|
|
class="pf-c-table__expandable-row ${this.expandedElements.indexOf(item) > -1
|
2021-08-03 15:52:21 +00:00
|
|
|
? "pf-m-expanded"
|
|
|
|
: ""}"
|
|
|
|
role="row"
|
|
|
|
>
|
2020-12-12 18:39:09 +00:00
|
|
|
<td></td>
|
2021-08-07 18:06:17 +00:00
|
|
|
${this.expandedElements.indexOf(item) > -1 ? this.renderExpanded(item) : html``}
|
2020-12-12 18:39:09 +00:00
|
|
|
</tr>
|
|
|
|
</tbody>`;
|
2020-11-29 21:14:48 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-12 18:39:09 +00:00
|
|
|
renderToolbar(): TemplateResult {
|
2021-12-02 18:34:17 +00:00
|
|
|
return html` <ak-spinner-button
|
|
|
|
.callAction=${() => {
|
|
|
|
return this.fetch();
|
2021-07-05 07:48:14 +00:00
|
|
|
}}
|
2021-12-02 18:34:17 +00:00
|
|
|
class="pf-m-secondary"
|
2021-08-03 15:52:21 +00:00
|
|
|
>
|
2021-12-02 18:34:17 +00:00
|
|
|
${t`Refresh`}</ak-spinner-button
|
|
|
|
>`;
|
2021-02-03 20:18:31 +00:00
|
|
|
}
|
|
|
|
|
2021-08-05 08:40:44 +00:00
|
|
|
renderToolbarSelected(): TemplateResult {
|
|
|
|
return html``;
|
|
|
|
}
|
|
|
|
|
2021-02-03 20:18:31 +00:00
|
|
|
renderToolbarAfter(): TemplateResult {
|
|
|
|
return html``;
|
2020-12-12 18:39:09 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 08:56:05 +00:00
|
|
|
renderSearch(): TemplateResult {
|
2021-04-10 18:13:11 +00:00
|
|
|
if (!this.searchEnabled()) {
|
|
|
|
return html``;
|
|
|
|
}
|
2021-08-03 15:52:21 +00:00
|
|
|
return html`<ak-table-search
|
2021-12-18 16:34:28 +00:00
|
|
|
class="pf-c-toolbar__item pf-m-search-filter"
|
2021-08-05 10:30:43 +00:00
|
|
|
value=${ifDefined(this.search)}
|
|
|
|
.onSearch=${(value: string) => {
|
|
|
|
this.search = value;
|
2021-12-02 18:34:17 +00:00
|
|
|
this.fetch();
|
2021-11-18 20:01:58 +00:00
|
|
|
updateURLParams({
|
|
|
|
search: value,
|
|
|
|
});
|
2021-08-05 10:30:43 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
</ak-table-search>`;
|
2021-04-10 18:13:11 +00:00
|
|
|
}
|
|
|
|
|
2021-04-10 18:19:23 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2021-04-10 18:13:11 +00:00
|
|
|
renderSelectedChip(item: T): TemplateResult {
|
2020-12-24 08:56:05 +00:00
|
|
|
return html``;
|
|
|
|
}
|
|
|
|
|
2021-08-12 19:14:51 +00:00
|
|
|
renderToolbarContainer(): TemplateResult {
|
|
|
|
return html`<div class="pf-c-toolbar">
|
|
|
|
<div class="pf-c-toolbar__content">
|
2021-12-18 16:34:28 +00:00
|
|
|
<div class="pf-c-toolbar__group pf-m-search-filter">${this.renderSearch()}</div>
|
2021-08-12 19:14:51 +00:00
|
|
|
<div class="pf-c-toolbar__bulk-select">${this.renderToolbar()}</div>
|
|
|
|
<div class="pf-c-toolbar__group">${this.renderToolbarAfter()}</div>
|
|
|
|
<div class="pf-c-toolbar__group">${this.renderToolbarSelected()}</div>
|
|
|
|
${this.paginated
|
|
|
|
? html`<ak-table-pagination
|
|
|
|
class="pf-c-toolbar__item pf-m-pagination"
|
|
|
|
.pages=${this.data?.pagination}
|
|
|
|
.pageChangeHandler=${(page: number) => {
|
|
|
|
this.page = page;
|
2023-01-30 11:01:40 +00:00
|
|
|
updateURLParams({ tablePage: page });
|
2021-12-02 18:34:17 +00:00
|
|
|
this.fetch();
|
2021-08-12 19:14:51 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
</ak-table-pagination>`
|
|
|
|
: html``}
|
|
|
|
</div>
|
|
|
|
</div>`;
|
|
|
|
}
|
|
|
|
|
2021-02-03 20:18:31 +00:00
|
|
|
firstUpdated(): void {
|
|
|
|
this.fetch();
|
|
|
|
}
|
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
renderTable(): TemplateResult {
|
2021-08-05 08:15:31 +00:00
|
|
|
return html` ${this.checkbox && this.checkboxChip
|
2021-08-03 15:52:21 +00:00
|
|
|
? html`<ak-chip-group>
|
|
|
|
${this.selectedElements.map((el) => {
|
|
|
|
return html`<ak-chip>${this.renderSelectedChip(el)}</ak-chip>`;
|
|
|
|
})}
|
|
|
|
</ak-chip-group>`
|
|
|
|
: html``}
|
2021-08-12 19:14:51 +00:00
|
|
|
${this.renderToolbarContainer()}
|
2020-12-12 18:39:09 +00:00
|
|
|
<table class="pf-c-table pf-m-compact pf-m-grid-md pf-m-expandable">
|
2020-11-29 21:14:48 +00:00
|
|
|
<thead>
|
|
|
|
<tr role="row">
|
2021-08-03 15:52:21 +00:00
|
|
|
${this.checkbox
|
|
|
|
? html`<td class="pf-c-table__check" role="cell">
|
|
|
|
<input
|
2021-08-14 19:38:05 +00:00
|
|
|
name="select-all"
|
2021-08-03 15:52:21 +00:00
|
|
|
type="checkbox"
|
|
|
|
aria-label=${t`Select all rows`}
|
2022-12-22 15:02:04 +00:00
|
|
|
.checked=${this.selectedElements.length ===
|
2022-12-25 13:10:02 +00:00
|
|
|
this.data?.results.length &&
|
|
|
|
this.selectedElements.length > 0}
|
2021-08-03 15:52:21 +00:00
|
|
|
@input=${(ev: InputEvent) => {
|
|
|
|
if ((ev.target as HTMLInputElement).checked) {
|
2021-08-14 19:34:04 +00:00
|
|
|
this.selectedElements =
|
|
|
|
this.data?.results.slice(0) || [];
|
2021-08-03 15:52:21 +00:00
|
|
|
} else {
|
|
|
|
this.selectedElements = [];
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</td>`
|
|
|
|
: html``}
|
2021-03-08 20:51:42 +00:00
|
|
|
${this.expandable ? html`<td role="cell"></td>` : html``}
|
2020-12-24 08:56:05 +00:00
|
|
|
${this.columns().map((col) => col.render(this))}
|
2020-11-29 21:14:48 +00:00
|
|
|
</tr>
|
|
|
|
</thead>
|
2021-08-03 15:52:21 +00:00
|
|
|
${this.isLoading || !this.data ? this.renderLoading() : this.renderRows()}
|
2020-11-29 21:14:48 +00:00
|
|
|
</table>
|
2021-08-12 19:14:51 +00:00
|
|
|
${this.paginated
|
|
|
|
? html` <div class="pf-c-pagination pf-m-bottom">
|
|
|
|
<ak-table-pagination
|
|
|
|
class="pf-c-toolbar__item pf-m-pagination"
|
|
|
|
.pages=${this.data?.pagination}
|
|
|
|
.pageChangeHandler=${(page: number) => {
|
|
|
|
this.page = page;
|
2021-12-02 18:34:17 +00:00
|
|
|
this.fetch();
|
2021-08-12 19:14:51 +00:00
|
|
|
}}
|
|
|
|
>
|
|
|
|
</ak-table-pagination>
|
|
|
|
</div>`
|
|
|
|
: html``}`;
|
2020-11-29 21:14:48 +00:00
|
|
|
}
|
2020-11-30 22:49:33 +00:00
|
|
|
|
2020-12-01 16:27:19 +00:00
|
|
|
render(): TemplateResult {
|
2020-11-30 22:49:33 +00:00
|
|
|
return this.renderTable();
|
|
|
|
}
|
2020-11-29 21:14:48 +00:00
|
|
|
}
|