Merge pull request #2147 from mslourens/prevent_space_in_url

replace spaces with underscores in screen routes
This commit is contained in:
Martin McKeaveney 2021-08-06 21:42:47 +01:00 committed by GitHub
commit 725e64f9cb
4 changed files with 23 additions and 6 deletions

View File

@ -7,5 +7,15 @@ context("Screen Tests", () => {
it("Should successfully create a screen", () => {
cy.createScreen("Test Screen", "/test")
cy.get(".nav-items-container").within(() => {
cy.contains("/test").should("exist")
})
})
it("Should update the url", () => {
cy.createScreen("Test Screen", "test with spaces")
cy.get(".nav-items-container").within(() => {
cy.contains("/test-with-spaces").should("exist")
})
})
})

View File

@ -160,7 +160,4 @@ Cypress.Commands.add("createScreen", (screenName, route) => {
cy.get("input").eq(1).type(route)
cy.get(".spectrum-Button--cta").click()
})
cy.get(".nav-items-container").within(() => {
cy.contains(route).should("exist")
})
})

View File

@ -84,6 +84,7 @@
if (!event.detail.startsWith("/")) {
route = "/" + event.detail
}
route = route.replaceAll(" ", "-")
}
</script>

View File

@ -11,7 +11,11 @@
export let componentInstance
export let bindings
function setAssetProps(name, value) {
function setAssetProps(name, value, parser) {
if (parser && typeof parser === "function") {
value = parser(value)
}
const selectedAsset = get(currentAsset)
store.update(state => {
if (
@ -29,7 +33,12 @@
const screenSettings = [
// { key: "description", label: "Description", control: Input },
{ key: "routing.route", label: "Route", control: Input },
{
key: "routing.route",
label: "Route",
control: Input,
parser: val => val.replaceAll(" ", "-"),
},
{ key: "routing.roleId", label: "Access", control: RoleSelect },
{ key: "layoutId", label: "Layout", control: LayoutSelect },
]
@ -44,7 +53,7 @@
label={def.label}
key={def.key}
value={deepGet($currentAsset, def.key)}
onChange={val => setAssetProps(def.key, val)}
on:change={event => setAssetProps(def.key, event.detail, def.parser)}
{bindings}
/>
{/each}