Merge remote-tracking branch 'origin/v3-ui' into feature/automation-branching-ux

This commit is contained in:
Dean 2024-10-14 14:33:32 +01:00
commit bde3852de2
4 changed files with 64 additions and 46 deletions

View File

@ -50,18 +50,13 @@
import { isEnabled } from "helpers/featureFlags" import { isEnabled } from "helpers/featureFlags"
import { getUserBindings } from "dataBinding" import { getUserBindings } from "dataBinding"
const AUTO_TYPE = FieldType.AUTO export let field
const FORMULA_TYPE = FieldType.FORMULA
const LINK_TYPE = FieldType.LINK
const STRING_TYPE = FieldType.STRING
const NUMBER_TYPE = FieldType.NUMBER
const JSON_TYPE = FieldType.JSON
const DATE_TYPE = FieldType.DATETIME
const dispatch = createEventDispatcher() const dispatch = createEventDispatcher()
const { dispatch: gridDispatch, rows } = getContext("grid") const { dispatch: gridDispatch, rows } = getContext("grid")
const SafeID = `${makePropSafe("user")}.${makePropSafe("_id")}`
export let field const SingleUserDefault = `{{ ${SafeID} }}`
const MultiUserDefault = `{{ js "${btoa(`return [$("${SafeID}")]`)}" }}`
let mounted = false let mounted = false
let originalName let originalName
@ -110,7 +105,7 @@
$: { $: {
// this parses any changes the user has made when creating a new internal relationship // this parses any changes the user has made when creating a new internal relationship
// into what we expect the schema to look like // into what we expect the schema to look like
if (editableColumn.type === LINK_TYPE) { if (editableColumn.type === FieldType.LINK) {
relationshipTableIdPrimary = table._id relationshipTableIdPrimary = table._id
if (relationshipPart1 === PrettyRelationshipDefinitions.ONE) { if (relationshipPart1 === PrettyRelationshipDefinitions.ONE) {
relationshipOpts2 = relationshipOpts2.filter( relationshipOpts2 = relationshipOpts2.filter(
@ -147,7 +142,7 @@
UNEDITABLE_USER_FIELDS.includes(editableColumn.name) UNEDITABLE_USER_FIELDS.includes(editableColumn.name)
$: invalid = $: invalid =
!editableColumn?.name || !editableColumn?.name ||
(editableColumn?.type === LINK_TYPE && !editableColumn?.tableId) || (editableColumn?.type === FieldType.LINK && !editableColumn?.tableId) ||
Object.keys(errors).length !== 0 || Object.keys(errors).length !== 0 ||
!optionsValid !optionsValid
$: errors = checkErrors(editableColumn) $: errors = checkErrors(editableColumn)
@ -173,9 +168,9 @@
$: defaultValuesEnabled = isEnabled("DEFAULT_VALUES") $: defaultValuesEnabled = isEnabled("DEFAULT_VALUES")
$: canHaveDefault = !required && canHaveDefaultColumn(editableColumn.type) $: canHaveDefault = !required && canHaveDefaultColumn(editableColumn.type)
$: canBeRequired = $: canBeRequired =
editableColumn?.type !== LINK_TYPE && editableColumn?.type !== FieldType.LINK &&
!uneditable && !uneditable &&
editableColumn?.type !== AUTO_TYPE && editableColumn?.type !== FieldType.AUTO &&
!editableColumn.autocolumn !editableColumn.autocolumn
$: hasDefault = $: hasDefault =
editableColumn?.default != null && editableColumn?.default !== "" editableColumn?.default != null && editableColumn?.default !== ""
@ -224,7 +219,7 @@
function makeFieldId(type, subtype, autocolumn) { function makeFieldId(type, subtype, autocolumn) {
// don't make field IDs for auto types // don't make field IDs for auto types
if (type === AUTO_TYPE || autocolumn) { if (type === FieldType.AUTO || autocolumn) {
return type.toUpperCase() return type.toUpperCase()
} else if ( } else if (
type === FieldType.BB_REFERENCE || type === FieldType.BB_REFERENCE ||
@ -249,7 +244,7 @@
// Here we are setting the relationship values based on the editableColumn // Here we are setting the relationship values based on the editableColumn
// This part of the code is used when viewing an existing field hence the check // This part of the code is used when viewing an existing field hence the check
// for the tableId // for the tableId
if (editableColumn.type === LINK_TYPE && editableColumn.tableId) { if (editableColumn.type === FieldType.LINK && editableColumn.tableId) {
relationshipTableIdPrimary = table._id relationshipTableIdPrimary = table._id
relationshipTableIdSecondary = editableColumn.tableId relationshipTableIdSecondary = editableColumn.tableId
if (editableColumn.relationshipType in relationshipMap) { if (editableColumn.relationshipType in relationshipMap) {
@ -290,14 +285,14 @@
delete saveColumn.fieldId delete saveColumn.fieldId
if (saveColumn.type === AUTO_TYPE) { if (saveColumn.type === FieldType.AUTO) {
saveColumn = buildAutoColumn( saveColumn = buildAutoColumn(
$tables.selected.name, $tables.selected.name,
saveColumn.name, saveColumn.name,
saveColumn.subtype saveColumn.subtype
) )
} }
if (saveColumn.type !== LINK_TYPE) { if (saveColumn.type !== FieldType.LINK) {
delete saveColumn.fieldName delete saveColumn.fieldName
} }
@ -384,9 +379,9 @@
editableColumn.subtype = definition.subtype editableColumn.subtype = definition.subtype
// Default relationships many to many // Default relationships many to many
if (editableColumn.type === LINK_TYPE) { if (editableColumn.type === FieldType.LINK) {
editableColumn.relationshipType = RelationshipType.MANY_TO_MANY editableColumn.relationshipType = RelationshipType.MANY_TO_MANY
} else if (editableColumn.type === FORMULA_TYPE) { } else if (editableColumn.type === FieldType.FORMULA) {
editableColumn.formulaType = "dynamic" editableColumn.formulaType = "dynamic"
} }
} }
@ -505,17 +500,23 @@
fieldToCheck.constraints = {} fieldToCheck.constraints = {}
} }
// some string types may have been built by server, may not always have constraints // some string types may have been built by server, may not always have constraints
if (fieldToCheck.type === STRING_TYPE && !fieldToCheck.constraints.length) { if (
fieldToCheck.type === FieldType.STRING &&
!fieldToCheck.constraints.length
) {
fieldToCheck.constraints.length = {} fieldToCheck.constraints.length = {}
} }
// some number types made server-side will be missing constraints // some number types made server-side will be missing constraints
if ( if (
fieldToCheck.type === NUMBER_TYPE && fieldToCheck.type === FieldType.NUMBER &&
!fieldToCheck.constraints.numericality !fieldToCheck.constraints.numericality
) { ) {
fieldToCheck.constraints.numericality = {} fieldToCheck.constraints.numericality = {}
} }
if (fieldToCheck.type === DATE_TYPE && !fieldToCheck.constraints.datetime) { if (
fieldToCheck.type === FieldType.DATETIME &&
!fieldToCheck.constraints.datetime
) {
fieldToCheck.constraints.datetime = {} fieldToCheck.constraints.datetime = {}
} }
} }
@ -590,13 +591,13 @@
on:input={e => { on:input={e => {
if ( if (
!uneditable && !uneditable &&
!(linkEditDisabled && editableColumn.type === LINK_TYPE) !(linkEditDisabled && editableColumn.type === FieldType.LINK)
) { ) {
editableColumn.name = e.target.value editableColumn.name = e.target.value
} }
}} }}
disabled={uneditable || disabled={uneditable ||
(linkEditDisabled && editableColumn.type === LINK_TYPE)} (linkEditDisabled && editableColumn.type === FieldType.LINK)}
error={errors?.name} error={errors?.name}
/> />
{/if} {/if}
@ -610,7 +611,7 @@
getOptionValue={field => field.fieldId} getOptionValue={field => field.fieldId}
getOptionIcon={field => field.icon} getOptionIcon={field => field.icon}
isOptionEnabled={option => { isOptionEnabled={option => {
if (option.type === AUTO_TYPE) { if (option.type === FieldType.AUTO) {
return availableAutoColumnKeys?.length > 0 return availableAutoColumnKeys?.length > 0
} }
return true return true
@ -653,7 +654,7 @@
bind:optionColors={editableColumn.optionColors} bind:optionColors={editableColumn.optionColors}
bind:valid={optionsValid} bind:valid={optionsValid}
/> />
{:else if editableColumn.type === DATE_TYPE && !editableColumn.autocolumn} {:else if editableColumn.type === FieldType.DATETIME && !editableColumn.autocolumn}
<div class="split-label"> <div class="split-label">
<div class="label-length"> <div class="label-length">
<Label size="M">Earliest</Label> <Label size="M">Earliest</Label>
@ -740,7 +741,7 @@
{tableOptions} {tableOptions}
{errors} {errors}
/> />
{:else if editableColumn.type === FORMULA_TYPE} {:else if editableColumn.type === FieldType.FORMULA}
{#if !externalTable} {#if !externalTable}
<div class="split-label"> <div class="split-label">
<div class="label-length"> <div class="label-length">
@ -783,12 +784,12 @@
/> />
</div> </div>
</div> </div>
{:else if editableColumn.type === JSON_TYPE} {:else if editableColumn.type === FieldType.JSON}
<Button primary text on:click={openJsonSchemaEditor}> <Button primary text on:click={openJsonSchemaEditor}>
Open schema editor Open schema editor
</Button> </Button>
{/if} {/if}
{#if editableColumn.type === AUTO_TYPE || editableColumn.autocolumn} {#if editableColumn.type === FieldType.AUTO || editableColumn.autocolumn}
<Select <Select
label="Auto column type" label="Auto column type"
value={editableColumn.subtype} value={editableColumn.subtype}
@ -835,6 +836,18 @@
(editableColumn.default = e.detail?.length ? e.detail : undefined)} (editableColumn.default = e.detail?.length ? e.detail : undefined)}
placeholder="None" placeholder="None"
/> />
{:else if editableColumn.subtype === BBReferenceFieldSubType.USER}
{@const defaultValue =
editableColumn.type === FieldType.BB_REFERENCE_SINGLE
? SingleUserDefault
: MultiUserDefault}
<Toggle
disabled={!canHaveDefault}
text="Default to current user"
value={editableColumn.default === defaultValue}
on:change={e =>
(editableColumn.default = e.detail ? defaultValue : undefined)}
/>
{:else} {:else}
<ModalBindableInput <ModalBindableInput
disabled={!canHaveDefault} disabled={!canHaveDefault}

View File

@ -6,16 +6,22 @@ import { dataFilters } from "@budibase/shared-core"
function convertToSearchFilters(view) { function convertToSearchFilters(view) {
// convert from SearchFilterGroup type // convert from SearchFilterGroup type
if (view?.query) { if (view?.query) {
view.queryUI = view.query return {
view.query = dataFilters.buildQuery(view.query) ...view,
queryUI: view.query,
query: dataFilters.buildQuery(view.query),
}
} }
return view return view
} }
function convertToSearchFilterGroup(view) { function convertToSearchFilterGroup(view) {
if (view?.queryUI) { if (view?.queryUI) {
view.query = view.queryUI return {
delete view.queryUI ...view,
query: view.queryUI,
queryUI: undefined,
}
} }
return view return view
} }

View File

@ -3,9 +3,12 @@ import { dataFilters } from "@budibase/shared-core"
function convertToSearchFilters(view) { function convertToSearchFilters(view) {
// convert from SearchFilterGroup type // convert from SearchFilterGroup type
if (view.query) { if (view?.query) {
view.queryUI = view.query return {
view.query = dataFilters.buildQuery(view.query) ...view,
queryUI: view.query,
query: dataFilters.buildQuery(view.query),
}
} }
return view return view
} }

View File

@ -24,9 +24,9 @@ const columnTypeManyParser = {
return parsed return parsed
} }
return value?.map(v => parseDate(v)) return value.map(v => parseDate(v))
}, },
[FieldType.BOOLEAN]: value => value?.map(v => !!v), [FieldType.BOOLEAN]: value => value.map(v => !!v),
[FieldType.BB_REFERENCE_SINGLE]: value => [ [FieldType.BB_REFERENCE_SINGLE]: value => [
...new Map(value.map(i => [i._id, i])).values(), ...new Map(value.map(i => [i._id, i])).values(),
], ],
@ -80,14 +80,10 @@ export function getRelatedTableValues(row, field, fromField) {
result = row[field.related.field]?.[0]?.[field.related.subField] result = row[field.related.field]?.[0]?.[field.related.subField]
} else { } else {
const parser = columnTypeManyParser[field.type] || (value => value) const parser = columnTypeManyParser[field.type] || (value => value)
const value = row[field.related.field]
result = parser(
row[field.related.field]
?.flatMap(r => r[field.related.subField]) ?.flatMap(r => r[field.related.subField])
?.filter(i => i !== undefined && i !== null), ?.filter(i => i !== undefined && i !== null)
field result = parser(value || [], field)
)
if ( if (
[ [
FieldType.STRING, FieldType.STRING,