code clean up
This commit is contained in:
parent
678afc134e
commit
85f4141e46
|
@ -5,7 +5,6 @@
|
|||
Label,
|
||||
Select,
|
||||
Toggle,
|
||||
RadioGroup,
|
||||
Icon,
|
||||
DatePicker,
|
||||
Modal,
|
||||
|
@ -26,10 +25,10 @@
|
|||
ALLOWABLE_STRING_TYPES,
|
||||
ALLOWABLE_NUMBER_TYPES,
|
||||
SWITCHABLE_TYPES,
|
||||
PrettyRelationshipDefinitions,
|
||||
} from "constants/backend"
|
||||
import { getAutoColumnInformation, buildAutoColumn } from "builderStore/utils"
|
||||
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||
import { truncate } from "lodash"
|
||||
import ModalBindableInput from "components/common/bindings/ModalBindableInput.svelte"
|
||||
import { getBindings } from "components/backend/DataTable/formula"
|
||||
import JSONSchemaModal from "./JSONSchemaModal.svelte"
|
||||
|
@ -58,8 +57,8 @@
|
|||
let indexes = [...($tables.selected.indexes || [])]
|
||||
let isCreating = undefined
|
||||
|
||||
let relationshipPart1 = "Many rows"
|
||||
let relationshipPart2 = "To one row"
|
||||
let relationshipPart1 = PrettyRelationshipDefinitions.Many
|
||||
let relationshipPart2 = PrettyRelationshipDefinitions.One
|
||||
|
||||
let relationshipTableIdSecondary = null
|
||||
let table = $tables.selected
|
||||
|
@ -80,22 +79,21 @@
|
|||
}
|
||||
|
||||
$: {
|
||||
console.log("test")
|
||||
if (editableColumn.type === LINK_TYPE) {
|
||||
if (editableColumn.type === LINK_TYPE && editableColumn.tableId) {
|
||||
// Determine the relationship type based on the selected values of both parts
|
||||
if (
|
||||
relationshipPart1 === "Many rows" &&
|
||||
relationshipPart2 === "To one row"
|
||||
relationshipPart1 === PrettyRelationshipDefinitions.Many &&
|
||||
relationshipPart2 === PrettyRelationshipDefinitions.One
|
||||
) {
|
||||
editableColumn.relationshipType = RelationshipType.MANY_TO_ONE
|
||||
} else if (
|
||||
relationshipPart1 === "Many rows" &&
|
||||
relationshipPart2 === "To many rows"
|
||||
relationshipPart1 === PrettyRelationshipDefinitions.Many &&
|
||||
relationshipPart2 === PrettyRelationshipDefinitions.MANY
|
||||
) {
|
||||
editableColumn.relationshipType = RelationshipType.MANY_TO_MANY
|
||||
} else if (
|
||||
relationshipPart1 === "One row" &&
|
||||
relationshipPart2 === "To many rows"
|
||||
relationshipPart1 === PrettyRelationshipDefinitions.One &&
|
||||
relationshipPart2 === PrettyRelationshipDefinitions.Many
|
||||
) {
|
||||
editableColumn.relationshipType = RelationshipType.ONE_TO_MANY
|
||||
}
|
||||
|
@ -134,23 +132,19 @@
|
|||
|
||||
if (editableColumn.type === LINK_TYPE && editableColumn.tableId) {
|
||||
relationshipTableIdSecondary = editableColumn.tableId
|
||||
console.log("test?")
|
||||
console.log(editableColumn.relationshipType)
|
||||
console.log(RelationshipType.MANY_TO_MANY)
|
||||
if (editableColumn.relationshipType === RelationshipType.MANY_TO_ONE) {
|
||||
relationshipPart1 = "Many rows"
|
||||
relationshipPart2 = "To one row"
|
||||
relationshipPart1 = PrettyRelationshipDefinitions.Many
|
||||
relationshipPart2 = PrettyRelationshipDefinitions.One
|
||||
} else if (
|
||||
editableColumn.relationshipType === RelationshipType.MANY_TO_MANY
|
||||
) {
|
||||
console.log("asdasdasd?")
|
||||
relationshipPart1 = "Many rows"
|
||||
relationshipPart2 = "To many rows"
|
||||
relationshipPart1 = PrettyRelationshipDefinitions.Many
|
||||
relationshipPart2 = PrettyRelationshipDefinitions.Many
|
||||
} else if (
|
||||
editableColumn.relationshipType === RelationshipType.ONE_TO_MANY
|
||||
) {
|
||||
relationshipPart1 = "One row"
|
||||
relationshipPart2 = "To many rows"
|
||||
relationshipPart1 = PrettyRelationshipDefinitions.One
|
||||
relationshipPart2 = PrettyRelationshipDefinitions.Many
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -210,7 +204,6 @@
|
|||
!uneditable &&
|
||||
editableColumn?.type !== AUTO_TYPE &&
|
||||
!editableColumn.autocolumn
|
||||
$: relationshipOptions = getRelationshipOptions(editableColumn)
|
||||
$: external = table.type === "external"
|
||||
// in the case of internal tables the sourceId will just be undefined
|
||||
$: tableOptions = $tables.list.filter(
|
||||
|
@ -341,35 +334,6 @@
|
|||
return match ? parseInt(match[1]) : 0
|
||||
}
|
||||
|
||||
function getRelationshipOptions(field) {
|
||||
if (!field || !field.tableId) {
|
||||
return null
|
||||
}
|
||||
const linkTable = tableOptions?.find(table => table._id === field.tableId)
|
||||
if (!linkTable) {
|
||||
return null
|
||||
}
|
||||
const thisName = truncate(table.name, { length: 14 }),
|
||||
linkName = truncate(linkTable.name, { length: 14 })
|
||||
return [
|
||||
{
|
||||
name: `Many ${thisName} rows → many ${linkName} rows`,
|
||||
alt: `Many ${table.name} rows → many ${linkTable.name} rows`,
|
||||
value: RelationshipType.MANY_TO_MANY,
|
||||
},
|
||||
{
|
||||
name: `One ${linkName} row → many ${thisName} rows`,
|
||||
alt: `One ${linkTable.name} rows → many ${table.name} rows`,
|
||||
value: RelationshipType.ONE_TO_MANY,
|
||||
},
|
||||
{
|
||||
name: `One ${thisName} row → many ${linkName} rows`,
|
||||
alt: `One ${table.name} rows → many ${linkTable.name} rows`,
|
||||
value: RelationshipType.MANY_TO_ONE,
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
function getAllowedTypes() {
|
||||
if (
|
||||
originalName &&
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<script>
|
||||
import { Select, Input } from "@budibase/bbui"
|
||||
import { RelationshipType } from "constants/backend"
|
||||
import { PrettyRelationshipDefinitions } from "constants/backend"
|
||||
|
||||
export let relationshipPart1
|
||||
export let relationshipPart2
|
||||
|
@ -17,7 +17,7 @@
|
|||
<Select
|
||||
disabled={linkEditDisabled}
|
||||
bind:value={relationshipPart1}
|
||||
options={["Many rows", "One row"]}
|
||||
options={Object.values(PrettyRelationshipDefinitions)}
|
||||
/>
|
||||
</div>
|
||||
<div class="relationship-label">in</div>
|
||||
|
@ -34,8 +34,8 @@
|
|||
<Select
|
||||
disabled={linkEditDisabled}
|
||||
bind:value={relationshipPart2}
|
||||
options={["To one row", "To many rows"]}
|
||||
getOptionLabel={option => option}
|
||||
options={Object.values(PrettyRelationshipDefinitions)}
|
||||
getOptionLabel={option => "To " + option.toLowerCase()}
|
||||
/>
|
||||
</div>
|
||||
<div class="relationship-label">in</div>
|
||||
|
|
|
@ -170,6 +170,11 @@ export const RelationshipType = {
|
|||
MANY_TO_ONE: "many-to-one",
|
||||
}
|
||||
|
||||
export const PrettyRelationshipDefinitions = {
|
||||
MANY: "Many rows",
|
||||
ONE: "One row",
|
||||
}
|
||||
|
||||
export const ALLOWABLE_STRING_OPTIONS = [
|
||||
FIELDS.STRING,
|
||||
FIELDS.OPTIONS,
|
||||
|
|
Loading…
Reference in New Issue