forked from tsai/budibase
12 changed files with 130 additions and 39 deletions
@ -1,18 +1,75 @@ |
|||||
<script> |
<script> |
||||
import { DataList } from "@budibase/bbui" |
import { DataList } from "@budibase/bbui" |
||||
import { createEventDispatcher } from "svelte" |
import { createEventDispatcher } from "svelte" |
||||
import { store } from "builderStore" |
import { store, backendUiStore } from "builderStore" |
||||
|
import fetchBindableProperties from "builderStore/fetchBindableProperties" |
||||
|
|
||||
const dispatch = createEventDispatcher() |
const dispatch = createEventDispatcher() |
||||
|
|
||||
export let value = "" |
export let value = "" |
||||
|
|
||||
|
$: urls = getUrls() |
||||
|
|
||||
const handleBlur = () => dispatch("change", value) |
const handleBlur = () => dispatch("change", value) |
||||
|
|
||||
|
// this will get urls of all screens, but only |
||||
|
// choose detail screens that are usable in the current context |
||||
|
// and substitute the :id param for the actual {{ ._id }} binding |
||||
|
const getUrls = () => { |
||||
|
const urls = [ |
||||
|
...$store.screens |
||||
|
.filter(screen => !screen.props._component.endsWith("/rowdetail")) |
||||
|
.map(screen => ({ |
||||
|
name: screen.props._instanceName, |
||||
|
url: screen.route, |
||||
|
sort: screen.props._component, |
||||
|
})), |
||||
|
] |
||||
|
|
||||
|
const bindableProperties = fetchBindableProperties({ |
||||
|
componentInstanceId: $store.currentComponentInfo._id, |
||||
|
components: $store.components, |
||||
|
screen: $store.currentPreviewItem, |
||||
|
tables: $backendUiStore.tables, |
||||
|
}) |
||||
|
|
||||
|
const detailScreens = $store.screens.filter(screen => |
||||
|
screen.props._component.endsWith("/rowdetail") |
||||
|
) |
||||
|
|
||||
|
for (let detailScreen of detailScreens) { |
||||
|
const idBinding = bindableProperties.find(p => { |
||||
|
if ( |
||||
|
p.type === "context" && |
||||
|
p.runtimeBinding.endsWith("._id") && |
||||
|
p.table |
||||
|
) { |
||||
|
const tableId = |
||||
|
typeof p.table === "string" ? p.table : p.table.tableId |
||||
|
return tableId === detailScreen.props.table |
||||
|
} |
||||
|
return false |
||||
|
}) |
||||
|
|
||||
|
if (idBinding) { |
||||
|
urls.push({ |
||||
|
name: detailScreen.props._instanceName, |
||||
|
url: detailScreen.route.replace( |
||||
|
":id", |
||||
|
`{{ ${idBinding.runtimeBinding} }}` |
||||
|
), |
||||
|
sort: detailScreen.props._component, |
||||
|
}) |
||||
|
} |
||||
|
|
||||
|
return urls |
||||
|
} |
||||
|
} |
||||
</script> |
</script> |
||||
|
|
||||
<DataList editable secondary on:blur={handleBlur} on:change bind:value> |
<DataList editable secondary on:blur={handleBlur} on:change bind:value> |
||||
<option value="" /> |
<option value="" /> |
||||
{#each $store.allScreens as screen} |
{#each urls as url} |
||||
<option value={screen.route}>{screen.props._instanceName}</option> |
<option value={url.url}>{url.name}</option> |
||||
{/each} |
{/each} |
||||
</DataList> |
</DataList> |
||||
|
|||||
Loading…
Reference in new issue