import { html, LitElement, property, TemplateResult } from "lit-element"; import { until } from "lit-html/directives/until.js"; import { PBResponse } from "../../api/client"; import { COMMON_STYLES } from "../../common/styles"; export abstract class Table extends LitElement { abstract apiEndpoint(page: number): Promise; abstract columns(): Array; abstract row(item: any): Array; @property() data?: PBResponse; @property() page: number = 1; static get styles() { return [COMMON_STYLES]; } public fetch() { this.apiEndpoint(this.page).then((r) => { this.data = r; this.page = r.pagination.current; }); } private renderRows(): TemplateResult[] | undefined { if (!this.data) { return; } return this.data.results.map((item) => { const fullRow = [``].concat( this.row(item).map((col) => { return `${col}`; }) ); fullRow.push(``); return html(fullRow); }); } render() { if (!this.data) { this.fetch(); return; } return html` { this.fetch(); }} class="pf-c-button pf-m-primary" > Refresh ${this.columns().map( (col) => html`${col}` )} ${this.renderRows()} `; } }