From 16f8f40df7d0540b498dd1ffe727c34b7a1b5dda Mon Sep 17 00:00:00 2001 From: Arnaud Meukam Date: Wed, 27 Nov 2024 02:05:35 +0100 Subject: [PATCH] Fix linting issues Fix some linting issues and improve readability of the codebase Signed-off-by: Arnaud Meukam --- web/src/tab-summary.ts | 36 +++-- web/src/testgrid-app.ts | 10 +- web/src/testgrid-dashboard-summary.ts | 2 +- web/src/testgrid-data-content.ts | 60 ++++---- web/src/testgrid-failures-summary.ts | 4 +- web/src/testgrid-grid-cell.ts | 1 + web/src/testgrid-grid.ts | 30 ++-- web/src/testgrid-group-summary.ts | 77 +++++----- web/src/testgrid-healthiness-summary.ts | 72 +++++---- web/src/testgrid-index.ts | 141 ++++++++++-------- web/src/testgrid-router.ts | 34 +++-- web/src/utils/navigation.ts | 18 +-- web/stories/tab-summary.stories.ts | 46 +++--- web/stories/testgrid-grid-cell.stories.ts | 54 ++++--- .../testgrid-grid-column-header.stories.ts | 15 +- web/stories/testgrid-grid-row-name.stories.ts | 10 +- web/stories/testgrid-grid.stories.ts | 12 +- web/stories/testgrid-group-summary.stories.ts | 8 +- web/test/testgrid-data-content.test.ts | 2 +- web/test/testgrid-grid-cell.test.ts | 76 +++++----- web/test/testgrid-grid.test.ts | 16 +- web/test/testgrid-index.test.ts | 57 +++---- 22 files changed, 443 insertions(+), 338 deletions(-) diff --git a/web/src/tab-summary.ts b/web/src/tab-summary.ts index 1ac70e2..981e370 100644 --- a/web/src/tab-summary.ts +++ b/web/src/tab-summary.ts @@ -44,30 +44,36 @@ export class TabSummary extends LitElement { - ${this.info?.failuresSummary !== undefined ? - html ` - `:''} - ${this.info?.healthinessSummary !== undefined ? - html ` - `:''} + ${this.info?.failuresSummary !== undefined + ? html` + ` + : ''} + ${this.info?.healthinessSummary !== undefined + ? html` + ` + : ''} `; } + /** * Lets the data content element know that the tab changed * * @fires tab-changed * @param tabName string */ - private changeTab(){ - window.dispatchEvent(new CustomEvent('tab-changed',{ - detail: { - tabName: this.info?.name! - }, - })) + private changeTab() { + window.dispatchEvent( + new CustomEvent('tab-changed', { + detail: { + tabName: this.info?.name!, + }, + }) + ); } static styles = css` - .tab-name { // title/link in each Summary card + .tab-name { + // title/link in each Summary card cursor: pointer; position: relative; padding: 4px 8px; @@ -86,7 +92,8 @@ export class TabSummary extends LitElement { align-items: center; } - .tab-name { // title/link in each Summary card + .tab-name { + // title/link in each Summary card cursor: pointer; position: relative; padding: 4px 8px; @@ -136,5 +143,4 @@ export class TabSummary extends LitElement { background-color: #000; } `; - } diff --git a/web/src/testgrid-app.ts b/web/src/testgrid-app.ts index 6daed01..42f7466 100644 --- a/web/src/testgrid-app.ts +++ b/web/src/testgrid-app.ts @@ -1,18 +1,18 @@ -import { LitElement, html } from "lit"; -import { customElement } from "lit/decorators.js"; -import './testgrid-router' +import { LitElement, html } from 'lit'; +import { customElement } from 'lit/decorators.js'; +import './testgrid-router'; /** * Class definition for the `testgrid-app` element. * Application root element. */ @customElement('testgrid-app') -export class TestgridApp extends LitElement{ +export class TestgridApp extends LitElement { /** * Lit-element lifecycle method. * Invoked on each update to perform rendering tasks. */ - render(){ + render() { return html``; } } diff --git a/web/src/testgrid-dashboard-summary.ts b/web/src/testgrid-dashboard-summary.ts index 19e2bcd..3353856 100644 --- a/web/src/testgrid-dashboard-summary.ts +++ b/web/src/testgrid-dashboard-summary.ts @@ -162,7 +162,7 @@ export class TestgridDashboardSummary extends LitElement { throw new Error(`HTTP error: ${response.status}`); } const data = ListTabSummariesResponse.fromJson(await response.json()); - var tabSummaries: Array = []; + const tabSummaries: Array = []; data.tabSummaries.forEach(ts => { const si = convertResponse(ts); tabSummaries.push(si); diff --git a/web/src/testgrid-data-content.ts b/web/src/testgrid-data-content.ts index 2f0f2ba..c5c72a0 100644 --- a/web/src/testgrid-data-content.ts +++ b/web/src/testgrid-data-content.ts @@ -17,7 +17,6 @@ import './testgrid-grid'; @customElement('testgrid-data-content') // eslint-disable-next-line @typescript-eslint/no-unused-vars export class TestgridDataContent extends LitElement { - @state() tabNames: string[] = []; @@ -34,20 +33,20 @@ export class TestgridDataContent extends LitElement { tabName?: string; // set the functionality when any tab is clicked on - private onTabActivated(event: CustomEvent<{index: number}>) { + private onTabActivated(event: CustomEvent<{ index: number }>) { const tabIndex = event.detail.index; - if (tabIndex === this.activeIndex){ - return + if (tabIndex === this.activeIndex) { + return; } this.tabName = this.tabNames[tabIndex]; - if (this.activeIndex === 0 || tabIndex === 0){ + if (this.activeIndex === 0 || tabIndex === 0) { this.showTab = !this.showTab; } this.activeIndex = tabIndex; - navigateTab(this.dashboardName, this.tabName) + navigateTab(this.dashboardName, this.tabName); } /** @@ -64,15 +63,15 @@ export class TestgridDataContent extends LitElement { navigateTab(this.dashboardName, this.tabName!); }); window.addEventListener('popstate', () => { - console.log(location.pathname); - console.log(location.pathname.split('/')); - if (location.pathname.split('/').length === 2){ + console.log(window.location.pathname); + console.log(window.location.pathname.split('/')); + if (location.pathname.split('/').length === 2) { this.showTab = false; this.tabName = undefined; this.highlightIndex(this.tabName); navigateTab(this.dashboardName, this.tabName!); } - }) + }); } /** @@ -80,20 +79,31 @@ export class TestgridDataContent extends LitElement { * Invoked on each update to perform rendering tasks. */ render() { - var tabBar = html`${ + const tabBar = html`${ // make sure we only render the tabs when there are tabs - when(this.tabNames.length > 0, () => html` - + when( + this.tabNames.length > 0, + () => html` ${map( - this.tabNames,(name: string) => html`` + this.tabNames, + (name: string) => html`` )} - `) + ` + ) }`; return html` ${tabBar} - ${!this.showTab ? - html`` : - html``} + ${!this.showTab + ? html`` + : html``} `; } @@ -107,7 +117,7 @@ export class TestgridDataContent extends LitElement { throw new Error(`HTTP error: ${response.status}`); } const data = ListDashboardTabsResponse.fromJson(await response.json()); - var tabNames: string[] = ['Summary']; + const tabNames: string[] = ['Summary']; data.dashboardTabs.forEach(tab => { tabNames.push(tab.name); }); @@ -120,21 +130,21 @@ export class TestgridDataContent extends LitElement { // identify which tab to highlight on the tab bar private highlightIndex(tabName: string | undefined) { - if (tabName === undefined){ + if (tabName === undefined) { this.activeIndex = 0; - return + return; } - var index = this.tabNames.indexOf(tabName); - if (index > -1){ + const index = this.tabNames.indexOf(tabName); + if (index > -1) { this.activeIndex = index; } } static styles = css` - mwc-tab{ + mwc-tab { --mdc-typography-button-letter-spacing: 0; --mdc-tab-horizontal-padding: 12px; --mdc-typography-button-font-size: 0.8rem; } -`; + `; } diff --git a/web/src/testgrid-failures-summary.ts b/web/src/testgrid-failures-summary.ts index 1711cd2..184c2d8 100644 --- a/web/src/testgrid-failures-summary.ts +++ b/web/src/testgrid-failures-summary.ts @@ -1,12 +1,13 @@ import { LitElement, html, css } from 'lit'; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { customElement, property, state } from 'lit/decorators.js'; -import { TabSummaryInfo } from './testgrid-dashboard-summary'; import { map } from 'lit/directives/map.js'; +import { TabSummaryInfo } from './testgrid-dashboard-summary'; @customElement('testgrid-failures-summary') export class TestgridFailuresSummary extends LitElement { @state() showFailureSummary = false; + @property() info?: TabSummaryInfo; render() { @@ -38,6 +39,7 @@ export class TestgridFailuresSummary extends LitElement { ` } + private dropdownTable(){ this.showFailureSummary = !this.showFailureSummary; } diff --git a/web/src/testgrid-grid-cell.ts b/web/src/testgrid-grid-cell.ts index 2753a8f..9ce2325 100644 --- a/web/src/testgrid-grid-cell.ts +++ b/web/src/testgrid-grid-cell.ts @@ -59,6 +59,7 @@ export class TestgridGridCell extends LitElement{ `; @property({reflect: true, attribute: 'status'}) status: String; + @property() icon: String; render(){ diff --git a/web/src/testgrid-grid.ts b/web/src/testgrid-grid.ts index fd6f388..5f192e6 100644 --- a/web/src/testgrid-grid.ts +++ b/web/src/testgrid-grid.ts @@ -1,7 +1,11 @@ -import { LitElement, html, PropertyValues } from "lit"; -import { map } from "lit/directives/map.js"; -import { customElement, property, state } from "lit/decorators.js"; -import { ListHeadersResponse, ListRowsResponse, ListRowsResponse_Row } from './gen/pb/api/v1/data.js'; +import { LitElement, html, PropertyValues } from 'lit'; +import { map } from 'lit/directives/map.js'; +import { customElement, property, state } from 'lit/decorators.js'; +import { + ListHeadersResponse, + ListRowsResponse, + ListRowsResponse_Row, +} from './gen/pb/api/v1/data.js'; import './testgrid-grid-row'; import './testgrid-grid-header-row'; @@ -11,7 +15,6 @@ import './testgrid-grid-header-row'; */ @customElement('testgrid-grid') export class TestgridGrid extends LitElement { - @property({ type: String, reflect: true }) dashboardName: String = ''; @@ -40,10 +43,17 @@ export class TestgridGrid extends LitElement { */ render() { return html` - - ${map(this.tabGridRows, - (row: ListRowsResponse_Row) => html`` - )} + + ${map( + this.tabGridRows, + (row: ListRowsResponse_Row) => + html`` + )} `; } @@ -62,7 +72,7 @@ export class TestgridGrid extends LitElement { throw new Error(`HTTP error: ${response.status}`); } const data = ListRowsResponse.fromJson(await response.json()); - var rows: Array = []; + const rows: Array = []; data.rows.forEach(row => rows.push(row)); this.tabGridRows = rows; } catch (error) { diff --git a/web/src/testgrid-group-summary.ts b/web/src/testgrid-group-summary.ts index efbaf61..c7354e8 100644 --- a/web/src/testgrid-group-summary.ts +++ b/web/src/testgrid-group-summary.ts @@ -1,8 +1,10 @@ import { LitElement, html, css } from 'lit'; import { customElement, property, state } from 'lit/decorators.js'; -import { ListDashboardSummariesResponse } from './gen/pb/api/v1/data'; -import { DashboardSummary } from './gen/pb/api/v1/data'; import { map } from 'lit/directives/map.js'; +import { + ListDashboardSummariesResponse, + DashboardSummary, +} from './gen/pb/api/v1/data'; import { TabStatusIcon } from './testgrid-dashboard-summary'; /** @@ -17,7 +19,6 @@ interface RenderedDashboardSummary { @customElement('testgrid-group-summary') export class TestgridGroupSummary extends LitElement { - @property({ type: String }) groupName = ''; @@ -39,14 +40,18 @@ export class TestgridGroupSummary extends LitElement { - ${map(this.dashboardSummaries, + ${map( + this.dashboardSummaries, (ds: RenderedDashboardSummary) => html` - ${ds.icon} + + ${ds.icon} + ${ds.name} ${ds.tabDescription} - `)} + ` + )} `; @@ -65,72 +70,76 @@ export class TestgridGroupSummary extends LitElement { if (!response.ok) { throw new Error(`HTTP error: ${response.status}`); } - const data = ListDashboardSummariesResponse.fromJson(await response.json()); - var summaries: RenderedDashboardSummary[] = []; - data.dashboardSummaries.forEach(summary => summaries.push(this.convertResponse(summary))); + const data = ListDashboardSummariesResponse.fromJson( + await response.json() + ); + const summaries: RenderedDashboardSummary[] = []; + data.dashboardSummaries.forEach(summary => + summaries.push(this.convertResponse(summary)) + ); this.dashboardSummaries = summaries; } catch (error) { console.error(`Could not get grid rows: ${error}`); } } - private convertResponse(summary: DashboardSummary){ + private convertResponse(summary: DashboardSummary) { const sortedStatuses: string[] = [ - "PASSING", - "ACCEPTABLE", - "FLAKY", - "FAILING", - "STALE", - "BROKEN", - "PENDING" - ] - - var numPassing = 0; - var total = 0; - for (const key in summary.tabStatusCount){ - if (key === "PASSING"){ + 'PASSING', + 'ACCEPTABLE', + 'FLAKY', + 'FAILING', + 'STALE', + 'BROKEN', + 'PENDING', + ]; + + let numPassing = 0; + let total = 0; + for (const key in summary.tabStatusCount) { + if (key === 'PASSING') { numPassing = summary.tabStatusCount[key]; } total += summary.tabStatusCount[key]; } - var prefix = `${numPassing} / ${total} PASSING`; - var descriptions: string [] = []; + let prefix = `${numPassing} / ${total} PASSING`; + const descriptions: string[] = []; sortedStatuses.forEach(status => { - if (summary.tabStatusCount[status] > 0){ + if (summary.tabStatusCount[status] > 0) { descriptions.push(`${summary.tabStatusCount[status]} ${status}`); } }); - if (descriptions.length >0){ - prefix += " ("+ descriptions.join(", ") +")"; + if (descriptions.length > 0) { + prefix += ` (${descriptions.join(', ')})`; } const rds: RenderedDashboardSummary = { name: summary.name, overallStatus: summary.overallStatus, icon: TabStatusIcon.get(summary.overallStatus)!, - tabDescription: prefix + tabDescription: prefix, }; return rds; } static styles = css` - - body{ + body { font-size: 12px; } - .material-icons{ + .material-icons { font-size: 2em; } - th, td { + th, + td { padding: 0.5em 2em; } - thead{ + thead { background-color: #e0e0e0; } diff --git a/web/src/testgrid-healthiness-summary.ts b/web/src/testgrid-healthiness-summary.ts index 72cc77a..2d6c745 100644 --- a/web/src/testgrid-healthiness-summary.ts +++ b/web/src/testgrid-healthiness-summary.ts @@ -1,48 +1,62 @@ import { LitElement, html, css } from 'lit'; // eslint-disable-next-line @typescript-eslint/no-unused-vars import { customElement, property, state } from 'lit/decorators.js'; -import { TabSummaryInfo } from './testgrid-dashboard-summary'; import { map } from 'lit/directives/map.js'; +import { TabSummaryInfo } from './testgrid-dashboard-summary'; @customElement('testgrid-healthiness-summary') export class TestgridTabTable extends LitElement { @state() showHealthinesSummary = false; + @property() info?: TabSummaryInfo; render() { return html` -