Files
windmill/frontend/src/lib/components/LightweightObjectResourceInput.svelte
Ruben Fiszel 5877727c16 feat: allow user resources in apps with a toggle (#3821)
* all

* all

* all

* all

* all

* all

* all

* all

* all

* all

* nits

* nits
2024-05-27 07:51:49 +02:00

46 lines
939 B
Svelte

<script lang="ts">
import LightweightResourcePicker from './LightweightResourcePicker.svelte'
export let format: string
export let value: any
export let disablePortal = false
function isString(value: any) {
return typeof value === 'string' || value instanceof String
}
let path: string = ''
function resourceToValue() {
if (path) {
value = `$res:${path}`
} else {
value = undefined
}
}
function isResource() {
return isString(value) && value.length >= '$res:'.length
}
function valueToPath() {
if (isResource()) {
path = value.substr('$res:'.length)
}
}
$: value && valueToPath()
</script>
<div class="flex flex-row w-full flex-wrap gap-x-2 gap-y-0.5">
<LightweightResourcePicker
{disablePortal}
on:change={(e) => {
path = e.detail
resourceToValue()
}}
bind:value={path}
resourceType={format.split('-').length > 1 ? format.substring('resource-'.length) : undefined}
/>
</div>