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>
import RelationshipField from "./RelationshipField.svelte"
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>
<RelationshipField
{...$$props}
datasourceType={"user"}
primaryDisplay={"email"}
valueConversion={value => {
if (Array.isArray(value)) {
return value.map(val => sdk.users.getGlobalUserID(val))
} else {
return sdk.users.getGlobalUserID(value)
}
defaultValue={updateReferences(defaultValue)}
onChange={value => {
return updateReferences(value)
}}
/>

View File

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

View File

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