web: clean up the options rendering in PromptForm (#9564)

* 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: clean up a bit inside the promptform

Just something I did while researching Github Issue 5197.
This commit is contained in:
Ken Sternberg
2024-05-06 08:55:43 -07:00
committed by GitHub
parent 46980db582
commit 9ec6f548a6
2 changed files with 32 additions and 116 deletions

View File

@ -11,6 +11,7 @@ import { msg } from "@lit/localize";
import { CSSResult, TemplateResult, html } from "lit";
import { customElement, state } from "lit/decorators.js";
import { ifDefined } from "lit/directives/if-defined.js";
import { map } from "lit/directives/map.js";
import PFTitle from "@patternfly/patternfly/components/Title/title.css";
import PFGrid from "@patternfly/patternfly/layouts/Grid/grid.css";
@ -121,120 +122,35 @@ export class PromptForm extends ModelForm<Prompt, string> {
}
renderTypes(): TemplateResult {
return html`
<option
value=${PromptTypeEnum.Text}
?selected=${this.instance?.type === PromptTypeEnum.Text}
>
${msg("Text: Simple Text input")}
</option>
<option
value=${PromptTypeEnum.TextArea}
?selected=${this.instance?.type === PromptTypeEnum.TextArea}
>
${msg("Text Area: Multiline text input")}
</option>
<option
value=${PromptTypeEnum.TextReadOnly}
?selected=${this.instance?.type === PromptTypeEnum.TextReadOnly}
>
${msg("Text (read-only): Simple Text input, but cannot be edited.")}
</option>
<option
value=${PromptTypeEnum.TextAreaReadOnly}
?selected=${this.instance?.type === PromptTypeEnum.TextAreaReadOnly}
>
${msg("Text Area (read-only): Multiline text input, but cannot be edited.")}
</option>
<option
value=${PromptTypeEnum.Username}
?selected=${this.instance?.type === PromptTypeEnum.Username}
>
${msg(
"Username: Same as Text input, but checks for and prevents duplicate usernames.",
)}
</option>
<option
value=${PromptTypeEnum.Email}
?selected=${this.instance?.type === PromptTypeEnum.Email}
>
${msg("Email: Text field with Email type.")}
</option>
<option
value=${PromptTypeEnum.Password}
?selected=${this.instance?.type === PromptTypeEnum.Password}
>
${msg(
"Password: Masked input, multiple inputs of this type on the same prompt need to be identical.",
)}
</option>
<option
value=${PromptTypeEnum.Number}
?selected=${this.instance?.type === PromptTypeEnum.Number}
>
${msg("Number")}
</option>
<option
value=${PromptTypeEnum.Checkbox}
?selected=${this.instance?.type === PromptTypeEnum.Checkbox}
>
${msg("Checkbox")}
</option>
<option
value=${PromptTypeEnum.RadioButtonGroup}
?selected=${this.instance?.type === PromptTypeEnum.RadioButtonGroup}
>
${msg("Radio Button Group (fixed choice)")}
</option>
<option
value=${PromptTypeEnum.Dropdown}
?selected=${this.instance?.type === PromptTypeEnum.Dropdown}
>
${msg("Dropdown (fixed choice)")}
</option>
<option
value=${PromptTypeEnum.Date}
?selected=${this.instance?.type === PromptTypeEnum.Date}
>
${msg("Date")}
</option>
<option
value=${PromptTypeEnum.DateTime}
?selected=${this.instance?.type === PromptTypeEnum.DateTime}
>
${msg("Date Time")}
</option>
<option
value=${PromptTypeEnum.File}
?selected=${this.instance?.type === PromptTypeEnum.File}
>
${msg("File")}
</option>
<option
value=${PromptTypeEnum.Separator}
?selected=${this.instance?.type === PromptTypeEnum.Separator}
>
${msg("Separator: Static Separator Line")}
</option>
<option
value=${PromptTypeEnum.Hidden}
?selected=${this.instance?.type === PromptTypeEnum.Hidden}
>
${msg("Hidden: Hidden field, can be used to insert data into form.")}
</option>
<option
value=${PromptTypeEnum.Static}
?selected=${this.instance?.type === PromptTypeEnum.Static}
>
${msg("Static: Static value, displayed as-is.")}
</option>
<option
value=${PromptTypeEnum.AkLocale}
?selected=${this.instance?.type === PromptTypeEnum.AkLocale}
>
${msg("authentik: Locale: Displays a list of locales authentik supports.")}
</option>
`;
// prettier-ignore
const promptTypesWithLabels = [
[PromptTypeEnum.Text, msg("Text: Simple Text input")],
[PromptTypeEnum.TextArea, msg("Text Area: Multiline text input")],
[PromptTypeEnum.TextReadOnly, msg("Text (read-only): Simple Text input, but cannot be edited.")],
[PromptTypeEnum.TextAreaReadOnly, msg("Text Area (read-only): Multiline text input, but cannot be edited.")],
[PromptTypeEnum.Username, msg("Username: Same as Text input, but checks for and prevents duplicate usernames.")],
[PromptTypeEnum.Email, msg("Email: Text field with Email type.")],
[PromptTypeEnum.Password, msg("Password: Masked input, multiple inputs of this type on the same prompt need to be identical.")],
[PromptTypeEnum.Number, msg("Number")],
[PromptTypeEnum.Checkbox, msg("Checkbox")],
[PromptTypeEnum.RadioButtonGroup, msg("Radio Button Group (fixed choice)")],
[PromptTypeEnum.Dropdown, msg("Dropdown (fixed choice)")],
[PromptTypeEnum.Date, msg("Date")],
[PromptTypeEnum.DateTime, msg("Date Time")],
[PromptTypeEnum.File, msg("File")],
[PromptTypeEnum.Separator, msg("Separator: Static Separator Line")],
[PromptTypeEnum.Hidden, msg("Hidden: Hidden field, can be used to insert data into form.")],
[PromptTypeEnum.Static, msg("Static: Static value, displayed as-is.")],
[PromptTypeEnum.AkLocale, msg("authentik: Locale: Displays a list of locales authentik supports.")],
];
const currentType = this.instance?.type;
return html` ${map(
promptTypesWithLabels,
([promptType, label]) =>
html`<option value=${promptType} ?selected=${promptType === currentType}>
${label}
</option>`,
)}`;
}
renderForm(): TemplateResult {