-
-
Notifications
You must be signed in to change notification settings - Fork 909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
web/admin: better footer links #12004
Open
kensternberg-authentik
wants to merge
17
commits into
main
Choose a base branch
from
web/admin/better-footer-links
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
89dad07
web: Add InvalidationFlow to Radius Provider dialogues
kensternberg-authentik 914993a
Merge branch 'main' into dev
kensternberg-authentik f25a9c6
Merge branch 'main' into dev
kensternberg-authentik e0d5df8
Merge branch 'main' into dev
kensternberg-authentik 7579090
Merge branch 'main' into dev
kensternberg-authentik 3244276
Merge branch 'main' into dev
kensternberg-authentik 5cc2c0f
Merge branch 'main' into dev
kensternberg-authentik 831797b
Merge branch 'main' into dev
kensternberg-authentik 518299a
First things first: save the blueprint that initializes the test runner.
kensternberg-authentik 65a2b1d
Committing to having the PKs be a string, and streamlining an event h…
kensternberg-authentik c2b8217
web/admin/better-footer-links
kensternberg-authentik 75708f1
Not ready for prime time.
kensternberg-authentik cd62f31
One lint. Other lints are still in progress.
kensternberg-authentik afcf0e7
web: lots of 'as unknown as Foo'
kensternberg-authentik 5d874cb
web/admin/better-footer-links
kensternberg-authentik 48a24ad
Merge branch 'main' into web/admin/better-footer-links
kensternberg-authentik 2806451
Ensure the UI is built from _current_ before running tests.
kensternberg-authentik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
100 changes: 100 additions & 0 deletions
100
web/src/admin/admin-settings/AdminSettingsFooterLinks.ts
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { AkControlElement } from "@goauthentik/elements/AkControlElement.js"; | ||
import { type Spread } from "@goauthentik/elements/types"; | ||
import { spread } from "@open-wc/lit-helpers"; | ||
|
||
import { msg } from "@lit/localize"; | ||
import { css, html } from "lit"; | ||
import { customElement, property, queryAll } from "lit/decorators.js"; | ||
import { ifDefined } from "lit/directives/if-defined.js"; | ||
|
||
import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css"; | ||
import PFInputGroup from "@patternfly/patternfly/components/InputGroup/input-group.css"; | ||
import PFBase from "@patternfly/patternfly/patternfly-base.css"; | ||
|
||
import { FooterLink } from "@goauthentik/api"; | ||
|
||
export interface IFooterLinkInput { | ||
footerLink: FooterLink; | ||
} | ||
|
||
const LEGAL_SCHEMES = ["http://", "https://", "mailto:"]; | ||
const hasLegalScheme = (url: string) => | ||
LEGAL_SCHEMES.some((scheme) => url.substr(0, scheme.length).toLowerCase() === scheme); | ||
|
||
@customElement("ak-admin-settings-footer-link") | ||
export class FooterLinkInput extends AkControlElement<FooterLink> { | ||
static get styles() { | ||
return [ | ||
PFBase, | ||
PFInputGroup, | ||
PFFormControl, | ||
css` | ||
.pf-c-input-group input#linkname { | ||
flex-grow: 1; | ||
width: 8rem; | ||
} | ||
`, | ||
]; | ||
} | ||
|
||
@property({ type: Object, attribute: false }) | ||
footerLink: FooterLink = { | ||
name: "", | ||
href: "", | ||
}; | ||
|
||
@queryAll(".ak-form-control") | ||
controls?: HTMLInputElement[]; | ||
|
||
json() { | ||
return Object.fromEntries( | ||
Array.from(this.controls ?? []).map((control) => [control.name, control.value]), | ||
) as unknown as FooterLink; | ||
} | ||
|
||
get isValid() { | ||
const href = this.json()?.href ?? ""; | ||
return hasLegalScheme(href) && URL.canParse(href); | ||
} | ||
|
||
render() { | ||
const onChange = () => { | ||
this.dispatchEvent(new Event("change", { composed: true, bubbles: true })); | ||
}; | ||
|
||
return html` <div class="pf-c-input-group"> | ||
<input | ||
type="text" | ||
@change=${onChange} | ||
value=${this.footerLink.name} | ||
id="linkname" | ||
class="pf-c-form-control ak-form-control" | ||
name="name" | ||
placeholder=${msg("Link Title")} | ||
tabindex="1" | ||
/> | ||
<input | ||
type="text" | ||
@change=${onChange} | ||
value="${ifDefined(this.footerLink.href ?? undefined)}" | ||
class="pf-c-form-control ak-form-control" | ||
required | ||
placeholder=${msg("URL")} | ||
name="href" | ||
tabindex="1" | ||
/> | ||
</div>`; | ||
} | ||
} | ||
|
||
export function akFooterLinkInput(properties: IFooterLinkInput) { | ||
return html`<ak-admin-settings-footer-link | ||
${spread(properties as unknown as Spread)} | ||
></ak-admin-settings-footer-link>`; | ||
} | ||
|
||
declare global { | ||
interface HTMLElementTagNameMap { | ||
"ak-admin-settings-footer-link": FooterLinkInput; | ||
} | ||
} |
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
80 changes: 80 additions & 0 deletions
80
web/src/admin/admin-settings/stories/AdminSettingsFooterLinks.stories.ts
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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import "@goauthentik/elements/messages/MessageContainer"; | ||
import { Meta, StoryObj, WebComponentsRenderer } from "@storybook/web-components"; | ||
import { DecoratorFunction } from "storybook/internal/types"; | ||
|
||
import { html } from "lit"; | ||
|
||
import { FooterLinkInput } from "../AdminSettingsFooterLinks.js"; | ||
import "../AdminSettingsFooterLinks.js"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
type Decorator = DecoratorFunction<WebComponentsRenderer, any>; | ||
|
||
const metadata: Meta<FooterLinkInput> = { | ||
title: "Components / Footer Link Input", | ||
component: "ak-admin-settings-footer-link", | ||
parameters: { | ||
docs: { | ||
description: { | ||
component: "A stylized control for the footer links", | ||
}, | ||
}, | ||
}, | ||
decorators: [ | ||
(story: Decorator) => { | ||
window.setTimeout(() => { | ||
const control = document.getElementById("footer-link"); | ||
if (!control) { | ||
throw new Error("Test was not initialized correctly."); | ||
} | ||
const messages = document.getElementById("reported-value"); | ||
control.addEventListener("change", (event: Event) => { | ||
if (!event.target) { | ||
return; | ||
} | ||
const target = event.target as FooterLinkInput; | ||
messages!.innerText = `${JSON.stringify(target.json(), null, 2)}\n\nValid: ${target.isValid ? "Yes" : "No"}`; | ||
}); | ||
}, 250); | ||
|
||
return html`<div | ||
style="background: #fff; padding: 2em; position: relative" | ||
id="the-main-event" | ||
> | ||
<style> | ||
li { | ||
display: block; | ||
} | ||
p { | ||
margin-top: 1em; | ||
} | ||
#the-answer-block { | ||
padding-top: 3em; | ||
} | ||
</style> | ||
<div> | ||
${ | ||
// @ts-expect-error The types for web components are not well-defined } | ||
story() | ||
} | ||
</div> | ||
<div style="margin-top: 2rem"> | ||
<p>Reported value:</p> | ||
<pre id="reported-value"></pre> | ||
</div> | ||
</div>`; | ||
}, | ||
], | ||
}; | ||
|
||
export default metadata; | ||
|
||
type Story = StoryObj; | ||
|
||
export const Default: Story = { | ||
render: () => | ||
html` <ak-admin-settings-footer-link | ||
id="footer-link" | ||
name="the-footer" | ||
></ak-admin-settings-footer-link>`, | ||
}; |
68 changes: 68 additions & 0 deletions
68
web/src/admin/admin-settings/stories/AdminSettingsFooterLinks.test.ts
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { render } from "@goauthentik/elements/tests/utils.js"; | ||
import { $, expect } from "@wdio/globals"; | ||
|
||
import { html } from "lit"; | ||
|
||
import "../AdminSettingsFooterLinks.js"; | ||
|
||
describe("ak-admin-settings-footer-link", () => { | ||
afterEach(async () => { | ||
await browser.execute(async () => { | ||
await document.body.querySelector("ak-admin-settings-footer-link")?.remove(); | ||
if (document.body["_$litPart$"]) { | ||
// @ts-expect-error expression of type '"_$litPart$"' is added by Lit | ||
await delete document.body["_$litPart$"]; | ||
} | ||
}); | ||
}); | ||
|
||
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("toJson")).toEqual({ name: "", href: "" }); | ||
}); | ||
|
||
it("should not be valid if just a name is filled in", async () => { | ||
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("toJson")).toEqual({ name: "foo", href: "" }); | ||
}); | ||
|
||
it("should be valid if just a URL is filled in", async () => { | ||
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("toJson")).toEqual({ | ||
name: "", | ||
href: "https://foo.com", | ||
}); | ||
}); | ||
|
||
it("should be valid if both are filled in", async () => { | ||
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 link.$('input[name="href"]').setValue("https://foo.com"); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(true); | ||
await expect(await link.getProperty("toJson")).toEqual({ | ||
name: "foo", | ||
href: "https://foo.com", | ||
}); | ||
}); | ||
|
||
it("should not be valid if the URL is not valid", async () => { | ||
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 link.$('input[name="href"]').setValue("never://foo.com"); | ||
await expect(await link.getProperty("toJson")).toEqual({ | ||
name: "foo", | ||
href: "never://foo.com", | ||
}); | ||
await expect(await link.getProperty("isValid")).toStrictEqual(false); | ||
}); | ||
}); |
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better type controls led to better type checking.