Prevent update a screen URL to an existing URL for the same role
This commit is contained in:
parent
aeea15e8db
commit
e61e3ddf27
|
@ -8,14 +8,41 @@
|
||||||
import { currentAsset, store } from "builderStore"
|
import { currentAsset, store } from "builderStore"
|
||||||
import { FrontendTypes } from "constants"
|
import { FrontendTypes } from "constants"
|
||||||
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl"
|
import sanitizeUrl from "builderStore/store/screenTemplates/utils/sanitizeUrl"
|
||||||
|
import { allScreens, selectedAccessRole } from "builderStore"
|
||||||
|
|
||||||
export let componentInstance
|
export let componentInstance
|
||||||
export let bindings
|
export let bindings
|
||||||
|
|
||||||
function setAssetProps(name, value, parser) {
|
let errors = {}
|
||||||
if (parser && typeof parser === "function") {
|
|
||||||
|
const routeExists = url => {
|
||||||
|
const roleId = get(selectedAccessRole) || "BASIC"
|
||||||
|
return get(allScreens).some(
|
||||||
|
screen =>
|
||||||
|
screen.routing.route.toLowerCase() === url.toLowerCase() &&
|
||||||
|
screen.routing.roleId === roleId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const setAssetProps = (name, value, parser, validate) => {
|
||||||
|
if (parser) {
|
||||||
value = parser(value)
|
value = parser(value)
|
||||||
}
|
}
|
||||||
|
if (validate) {
|
||||||
|
const error = validate(value)
|
||||||
|
errors = {
|
||||||
|
...errors,
|
||||||
|
[name]: error,
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
errors = {
|
||||||
|
...errors,
|
||||||
|
[name]: null,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const selectedAsset = get(currentAsset)
|
const selectedAsset = get(currentAsset)
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
|
@ -38,7 +65,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const screenSettings = [
|
const screenSettings = [
|
||||||
// { key: "description", label: "Description", control: Input },
|
|
||||||
{
|
{
|
||||||
key: "routing.route",
|
key: "routing.route",
|
||||||
label: "Route",
|
label: "Route",
|
||||||
|
@ -49,6 +75,13 @@
|
||||||
}
|
}
|
||||||
return sanitizeUrl(val)
|
return sanitizeUrl(val)
|
||||||
},
|
},
|
||||||
|
validate: val => {
|
||||||
|
const exisingValue = deepGet($currentAsset, "routing.route")
|
||||||
|
if (val !== exisingValue && routeExists(val)) {
|
||||||
|
return "That URL is already in use"
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{ key: "routing.roleId", label: "Access", control: RoleSelect },
|
{ key: "routing.roleId", label: "Access", control: RoleSelect },
|
||||||
{ key: "layoutId", label: "Layout", control: LayoutSelect },
|
{ key: "layoutId", label: "Layout", control: LayoutSelect },
|
||||||
|
@ -62,9 +95,11 @@
|
||||||
control={def.control}
|
control={def.control}
|
||||||
label={def.label}
|
label={def.label}
|
||||||
key={def.key}
|
key={def.key}
|
||||||
|
error="asdasds"
|
||||||
value={deepGet($currentAsset, def.key)}
|
value={deepGet($currentAsset, def.key)}
|
||||||
onChange={val => setAssetProps(def.key, val, def.parser)}
|
onChange={val => setAssetProps(def.key, val, def.parser, def.validate)}
|
||||||
{bindings}
|
{bindings}
|
||||||
|
props={{ error: errors[def.key] }}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
</DetailSummary>
|
</DetailSummary>
|
||||||
|
|
Loading…
Reference in New Issue