mirror of
https://github.com/goauthentik/authentik
synced 2026-05-05 22:52:42 +02:00
web: Unify usage of "valid".
This commit is contained in:
@@ -51,7 +51,7 @@ export class FooterLinkInput extends AkControlElement<FooterLink> {
|
||||
) as unknown as FooterLink;
|
||||
}
|
||||
|
||||
get isValid() {
|
||||
get valid() {
|
||||
const href = this.json()?.href ?? "";
|
||||
return hasLegalScheme(href) && URL.canParse(href);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ const metadata: Meta<FooterLinkInput> = {
|
||||
return;
|
||||
}
|
||||
const target = event.target as FooterLinkInput;
|
||||
messages!.innerText = `${JSON.stringify(target.json(), null, 2)}\n\nValid: ${target.isValid ? "Yes" : "No"}`;
|
||||
messages!.innerText = `${JSON.stringify(target.json(), null, 2)}\n\nValid: ${target.valid ? "Yes" : "No"}`;
|
||||
});
|
||||
}, 250);
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ describe("ak-admin-settings-footer-link", () => {
|
||||
it("should render an empty control", async () => {
|
||||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`);
|
||||
const link = await $("ak-admin-settings-footer-link");
|
||||
await expect(await link.getProperty("isValid")).toStrictEqual(false);
|
||||
await expect(await link.getProperty("valid")).toStrictEqual(false);
|
||||
await expect(await link.getProperty("toJson")).toEqual({ name: "", href: "" });
|
||||
});
|
||||
|
||||
@@ -28,7 +28,7 @@ describe("ak-admin-settings-footer-link", () => {
|
||||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`);
|
||||
const link = await $("ak-admin-settings-footer-link");
|
||||
await link.$('input[name="name"]').setValue("foo");
|
||||
await expect(await link.getProperty("isValid")).toStrictEqual(false);
|
||||
await expect(await link.getProperty("valid")).toStrictEqual(false);
|
||||
await expect(await link.getProperty("toJson")).toEqual({ name: "foo", href: "" });
|
||||
});
|
||||
|
||||
@@ -36,7 +36,7 @@ describe("ak-admin-settings-footer-link", () => {
|
||||
render(html`<ak-admin-settings-footer-link name="link"></ak-admin-settings-footer-link>`);
|
||||
const link = await $("ak-admin-settings-footer-link");
|
||||
await link.$('input[name="href"]').setValue("https://foo.com");
|
||||
await expect(await link.getProperty("isValid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("valid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("toJson")).toEqual({
|
||||
name: "",
|
||||
href: "https://foo.com",
|
||||
@@ -48,7 +48,7 @@ describe("ak-admin-settings-footer-link", () => {
|
||||
const link = await $("ak-admin-settings-footer-link");
|
||||
await link.$('input[name="name"]').setValue("foo");
|
||||
await link.$('input[name="href"]').setValue("https://foo.com");
|
||||
await expect(await link.getProperty("isValid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("valid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("toJson")).toEqual({
|
||||
name: "foo",
|
||||
href: "https://foo.com",
|
||||
@@ -64,6 +64,6 @@ describe("ak-admin-settings-footer-link", () => {
|
||||
name: "foo",
|
||||
href: "never://foo.com",
|
||||
});
|
||||
await expect(await link.getProperty("isValid")).toStrictEqual(false);
|
||||
await expect(await link.getProperty("valid")).toStrictEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ export class ServiceConnectionWizard extends AKElement {
|
||||
"initial",
|
||||
`type-${ev.detail.component}-${ev.detail.modelName}`,
|
||||
];
|
||||
this.wizard.isValid = true;
|
||||
this.wizard.valid = true;
|
||||
}}
|
||||
>
|
||||
</ak-wizard-page-type-create>
|
||||
|
||||
@@ -66,7 +66,7 @@ export class PolicyWizard extends AKElement {
|
||||
|
||||
this.wizard.steps.splice(idx, 0, `type-${component}-${modelName}`);
|
||||
|
||||
this.wizard.isValid = true;
|
||||
this.wizard.valid = true;
|
||||
};
|
||||
|
||||
render(): TemplateResult {
|
||||
|
||||
@@ -65,7 +65,7 @@ export class PropertyMappingWizard extends AKElement {
|
||||
"initial",
|
||||
`type-${ev.detail.component}-${ev.detail.modelName}`,
|
||||
];
|
||||
this.wizard.isValid = true;
|
||||
this.wizard.valid = true;
|
||||
}}
|
||||
>
|
||||
</ak-wizard-page-type-create>
|
||||
|
||||
@@ -68,7 +68,7 @@ export class ProviderWizard extends AKElement {
|
||||
@select=${(ev: CustomEvent<TypeCreate>) => {
|
||||
if (!this.wizard) return;
|
||||
this.wizard.steps = ["initial", `type-${ev.detail.component}`];
|
||||
this.wizard.isValid = true;
|
||||
this.wizard.valid = true;
|
||||
}}
|
||||
>
|
||||
</ak-wizard-page-type-create>
|
||||
|
||||
@@ -48,7 +48,7 @@ export class OAuth2ProviderRedirectURI extends AkControlElement<RedirectURI> {
|
||||
) as unknown as RedirectURI;
|
||||
}
|
||||
|
||||
get isValid() {
|
||||
get valid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,7 +57,7 @@ export class SourceWizard extends AKElement {
|
||||
"initial",
|
||||
`type-${ev.detail.component}-${ev.detail.modelName}`,
|
||||
];
|
||||
this.wizard.isValid = true;
|
||||
this.wizard.valid = true;
|
||||
}}
|
||||
>
|
||||
</ak-wizard-page-type-create>
|
||||
|
||||
@@ -93,7 +93,7 @@ export class StageWizard extends AKElement {
|
||||
0,
|
||||
`type-${ev.detail.component}-${ev.detail.modelName}`,
|
||||
);
|
||||
this.wizard.isValid = true;
|
||||
this.wizard.valid = true;
|
||||
}}
|
||||
>
|
||||
</ak-wizard-page-type-create>
|
||||
|
||||
@@ -22,7 +22,7 @@ export class AkControlElement<T = string | string[]> extends AKElement {
|
||||
return this.json();
|
||||
}
|
||||
|
||||
get isValid(): boolean {
|
||||
get valid(): boolean {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,15 +96,16 @@ export class ArrayInput<T> extends AkControlElement<T[]> implements IArrayInput<
|
||||
return this.items;
|
||||
}
|
||||
|
||||
get isValid() {
|
||||
get valid() {
|
||||
if (!this.validate) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const oneIsValid = (g: HTMLDivElement) =>
|
||||
g.querySelector<HTMLInputElement & AkControlElement<T>>("[name]")?.isValid ?? true;
|
||||
const allAreValid = Array.from(this.inputGroups ?? []).every(oneIsValid);
|
||||
return allAreValid && (this.validator ? this.validator(this.items) : true);
|
||||
const valid = Array.from(this.inputGroups || []).every((inputGroup) => {
|
||||
return inputGroup.querySelector<AkControlElement>("[name]")?.valid ?? true;
|
||||
});
|
||||
|
||||
return valid && (this.validator?.(this.items) ?? true);
|
||||
}
|
||||
|
||||
itemsFromDom(): T[] {
|
||||
|
||||
@@ -40,7 +40,7 @@ const metadata: Meta<IArrayInput<unknown>> = {
|
||||
return;
|
||||
}
|
||||
const target = event.target as FooterLinkInput;
|
||||
messages!.innerText = `${JSON.stringify(target.json(), null, 2)}\n\nValid: ${target.isValid ? "Yes" : "No"}`;
|
||||
messages!.innerText = `${JSON.stringify(target.json(), null, 2)}\n\nValid: ${target.valid ? "Yes" : "No"}`;
|
||||
});
|
||||
}, 250);
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ describe("ak-array-input", () => {
|
||||
await component();
|
||||
const link = await $("ak-array-input");
|
||||
await browser.pause(500);
|
||||
await expect(await link.getProperty("isValid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("valid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("toJson")).toEqual([]);
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ describe("ak-array-input", () => {
|
||||
await component(sampleItems);
|
||||
const link = await $("ak-array-input");
|
||||
await browser.pause(500);
|
||||
await expect(await link.getProperty("isValid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("valid")).toStrictEqual(true);
|
||||
await expect(await link.getProperty("toJson")).toEqual(sampleItems);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -15,6 +15,12 @@ export function isNamedElement(element: Element): element is NamedElement {
|
||||
return "name" in element.attributes;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"[name]": NamedElement<HTMLElement>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a map of files provided by input elements within the given iterable.
|
||||
*/
|
||||
|
||||
@@ -55,7 +55,7 @@ export class ActionWizardPage extends WizardPage {
|
||||
await this.run();
|
||||
|
||||
// Ensure wizard is closable, even when run() failed
|
||||
this.host.isValid = true;
|
||||
this.host.valid = true;
|
||||
};
|
||||
|
||||
sidebarLabel = () => msg("Apply changes");
|
||||
@@ -91,7 +91,7 @@ export class ActionWizardPage extends WizardPage {
|
||||
}
|
||||
}
|
||||
|
||||
this.host.isValid = true;
|
||||
this.host.valid = true;
|
||||
|
||||
this.dispatchEvent(
|
||||
new CustomEvent(EVENT_REFRESH, {
|
||||
|
||||
@@ -15,7 +15,7 @@ export class FormWizardPage extends WizardPage {
|
||||
};
|
||||
|
||||
activeCallback = async () => {
|
||||
this.host.isValid = true;
|
||||
this.host.valid = true;
|
||||
this.activePageCallback(this);
|
||||
};
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ export class TypeCreateWizardPage extends WithLicenseSummary(WizardPage) {
|
||||
activeCallback = (): void => {
|
||||
const form = this.formRef.value;
|
||||
|
||||
this.host.isValid = form?.checkValidity() ?? false;
|
||||
this.host.valid = form?.checkValidity() ?? false;
|
||||
|
||||
if (this.selectedType) {
|
||||
this.selectDispatch(this.selectedType);
|
||||
|
||||
@@ -64,7 +64,7 @@ export class Wizard extends ModalButton {
|
||||
* Whether the wizard is valid and can proceed to the next step.
|
||||
*/
|
||||
@property({ type: Boolean })
|
||||
isValid = false;
|
||||
valid = false;
|
||||
|
||||
/**
|
||||
* Actions to display at the end of the wizard.
|
||||
@@ -328,7 +328,7 @@ export class Wizard extends ModalButton {
|
||||
<footer class="pf-c-wizard__footer">
|
||||
<button
|
||||
class="pf-c-button pf-m-primary"
|
||||
?disabled=${!this.isValid}
|
||||
?disabled=${!this.valid}
|
||||
type="button"
|
||||
@click=${navigateNextListener}
|
||||
>
|
||||
|
||||
@@ -50,7 +50,7 @@ export class WizardPage extends AKElement {
|
||||
* Called when this is the page brought into view.
|
||||
*/
|
||||
activeCallback: WizardPageActiveCallback = () => {
|
||||
this.host.isValid = false;
|
||||
this.host.valid = false;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -59,7 +59,7 @@ export class AkRememberMeController implements ReactiveController {
|
||||
) as HTMLInputElement | null;
|
||||
}
|
||||
|
||||
get isValidChallenge() {
|
||||
get validChallenge() {
|
||||
return !(
|
||||
this.host.challenge.responseErrors &&
|
||||
this.host.challenge.responseErrors.non_field_errors &&
|
||||
|
||||
Reference in New Issue
Block a user