mirror of
https://github.com/goauthentik/authentik.git
synced 2026-06-17 19:09:11 +03:00
web/elements: add past-tense submitted formatter to Form (#22900)
Adds `submittedVerb` and `formatSubmittedLabel` to the `Form` base
class, plus a `submittedLabel` per-instance override — the past-tense
counterpart to the `submitVerb` / `submittingVerb` pair already
in place. `ModelForm` swaps in a `savedLabel` ("Changes Saved") when
`instancePk` is set, the same create-vs-edit branch already used by
`saveLabel` and `savingLabel`.
With this in place, `getSuccessMessage()` overrides can read the
"Created X" / "Changes Saved" wording off the formatter instead of
restating the create/update branch in every form.
Closes #22900.
Co-Authored-By: Agent (authentik-i22900-assured-preferred-petunia) <279763771+playpen-agent@users.noreply.github.com>
This commit is contained in:
@@ -148,6 +148,13 @@ export class Form<T = Record<string, unknown>, D = T>
|
||||
id: "form.submit.verb.creating",
|
||||
});
|
||||
|
||||
/**
|
||||
* The past-tense verb to use in the default success message, e.g. "Created" or "Updated".
|
||||
*/
|
||||
public static submittedVerb: string = msg("Created", {
|
||||
id: "form.submit.verb.created",
|
||||
});
|
||||
|
||||
//#region Modal helpers
|
||||
|
||||
public [TransclusionChildSymbol] = true;
|
||||
@@ -240,6 +247,14 @@ export class Form<T = Record<string, unknown>, D = T>
|
||||
@property({ type: String, attribute: "submitting-label", useDefault: true })
|
||||
public submittingLabel: string | null = null;
|
||||
|
||||
/**
|
||||
* The message shown after the form has been successfully submitted. If not provided,
|
||||
* a default label will be generated based on `submittedVerb` and `verboseName`,
|
||||
* falling back to "Created".
|
||||
*/
|
||||
@property({ type: String, attribute: "submitted-label", useDefault: true })
|
||||
public submittedLabel: string | null = null;
|
||||
|
||||
@property({ type: String, attribute: "cancel-label", useDefault: true })
|
||||
public cancelButtonLabel: string | null = msg("Cancel");
|
||||
|
||||
@@ -427,6 +442,26 @@ export class Form<T = Record<string, unknown>, D = T>
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* An overridable method for formatting the message shown after the form has been
|
||||
* successfully submitted.
|
||||
*/
|
||||
protected formatSubmittedLabel(submittedLabel = this.submittedLabel): string {
|
||||
if (submittedLabel) {
|
||||
return submittedLabel;
|
||||
}
|
||||
|
||||
const noun = this.verboseName;
|
||||
const verb = (this.constructor as typeof Form).submittedVerb;
|
||||
|
||||
return noun
|
||||
? msg(str`${verb} ${noun}`, {
|
||||
id: "form.submitted.verb-entity",
|
||||
desc: "The message shown after a form is successfully submitted.",
|
||||
})
|
||||
: verb;
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
//#region Public methods
|
||||
|
||||
@@ -70,6 +70,14 @@ export abstract class ModelForm<
|
||||
id: "form.submit.saving-changes",
|
||||
});
|
||||
|
||||
/**
|
||||
* The message shown after the form has been successfully submitted when
|
||||
* editing an instance, e.g. "Changes Saved".
|
||||
*/
|
||||
public static savedLabel: string | null = msg("Changes Saved", {
|
||||
id: "form.submit.changes-saved",
|
||||
});
|
||||
|
||||
/**
|
||||
* A helper method to create an invoker for editing an instance of this form.
|
||||
*
|
||||
@@ -182,6 +190,16 @@ export abstract class ModelForm<
|
||||
return super.formatSubmittingLabel(submittingLabel);
|
||||
}
|
||||
|
||||
protected override formatSubmittedLabel(submittedLabel?: string): string {
|
||||
const { savedLabel } = this.constructor as typeof ModelForm;
|
||||
|
||||
if (this.instancePk && savedLabel) {
|
||||
return savedLabel;
|
||||
}
|
||||
|
||||
return super.formatSubmittedLabel(submittedLabel);
|
||||
}
|
||||
|
||||
protected override formatHeadline(modifier?: string | null): string {
|
||||
modifier ||= this.instancePk ? (this.constructor as typeof ModelForm).modifierLabel : null;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user