Formatting.

This commit is contained in:
mike12345567 2021-02-22 11:40:24 +00:00
parent c801203dc5
commit 99d356a862
4 changed files with 43 additions and 27 deletions

View File

@ -7,7 +7,6 @@
Select,
Toggle,
Radio,
} from "@budibase/bbui"
import { cloneDeep } from "lodash/fp"
import { backendUiStore } from "builderStore"
@ -38,12 +37,14 @@
$backendUiStore.selectedTable.primaryDisplay === field.name
let relationshipTypes = [
{text: 'Many to many (N:N)', value: 'many-to-many',},
{text: 'One to many (1:N)', value: 'one-to-many',}
{ text: "Many to many (N:N)", value: "many-to-many" },
{ text: "One to many (1:N)", value: "one-to-many" },
]
let types = ['Many to many (N:N)', 'One to many (1:N)']
let types = ["Many to many (N:N)", "One to many (1:N)"]
let selectedRelationshipType = relationshipTypes.find(type => type.value === field.relationshipType)?.text || 'Many to many (N:N)'
let selectedRelationshipType =
relationshipTypes.find(type => type.value === field.relationshipType)
?.text || "Many to many (N:N)"
let indexes = [...($backendUiStore.selectedTable.indexes || [])]
let confirmDeleteDialog
@ -69,8 +70,10 @@
async function saveColumn() {
// Set relationship type if it's
if (field.type === 'link') {
field.relationshipType = relationshipTypes.find(type => type.text === selectedRelationshipType).value
if (field.type === "link") {
field.relationshipType = relationshipTypes.find(
type => type.text === selectedRelationshipType
).value
}
if (field.type === AUTO_COL) {
@ -232,7 +235,11 @@
<Label grey extraSmall>Select relationship type</Label>
<div class="radio-buttons">
{#each types as type}
<Radio disabled={originalName} name="Relationship type" value={type} bind:group={selectedRelationshipType}>
<Radio
disabled={originalName}
name="Relationship type"
value={type}
bind:group={selectedRelationshipType}>
<label for={type}>{type}</label>
</Radio>
{/each}
@ -282,7 +289,7 @@
.radio-buttons {
display: flex;
gap: var(--spacing-m);
font-size: var(--font-size-xs)
font-size: var(--font-size-xs);
}
.actions {
display: grid;

View File

@ -42,10 +42,17 @@
</Label>
{:else}
{#if schema.relationshipType === 'one-to-many'}
<Select thin secondary on:change={e => linkedRows = [e.target.value]} name={label} {label}>
<Select
thin
secondary
on:change={e => (linkedRows = [e.target.value])}
name={label}
{label}>
<option value="">Choose an option</option>
{#each rows as row}
<option selected={row._id === linkedRows[0]} value={row._id}>{getPrettyName(row)}</option>
<option selected={row._id === linkedRows[0]} value={row._id}>
{getPrettyName(row)}
</option>
{/each}
</Select>
{:else}

View File

@ -202,10 +202,12 @@
Please run your query to fetch some data.
{:else}
{JSON.stringify(data[0], undefined, 2)}
{/if}

View File

@ -19,24 +19,24 @@
let tableDefinition
let fieldText = ""
const setFieldText = (value) => {
if (fieldSchema?.relationshipType === 'one-to-many') {
const setFieldText = value => {
if (fieldSchema?.relationshipType === "one-to-many") {
if (value?.length && options?.length) {
const row = options.find(row => row._id === value[0])
return row.name
} else {
return placeholder || 'Choose an option'
return placeholder || "Choose an option"
}
} else {
if (value?.length) {
return `${value?.length ?? 0} selected rows`
} else {
return placeholder || 'Choose some options'
return placeholder || "Choose some options"
}
}
}
$: options, fieldText = setFieldText($fieldState?.value)
$: options, (fieldText = setFieldText($fieldState?.value))
$: valueLookupMap = getValueLookupMap($fieldState?.value)
$: isOptionSelected = option => valueLookupMap[option] === true
$: linkedTableId = fieldSchema?.tableId
@ -74,7 +74,7 @@
}
const toggleOption = option => {
if (fieldSchema.type === 'one-to-many') {
if (fieldSchema.type === "one-to-many") {
fieldApi.setValue([option])
} else {
if ($fieldState.value.includes(option)) {