2020-08-21 17:10:56 +02:00
|
|
|
<script>
|
2020-09-28 12:50:29 +02:00
|
|
|
import { Button, Icon, DropdownMenu, Spacer, Heading } from "@budibase/bbui"
|
2020-08-24 17:26:00 +02:00
|
|
|
import { createEventDispatcher } from "svelte"
|
2020-10-09 13:24:18 +02:00
|
|
|
import { store, backendUiStore } from "builderStore"
|
|
|
|
import fetchBindableProperties from "../../builderStore/fetchBindableProperties"
|
2020-08-21 17:10:56 +02:00
|
|
|
|
2020-08-24 17:26:00 +02:00
|
|
|
const dispatch = createEventDispatcher()
|
2020-09-28 12:50:29 +02:00
|
|
|
let anchorRight, dropdownRight
|
2020-08-21 17:10:56 +02:00
|
|
|
|
2020-08-24 17:26:00 +02:00
|
|
|
export let value = {}
|
|
|
|
|
|
|
|
function handleSelected(selected) {
|
|
|
|
dispatch("change", selected)
|
2020-10-05 15:02:33 +02:00
|
|
|
dropdownRight.hide()
|
2020-08-24 17:26:00 +02:00
|
|
|
}
|
2020-08-21 17:10:56 +02:00
|
|
|
|
2020-10-13 10:58:08 +02:00
|
|
|
$: tables = $backendUiStore.tables.map(m => ({
|
2020-08-24 17:26:00 +02:00
|
|
|
label: m.name,
|
|
|
|
name: `all_${m._id}`,
|
2020-10-09 19:49:23 +02:00
|
|
|
tableId: m._id,
|
2020-10-13 10:58:08 +02:00
|
|
|
type: "table",
|
2020-08-21 17:10:56 +02:00
|
|
|
}))
|
|
|
|
|
2020-10-13 10:58:08 +02:00
|
|
|
$: views = $backendUiStore.tables.reduce((acc, cur) => {
|
2020-08-21 17:10:56 +02:00
|
|
|
let viewsArr = Object.entries(cur.views).map(([key, value]) => ({
|
2020-08-24 17:26:00 +02:00
|
|
|
label: key,
|
2020-08-21 17:10:56 +02:00
|
|
|
name: key,
|
2020-08-26 18:03:30 +02:00
|
|
|
...value,
|
2020-10-09 13:24:18 +02:00
|
|
|
type: "view",
|
2020-08-21 17:10:56 +02:00
|
|
|
}))
|
|
|
|
return [...acc, ...viewsArr]
|
|
|
|
}, [])
|
2020-10-09 13:24:18 +02:00
|
|
|
|
|
|
|
$: bindableProperties = fetchBindableProperties({
|
|
|
|
componentInstanceId: $store.currentComponentInfo._id,
|
|
|
|
components: $store.components,
|
|
|
|
screen: $store.currentPreviewItem,
|
2020-10-13 10:58:08 +02:00
|
|
|
tables: $backendUiStore.tables,
|
2020-10-09 13:24:18 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
$: links = bindableProperties
|
|
|
|
.filter(x => x.fieldSchema.type === "link")
|
|
|
|
.map(property => ({
|
|
|
|
label: property.readableBinding,
|
|
|
|
fieldName: property.fieldSchema.name,
|
2020-10-13 10:58:08 +02:00
|
|
|
name: `all_${property.fieldSchema.tableId}`,
|
|
|
|
tableId: property.fieldSchema.tableId,
|
2020-10-09 13:24:18 +02:00
|
|
|
type: "link",
|
|
|
|
}))
|
2020-08-21 17:10:56 +02:00
|
|
|
</script>
|
|
|
|
|
2020-10-12 16:13:38 +02:00
|
|
|
<div
|
|
|
|
class="dropdownbutton"
|
|
|
|
bind:this={anchorRight}
|
|
|
|
on:click={dropdownRight.show}>
|
2020-10-13 10:58:08 +02:00
|
|
|
<span>{value.label ? value.label : 'Table / View'}</span>
|
2020-10-12 16:13:38 +02:00
|
|
|
<Icon name="arrowdown" />
|
2020-08-21 17:10:56 +02:00
|
|
|
</div>
|
2020-09-28 12:50:29 +02:00
|
|
|
<DropdownMenu bind:this={dropdownRight} anchor={anchorRight}>
|
|
|
|
<div class="dropdown">
|
|
|
|
<div class="title">
|
|
|
|
<Heading extraSmall>Tables</Heading>
|
|
|
|
</div>
|
2020-08-21 17:10:56 +02:00
|
|
|
<ul>
|
2020-10-09 19:49:23 +02:00
|
|
|
{#each tables as table}
|
2020-08-21 17:10:56 +02:00
|
|
|
<li
|
2020-10-09 19:49:23 +02:00
|
|
|
class:selected={value === table}
|
|
|
|
on:click={() => handleSelected(table)}>
|
|
|
|
{table.label}
|
2020-08-21 17:10:56 +02:00
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
|
|
|
<hr />
|
2020-09-28 12:50:29 +02:00
|
|
|
<div class="title">
|
|
|
|
<Heading extraSmall>Views</Heading>
|
|
|
|
</div>
|
2020-08-21 17:10:56 +02:00
|
|
|
<ul>
|
|
|
|
{#each views as view}
|
|
|
|
<li
|
2020-08-24 17:26:00 +02:00
|
|
|
class:selected={value === view}
|
|
|
|
on:click={() => handleSelected(view)}>
|
|
|
|
{view.label}
|
2020-08-21 17:10:56 +02:00
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
2020-10-09 13:24:18 +02:00
|
|
|
<hr />
|
|
|
|
<div class="title">
|
|
|
|
<Heading extraSmall>Relationships</Heading>
|
|
|
|
</div>
|
|
|
|
<ul>
|
|
|
|
{#each links as link}
|
|
|
|
<li
|
|
|
|
class:selected={value === link}
|
|
|
|
on:click={() => handleSelected(link)}>
|
|
|
|
{link.label}
|
|
|
|
</li>
|
|
|
|
{/each}
|
|
|
|
</ul>
|
2020-08-21 17:10:56 +02:00
|
|
|
</div>
|
|
|
|
</DropdownMenu>
|
|
|
|
|
|
|
|
<style>
|
2020-09-28 12:50:29 +02:00
|
|
|
.dropdownbutton {
|
2020-10-12 16:13:38 +02:00
|
|
|
background-color: var(--grey-2);
|
|
|
|
border: var(--border-transparent);
|
|
|
|
padding: var(--spacing-m);
|
|
|
|
border-radius: var(--border-radius-m);
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: space-between;
|
|
|
|
align-items: center;
|
|
|
|
overflow: hidden;
|
|
|
|
flex: 1 1 auto;
|
2020-08-21 17:10:56 +02:00
|
|
|
}
|
2020-10-12 16:13:38 +02:00
|
|
|
.dropdownbutton:hover {
|
|
|
|
cursor: pointer;
|
|
|
|
background-color: var(--grey-3);
|
2020-08-21 17:10:56 +02:00
|
|
|
}
|
2020-10-12 16:13:38 +02:00
|
|
|
.dropdownbutton span {
|
|
|
|
white-space: nowrap;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
flex: 1 1 auto;
|
|
|
|
text-align: left;
|
|
|
|
font-size: var(--font-size-xs);
|
|
|
|
}
|
|
|
|
.dropdownbutton :global(svg) {
|
|
|
|
margin: -4px 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 12:50:29 +02:00
|
|
|
.dropdown {
|
|
|
|
padding: var(--spacing-m) 0;
|
2020-09-28 13:19:11 +02:00
|
|
|
z-index: 99999999;
|
2020-08-21 17:10:56 +02:00
|
|
|
}
|
2020-09-28 12:50:29 +02:00
|
|
|
.title {
|
|
|
|
padding: 0 var(--spacing-m) var(--spacing-xs) var(--spacing-m);
|
2020-08-21 17:10:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hr {
|
2020-09-28 12:50:29 +02:00
|
|
|
margin: var(--spacing-m) 0 var(--spacing-xl) 0;
|
2020-08-21 17:10:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ul {
|
|
|
|
list-style: none;
|
|
|
|
padding-left: 0px;
|
|
|
|
margin: 0px;
|
|
|
|
}
|
|
|
|
|
|
|
|
li {
|
|
|
|
cursor: pointer;
|
|
|
|
margin: 0px;
|
2020-09-28 12:50:29 +02:00
|
|
|
padding: var(--spacing-s) var(--spacing-m);
|
|
|
|
font-size: var(--font-size-xs);
|
2020-08-21 17:10:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.selected {
|
|
|
|
background-color: var(--grey-4);
|
|
|
|
}
|
|
|
|
|
|
|
|
li:hover {
|
|
|
|
background-color: var(--grey-4);
|
|
|
|
}
|
|
|
|
</style>
|