PR comments.

This commit is contained in:
mike12345567 2023-10-10 11:22:59 +01:00
parent 2ef5cb3894
commit 95caee66a7
3 changed files with 29 additions and 11 deletions

View File

@ -1,17 +1,31 @@
<script> <script>
import RelationshipField from "./RelationshipField.svelte" import RelationshipField from "./RelationshipField.svelte"
import { sdk } from "@budibase/shared-core" import { sdk } from "@budibase/shared-core"
export let defaultValue
function updateUserIDs(value) {
if (Array.isArray(value)) {
return value.map(val => sdk.users.getGlobalUserID(val))
} else {
return sdk.users.getGlobalUserID(value)
}
}
function updateReferences(value) {
if (sdk.users.containsUserID(value)) {
return updateUserIDs(value)
}
return value
}
</script> </script>
<RelationshipField <RelationshipField
{...$$props} {...$$props}
datasourceType={"user"} datasourceType={"user"}
primaryDisplay={"email"} primaryDisplay={"email"}
valueConversion={value => { defaultValue={updateReferences(defaultValue)}
if (Array.isArray(value)) { onChange={value => {
return value.map(val => sdk.users.getGlobalUserID(val)) return updateReferences(value)
} else {
return sdk.users.getGlobalUserID(value)
}
}} }}
/> />

View File

@ -18,7 +18,6 @@
export let filter export let filter
export let datasourceType = "table" export let datasourceType = "table"
export let primaryDisplay export let primaryDisplay
export let valueConversion
let fieldState let fieldState
let fieldApi let fieldApi
@ -162,7 +161,7 @@
const changed = fieldApi.setValue(value) const changed = fieldApi.setValue(value)
if (onChange && changed) { if (onChange && changed) {
onChange({ onChange({
value: valueConversion ? valueConversion(value) : value, value,
}) })
} }
} }
@ -179,9 +178,7 @@
{field} {field}
{disabled} {disabled}
{validation} {validation}
defaultValue={valueConversion defaultValue={expandedDefaultValue}
? valueConversion(expandedDefaultValue)
: expandedDefaultValue}
{type} {type}
bind:fieldState bind:fieldState
bind:fieldApi bind:fieldApi

View File

@ -84,3 +84,10 @@ export function getGlobalUserID(userId?: string): string | undefined {
} }
return userId.split(prefix)[1] return userId.split(prefix)[1]
} }
export function containsUserID(value: string | undefined): boolean {
if (typeof value !== "string") {
return false
}
return value.includes(`${DocumentType.USER}${SEPARATOR}`)
}