From df16dc3088110fa0b5a8e93889d8c7d7280b7ebe Mon Sep 17 00:00:00 2001 From: Ken Sternberg Date: Thu, 3 Aug 2023 14:43:31 -0700 Subject: [PATCH] web: Replace ad-hoc toggle control with ak-toggle-group This commit replaces various ad-hoc implementations of the Patternfly Toggle Group HTML with a web component that encapsulates all of the needed behavior and exposes a single API with a single event handler, return the value of the option clicked. The results are: Lots of visual clutter is eliminated. A single link of: ```
``` Now looks like: ``` ``` This also means that the three pages that used the Patternfly Toggle Group could eliminate all of their Patternfly PFToggleGroup needs, as well as the `justify-content: center` extension, which also eliminated the `css` import. The savings aren't as spectacular as I'd hoped: removed 178 lines, but added 123; total savings 55 lines of code. I still count this a win: we need never write another toggle component again, and any bugs, extensions or features we may want to add can be centralized or forked without risking the whole edifice. --- web/src/admin/blueprints/BlueprintForm.ts | 69 +++----------- web/src/admin/policies/PolicyBindingForm.ts | 68 +++----------- .../providers/proxy/ProxyProviderForm.ts | 81 +++++------------ web/src/components/ak-toggle-group.ts | 90 +++++++++++++++++++ web/tsconfig.json | 1 + 5 files changed, 136 insertions(+), 173 deletions(-) create mode 100644 web/src/components/ak-toggle-group.ts diff --git a/web/src/admin/blueprints/BlueprintForm.ts b/web/src/admin/blueprints/BlueprintForm.ts index 24a55ee8a..3176ddb0e 100644 --- a/web/src/admin/blueprints/BlueprintForm.ts +++ b/web/src/admin/blueprints/BlueprintForm.ts @@ -9,12 +9,11 @@ import "@goauthentik/elements/forms/SearchSelect"; import YAML from "yaml"; import { msg } from "@lit/localize"; -import { CSSResult, TemplateResult, css, html } from "lit"; +import { CSSResult, TemplateResult, html } from "lit"; import { customElement, state } from "lit/decorators.js"; import { ifDefined } from "lit/directives/if-defined.js"; import PFContent from "@patternfly/patternfly/components/Content/content.css"; -import PFToggleGroup from "@patternfly/patternfly/components/ToggleGroup/toggle-group.css"; import { BlueprintFile, BlueprintInstance, ManagedApi } from "@goauthentik/api"; @@ -51,15 +50,7 @@ export class BlueprintForm extends ModelForm { } static get styles(): CSSResult[] { - return super.styles.concat( - PFToggleGroup, - PFContent, - css` - .pf-c-toggle-group { - justify-content: center; - } - `, - ); + return [...super.styles, PFContent]; } async send(data: BlueprintInstance): Promise { @@ -105,52 +96,16 @@ export class BlueprintForm extends ModelForm {
-
-
- -
- -
- -
- -
- -
-
+ ) => { + this.source = ev.detail.value; + }} + > + + + +