Skip to content

Commit

Permalink
web: add HTMLTagNameElementMaps to everything to activate lit analyzer (
Browse files Browse the repository at this point in the history
#10217)

* web: fix esbuild issue with style sheets

Getting ESBuild, Lit, and Storybook to all agree on how to read and parse stylesheets is a serious
pain. This fix better identifies the value types (instances) being passed from various sources in
the repo to the three *different* kinds of style processors we're using (the native one, the
polyfill one, and whatever the heck Storybook does internally).

Falling back to using older CSS instantiating techniques one era at a time seems to do the trick.
It's ugly, but in the face of the aggressive styling we use to avoid Flashes of Unstyled Content
(FLoUC), it's the logic with which we're left.

In standard mode, the following warning appears on the console when running a Flow:

```
Autofocus processing was blocked because a document already has a focused element.
```

In compatibility mode, the following **error** appears on the console when running a Flow:

```
crawler-inject.js:1106 Uncaught TypeError: Failed to execute 'observe' on 'MutationObserver': parameter 1 is not of type 'Node'.
    at initDomMutationObservers (crawler-inject.js:1106:18)
    at crawler-inject.js:1114:24
    at Array.forEach (<anonymous>)
    at initDomMutationObservers (crawler-inject.js:1114:10)
    at crawler-inject.js:1549:1
initDomMutationObservers @ crawler-inject.js:1106
(anonymous) @ crawler-inject.js:1114
initDomMutationObservers @ crawler-inject.js:1114
(anonymous) @ crawler-inject.js:1549
```

Despite this error, nothing seems to be broken and flows work as anticipated.

* web: add more linting

* A reliable test for the extra code needed in analyzer, passing shellcheck

* web: re-enable custom-element-manifest and enable component checking in Typescript

This commit includes a monkeypatch to allow custom-element-manifest (CEM) to work correctly again
despite our rich collection of mixins, reactive controllers, symbol-oriented event handlers, and the
like. With that monkeypatch in place, we can now create the CEM manifest file and then exploit it so
that IDEs and the Typescript compilation pass can tell when a component is being used incorrectly;
when the wrong types are being passed to it, or when a required attribute is not initialized.

* Added building the manifest to the build process, rather than storing it.  It is not appreciably slow.

* web: the most boring PR in the universe: Add HTMLTagNameElementMap to everyhing

This commit adds HTMLTagNameElementMap entries to every web component in the front end. Activating
and associating the HTMLTagNamElementMap with its class has enabled
[LitAnalyzer](https://github.com/runem/lit-analyzer/tree/master/packages/lit-analyzer) to reveal a
*lot* of basic problems within the UI, the most popular of which is "missing import." We usually get
away with it because the object being imported was already registered with the browser elsewhere,
but it still surprises me that we haven't gotten any complaints over things like:

```
./src/flow/stages/base.ts
Missing import for <ak-form-static>
96:  <ak-form-static
no-missing-import
```

Given how early and fundamental that seems to be in our code, I'd have expected to hear _something_
about it.

I have not enabled most of the possible checks because, well, there are just a ton of warnings when
I do.  I'd like to get in and fix those.

Aside from this, I have also _removed_ `customElement` declarations from anything declared as an
`abstract class`. It makes no sense to try and instantiate something that cannot, by definition, be
instantiated.  If the class is capable of running on its own, it's not abstract, it just needs to be
overridden in child classes.  Before removing the declaration I did check to make sure no other
piece of code was even *trying* to instantiate it, and so far I have detected no failures.  Those
elements were:

- elements/forms/Form.ts
- element-/wizard/WizardFormPage.ts

The one that blows my mind, though, is this:

```
src/elements/forms/ProxyForm.ts
6-@CustomElement("ak-proxy-form")
7:export abstract class ProxyForm extends Form<unknown> {
```

Which, despite being `abstract`, is somehow instantiable?

```
src/admin/outposts/ServiceConnectionListPage.ts:    <ak-proxy-form
src/admin/providers/ProviderListPage.ts:    <ak-proxy-form
src/admin/sources/SourceWizard.ts:    <ak-proxy-form
src/admin/sources/SourceListPage.ts:    <ak-proxy-form
src/admin/providers/ProviderWizard.ts:    <ak-proxy-form type=${type.component}></ak-proxy-form>
src/admin/stages/StageListPage.ts:    <ak-proxy-form
```

I've made a note to investigate.

I've started a new folder where all of my one-off tools for *how* a certain PR was run.  It has a
README describing what it's for, and the first tool, `add-htmlelementtagnamemaps-to-everything`, is
its first entry.  That tool is also documented internally.

``` Gilbert & Sullivan

I've got a little list,
I've got a little list,
Of all the code that would never be missed,
The duplicate code of cute-and-paste,
The weak abstractions that lead to waste,
The embedded templates-- you get the gist,
There ain't none of 'em that will ever be missed,
And that's why I've got them on my list!

```
  • Loading branch information
kensternberg-authentik authored Jul 15, 2024
1 parent 1f2654f commit ee58cf0
Show file tree
Hide file tree
Showing 361 changed files with 2,236 additions and 4 deletions.
1 change: 1 addition & 0 deletions web/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,4 @@ temp/
# End of https://www.gitignore.io/api/node
api/**
storybook-static/
custom-elements.json
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"lint:precommit": "bun scripts/eslint-precommit.mjs",
"lint:spelling": "node scripts/check-spelling.mjs",
"lit-analyse": "lit-analyzer src",
"lit-analyse:strict": "lit-analyzer src --strict",
"postinstall": "bash scripts/patch-spotlight.sh",
"precommit": "npm-run-all --parallel tsc lit-analyse lint:spelling lint:lockfile --sequential lint:precommit prettier",
"prequick": "run-s tsc:execute lit-analyse lint:precommit lint:spelling",
Expand Down
6 changes: 6 additions & 0 deletions web/src/admin/AdminInterface/AdminInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,3 +158,9 @@ export class AdminInterface extends EnterpriseAwareInterface {
></ak-locale-context>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-interface-admin": AdminInterface;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/AdminInterface/AdminSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,9 @@ export class AkAdminSidebar extends WithCapabilitiesConfig(AKElement) {
: nothing;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-sidebar": AkAdminSidebar;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/DebugPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,9 @@ export class DebugPage extends AKElement {
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-debug-page": DebugPage;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/DashboardUserPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,9 @@ export class DashboardUserPage extends AKElement {
</section> `;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-dashboard-users": DashboardUserPage;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/TopApplicationsTable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ export class TopApplicationsTable extends AKElement {
</table>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-top-applications-table": TopApplicationsTable;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/cards/RecentEventsCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,9 @@ export class RecentEventsCard extends Table<Event> {
);
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-recent-events": RecentEventsCard;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/cards/SystemStatusCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,9 @@ export class SystemStatusCard extends AdminStatusCard<SystemInfo> {
return html`${this.statusSummary}`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-status-system": SystemStatusCard;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/cards/VersionStatusCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,9 @@ export class VersionStatusCard extends AdminStatusCard<Version> {
return html`<a rel="noopener noreferrer" href=${link} target="_blank">${text}</a>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-status-version": VersionStatusCard;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/cards/WorkerStatusCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,9 @@ export class WorkersStatusCard extends AdminStatusCard<number> {
}
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-status-card-workers": WorkersStatusCard;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,9 @@ export class AdminLoginAuthorizeChart extends AKChart<LoginMetrics> {
};
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-charts-admin-login-authorization": AdminLoginAuthorizeChart;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/charts/AdminModelPerDay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,9 @@ export class AdminModelPerDay extends AKChart<Coordinate[]> {
};
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-charts-admin-model-per-day": AdminModelPerDay;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/charts/OutpostStatusChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,9 @@ export class OutpostStatusChart extends AKChart<SummarizedSyncStatus[]> {
};
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-status-chart-outpost": OutpostStatusChart;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-overview/charts/SyncStatusChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,9 @@ export class SyncStatusChart extends AKChart<SummarizedSyncStatus[]> {
};
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-status-chart-sync": SyncStatusChart;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-settings/AdminSettingsForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,9 @@ export class AdminSettingsForm extends Form<SettingsRequest> {
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-settings-form": AdminSettingsForm;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/admin-settings/AdminSettingsPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,9 @@ export class AdminSettingsPage extends AKElement {
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-admin-settings": AdminSettingsPage;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/ApplicationAuthorizeChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ export class ApplicationAuthorizeChart extends AKChart<Coordinate[]> {
};
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-charts-application-authorize": ApplicationAuthorizeChart;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/ApplicationCheckAccessForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,9 @@ export class ApplicationCheckAccessForm extends Form<{ forUser: number }> {
${this.result ? this.renderResult() : html``}`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-application-check-access-form": ApplicationCheckAccessForm;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/ApplicationForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,9 @@ export class ApplicationForm extends WithCapabilitiesConfig(ModelForm<Applicatio
</form>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-application-form": ApplicationForm;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/ApplicationListPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,9 @@ export class ApplicationListPage extends TablePage<Application> {
</ak-forms-modal>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-application-list": ApplicationListPage;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/ApplicationViewPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,3 +322,9 @@ export class ApplicationViewPage extends AKElement {
</ak-tabs>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-application-view": ApplicationViewPage;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/ApplicationWizardHint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,9 @@ export class AkApplicationWizardHint extends AKElement implements ShowHintContro
}

export default AkApplicationWizardHint;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-hint": AkApplicationWizardHint;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/ProviderSelectModal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ export class ProviderSelectModal extends TableModal<Provider> {
</footer>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-provider-select-table": ProviderSelectModal;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/components/ak-backchannel-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,9 @@ export class AkBackchannelProvidersInput extends AKElement {
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-backchannel-providers-input": AkBackchannelProvidersInput;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,9 @@ export class AkProviderInput extends AKElement {
</ak-form-element-horizontal>`;
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-provider-search-input": AkProviderInput;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/wizard/ak-application-wizard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ export class ApplicationWizard extends CustomListenerElement(
this.requestUpdate();
}
}

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard": ApplicationWizard;
}
}
6 changes: 6 additions & 0 deletions web/src/admin/applications/wizard/ak-wizard-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ export class AkWizardTitle extends AKElement {
}

export default AkWizardTitle;

declare global {
interface HTMLElementTagNameMap {
"ak-wizard-title": AkWizardTitle;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,9 @@ export class ApplicationWizardApplicationDetails extends BasePanel {
}

export default ApplicationWizardApplicationDetails;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-application-details": ApplicationWizardApplicationDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,9 @@ export class ApplicationWizardAuthenticationMethodChoice extends WithLicenseSumm
}

export default ApplicationWizardAuthenticationMethodChoice;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-method-choice": ApplicationWizardAuthenticationMethodChoice;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -217,3 +217,9 @@ export class ApplicationWizardCommitApplication extends BasePanel {
}

export default ApplicationWizardCommitApplication;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-commit-application": ApplicationWizardCommitApplication;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ export class ApplicationWizardApplicationDetails extends BasePanel {
}

export default ApplicationWizardApplicationDetails;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-method": ApplicationWizardApplicationDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,9 @@ export class ApplicationWizardApplicationDetails extends WithBrandConfig(BasePro
}

export default ApplicationWizardApplicationDetails;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-by-ldap": ApplicationWizardApplicationDetails;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -288,3 +288,9 @@ export class ApplicationWizardAuthenticationByOauth extends BaseProviderPanel {
}

export default ApplicationWizardAuthenticationByOauth;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-by-oauth": ApplicationWizardAuthenticationByOauth;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,9 @@ export class AkForwardDomainProxyApplicationWizardPage extends AkTypeProxyApplic
}

export default AkForwardDomainProxyApplicationWizardPage;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-for-forward-proxy-domain": AkForwardDomainProxyApplicationWizardPage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ export class AkReverseProxyApplicationWizardPage extends AkTypeProxyApplicationW
}

export default AkReverseProxyApplicationWizardPage;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-for-reverse-proxy": AkReverseProxyApplicationWizardPage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ export class AkForwardSingleProxyApplicationWizardPage extends AkTypeProxyApplic
}

export default AkForwardSingleProxyApplicationWizardPage;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-for-single-forward-proxy": AkForwardSingleProxyApplicationWizardPage;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ export class ApplicationWizardAuthenticationByRAC extends BaseProviderPanel {
}

export default ApplicationWizardAuthenticationByRAC;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-for-rac": ApplicationWizardAuthenticationByRAC;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,9 @@ export class ApplicationWizardAuthenticationByRadius extends WithBrandConfig(Bas
}

export default ApplicationWizardAuthenticationByRadius;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-by-radius": ApplicationWizardAuthenticationByRadius;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,9 @@ export class ApplicationWizardProviderSamlConfiguration extends BaseProviderPane
}

export default ApplicationWizardProviderSamlConfiguration;

declare global {
interface HTMLElementTagNameMap {
"ak-application-wizard-authentication-by-saml-configuration": ApplicationWizardProviderSamlConfiguration;
}
}
Loading

0 comments on commit ee58cf0

Please sign in to comment.