-
-
Notifications
You must be signed in to change notification settings - Fork 946
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
web/admin: refactor property mappings forms (#10810)
- Loading branch information
Showing
13 changed files
with
54 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,56 @@ | ||
import { docLink } from "@goauthentik/common/global"; | ||
import { CodeMirrorMode } from "@goauthentik/elements/CodeMirror"; | ||
import { ModelForm } from "@goauthentik/elements/forms/ModelForm"; | ||
|
||
import { msg } from "@lit/localize"; | ||
import { TemplateResult, html } from "lit"; | ||
import { ifDefined } from "lit/directives/if-defined.js"; | ||
|
||
interface PropertyMapping { | ||
name: string; | ||
expression: string; | ||
} | ||
|
||
export abstract class BasePropertyMappingForm<T extends PropertyMapping> extends ModelForm< | ||
T, | ||
string | ||
> { | ||
docLink(): string { | ||
return "/docs/property-mappings/expression?utm_source=authentik"; | ||
} | ||
|
||
export abstract class BasePropertyMappingForm<T> extends ModelForm<T, string> { | ||
getSuccessMessage(): string { | ||
return this.instance | ||
? msg("Successfully updated mapping.") | ||
: msg("Successfully created mapping."); | ||
} | ||
|
||
renderExtraFields(): TemplateResult { | ||
return html``; | ||
} | ||
|
||
renderForm(): TemplateResult { | ||
return html` <ak-form-element-horizontal label=${msg("Name")} required name="name"> | ||
<input | ||
type="text" | ||
value="${ifDefined(this.instance?.name)}" | ||
class="pf-c-form-control" | ||
required | ||
/> | ||
</ak-form-element-horizontal> | ||
${this.renderExtraFields()} | ||
<ak-form-element-horizontal label=${msg("Expression")} required name="expression"> | ||
<ak-codemirror | ||
mode=${CodeMirrorMode.Python} | ||
value="${ifDefined(this.instance?.expression)}" | ||
> | ||
</ak-codemirror> | ||
<p class="pf-c-form__helper-text"> | ||
${msg("Expression using Python.")} | ||
<a target="_blank" rel="noopener noreferrer" href="${docLink(this.docLink())}"> | ||
${msg("See documentation for a list of all variables.")} | ||
</a> | ||
</p> | ||
</ak-form-element-horizontal>`; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.