relationships E2E
This commit is contained in:
parent
08393044c9
commit
edcf3161a3
|
@ -1,20 +1,21 @@
|
||||||
<script>
|
<script>
|
||||||
import { RelationshipTypes } from "constants/backend"
|
import { RelationshipTypes } from "constants/backend"
|
||||||
import { Menu, MenuItem, MenuSection, Button, Input, Icon, ModalContent, RadioGroup, Heading } from "@budibase/bbui"
|
import { Menu, MenuItem, MenuSection, Button, Input, Icon, ModalContent, RadioGroup, Heading } from "@budibase/bbui"
|
||||||
|
import { tables } from "stores/backend"
|
||||||
|
|
||||||
export let save
|
export let save
|
||||||
export let datasource
|
export let datasource
|
||||||
export let from
|
export let from
|
||||||
export let tables
|
export let plusTables
|
||||||
export let relationship = {}
|
export let relationship = {}
|
||||||
|
|
||||||
let originalName = relationship.name
|
let originalName = relationship.name
|
||||||
|
|
||||||
$: console.log(relationship)
|
$: console.log(relationship)
|
||||||
$: valid = relationship.name && relationship.tableId && relationship.relationshipType
|
$: valid = relationship.name && relationship.tableId && relationship.relationshipType
|
||||||
$: from = tables.find(table => table._id === relationship.source)
|
$: from = plusTables.find(table => table._id === relationship.source)
|
||||||
$: to = tables.find(table => table._id === relationship.tableId)
|
$: to = plusTables.find(table => table._id === relationship.tableId)
|
||||||
$: through = tables.find(table => table._id === relationship.through)
|
$: through = plusTables.find(table => table._id === relationship.through)
|
||||||
$: linkTable = through || to
|
$: linkTable = through || to
|
||||||
|
|
||||||
$: relationshipOptions = from && to ? [
|
$: relationshipOptions = from && to ? [
|
||||||
|
@ -43,11 +44,11 @@
|
||||||
...relationship
|
...relationship
|
||||||
}
|
}
|
||||||
if (originalName) {
|
if (originalName) {
|
||||||
// TODO: possible bug if you change name
|
delete datasource.entities[from.name].schema[originalName]
|
||||||
delete datasource.entities[from.name][originalName]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
save()
|
save()
|
||||||
|
tables.fetch()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -63,7 +64,7 @@
|
||||||
<div class="table-selector">
|
<div class="table-selector">
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuSection heading="From">
|
<MenuSection heading="From">
|
||||||
{#each tables as table}
|
{#each plusTables as table}
|
||||||
<MenuItem noClose icon="Table" on:click={() => (relationship.source = table._id)}>
|
<MenuItem noClose icon="Table" on:click={() => (relationship.source = table._id)}>
|
||||||
{table.name}
|
{table.name}
|
||||||
{#if relationship.source === table._id}
|
{#if relationship.source === table._id}
|
||||||
|
@ -75,7 +76,7 @@
|
||||||
</Menu>
|
</Menu>
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuSection heading="To">
|
<MenuSection heading="To">
|
||||||
{#each tables as table}
|
{#each plusTables as table}
|
||||||
<MenuItem noClose icon="Table" on:click={() => (relationship.tableId = table._id)}>
|
<MenuItem noClose icon="Table" on:click={() => (relationship.tableId = table._id)}>
|
||||||
{table.name}
|
{table.name}
|
||||||
{#if relationship.tableId === table._id}
|
{#if relationship.tableId === table._id}
|
||||||
|
@ -102,7 +103,7 @@
|
||||||
{#if relationship?.relationshipType === RelationshipTypes.MANY_TO_MANY}
|
{#if relationship?.relationshipType === RelationshipTypes.MANY_TO_MANY}
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuSection heading="Join Table">
|
<MenuSection heading="Join Table">
|
||||||
{#each tables as table}
|
{#each plusTables as table}
|
||||||
<MenuItem noClose icon="Table" on:click={() => (relationship.through = table._id)}>
|
<MenuItem noClose icon="Table" on:click={() => (relationship.through = table._id)}>
|
||||||
{table.name}
|
{table.name}
|
||||||
{#if relationship.through === table._id}
|
{#if relationship.through === table._id}
|
||||||
|
@ -119,9 +120,9 @@
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuSection heading={`${linkTable.name} Column`}>
|
<MenuSection heading={`${linkTable.name} Column`}>
|
||||||
{#each Object.keys(linkTable.schema) as column}
|
{#each Object.keys(linkTable.schema) as column}
|
||||||
<MenuItem noClose icon="Table" on:click={() => (relationship.foreignKey = column)}>
|
<MenuItem noClose icon="Table" on:click={() => (relationship.fieldName = column)}>
|
||||||
{column}
|
{column}
|
||||||
{#if relationship.foreignKey === column}
|
{#if relationship.fieldName === column}
|
||||||
<Icon size="S" name="Checkmark" />
|
<Icon size="S" name="Checkmark" />
|
||||||
{/if}
|
{/if}
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
|
@ -10,10 +10,11 @@
|
||||||
|
|
||||||
let unsaved = false
|
let unsaved = false
|
||||||
let relationshipModal
|
let relationshipModal
|
||||||
|
let selectedRelationship
|
||||||
|
|
||||||
$: datasource = $datasources.list.find(ds => ds._id === $datasources.selected)
|
$: datasource = $datasources.list.find(ds => ds._id === $datasources.selected)
|
||||||
$: integration = datasource && $integrations[datasource.source]
|
$: integration = datasource && $integrations[datasource.source]
|
||||||
$: plusTables = datasource?.plus ? Object.values(datasource.entities) : []
|
$: plusTables = datasource?.plus ? Object.values(datasource.entities || {}) : []
|
||||||
|
|
||||||
function buildRelationshipDisplayString(fromTable, toTable) {
|
function buildRelationshipDisplayString(fromTable, toTable) {
|
||||||
let displayString = fromTable.name
|
let displayString = fromTable.name
|
||||||
|
@ -64,7 +65,8 @@
|
||||||
unsaved = true
|
unsaved = true
|
||||||
}
|
}
|
||||||
|
|
||||||
function openRelationshipModal() {
|
function openRelationshipModal(relationship) {
|
||||||
|
selectedRelationship = relationship
|
||||||
relationshipModal.show()
|
relationshipModal.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,7 +82,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Modal bind:this={relationshipModal}>
|
<Modal bind:this={relationshipModal}>
|
||||||
<CreateEditRelationship {datasource} save={saveDatasource} tables={plusTables} />
|
<CreateEditRelationship {datasource} save={saveDatasource} {plusTables} relationship={selectedRelationship} />
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
{#if datasource && integration}
|
{#if datasource && integration}
|
||||||
|
@ -152,11 +154,9 @@
|
||||||
{#if table.schema[column].type === "link"}
|
{#if table.schema[column].type === "link"}
|
||||||
<div
|
<div
|
||||||
class="query-list-item"
|
class="query-list-item"
|
||||||
on:click={() => onClickTable(table.schema[column])}
|
on:click={() => openRelationshipModal(table.schema[column])}>
|
||||||
>
|
|
||||||
<p class="query-name">{table.schema[column].name}</p>
|
<p class="query-name">{table.schema[column].name}</p>
|
||||||
<p>{buildRelationshipDisplayString(table, table.schema[column])}</p>
|
<p>{buildRelationshipDisplayString(table, table.schema[column])}</p>
|
||||||
<!-- <p>{table.name} → {getTableNameFromId(table.schema[column].tableId)} ({table.schema[column].relationshipType}) </p> -->
|
|
||||||
<p>→</p>
|
<p>→</p>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
const roles = app.roles
|
const roles = app.roles
|
||||||
let options = roles.map(role => role._id)
|
let options = roles.map(role => ({ value: role._id, label: role.name }))
|
||||||
let selectedRole = user?.roles?.[app?._id]
|
let selectedRole = user?.roles?.[app?._id]
|
||||||
|
|
||||||
async function updateUserRoles() {
|
async function updateUserRoles() {
|
||||||
|
|
Loading…
Reference in New Issue