1
0
Fork 0
mirror of synced 2024-06-27 02:20:35 +12:00

Single attachment subtype

This commit is contained in:
Adria Navarro 2024-03-20 13:35:09 +01:00
parent 23ac11ad6b
commit 59a7d8052a
3 changed files with 32 additions and 10 deletions

View file

@ -34,7 +34,12 @@
import { getBindings } from "components/backend/DataTable/formula"
import JSONSchemaModal from "./JSONSchemaModal.svelte"
import { ValidColumnNameRegex } from "@budibase/shared-core"
import { FieldType, FieldSubtype, SourceName } from "@budibase/types"
import {
FieldType,
FieldSubtype,
SourceName,
FieldTypeSubtypes,
} from "@budibase/types"
import RelationshipSelector from "components/common/RelationshipSelector.svelte"
import { RowUtils } from "@budibase/frontend-core"
import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte"
@ -191,8 +196,10 @@
// don't make field IDs for auto types
if (type === AUTO_TYPE || autocolumn) {
return type.toUpperCase()
} else {
} else if (type === FieldType.BB_REFERENCE) {
return `${type}${subtype || ""}`.toUpperCase()
} else {
return type.toUpperCase()
}
}
@ -705,17 +712,12 @@
/>
{:else if editableColumn.type === FieldType.ATTACHMENT}
<Toggle
value={editableColumn.constraints?.length?.maximum !== 1}
value={editableColumn.subtype !== FieldTypeSubtypes.ATTACHMENT.SINGLE}
on:change={e => {
if (!e.detail) {
editableColumn.constraints ??= { length: {} }
editableColumn.constraints.length ??= {}
editableColumn.constraints.length.maximum = 1
editableColumn.constraints.length.message =
"cannot contain multiple files"
editableColumn.subtype = FieldTypeSubtypes.ATTACHMENT.SINGLE
} else {
delete editableColumn.constraints?.length?.maximum
delete editableColumn.constraints?.length?.message
delete editableColumn.subtype
}
}}
thin

View file

@ -30,6 +30,7 @@ import {
View,
RelationshipFieldMetadata,
FieldType,
FieldTypeSubtypes,
} from "@budibase/types"
export async function clearColumns(table: Table, columnNames: string[]) {
@ -88,6 +89,24 @@ export async function checkForColumnUpdates(
// Update views
await checkForViewUpdates(updatedTable, deletedColumns, columnRename)
}
for (const attachmentColumn of Object.values(updatedTable.schema).filter(
column =>
column.type === FieldType.ATTACHMENT &&
column.subtype !== oldTable?.schema[column.name]?.subtype
)) {
if (attachmentColumn.subtype === FieldTypeSubtypes.ATTACHMENT.SINGLE) {
attachmentColumn.constraints ??= { length: {} }
attachmentColumn.constraints.length ??= {}
attachmentColumn.constraints.length.maximum = 1
attachmentColumn.constraints.length.message =
"cannot contain multiple files"
} else {
delete attachmentColumn.constraints?.length?.maximum
delete attachmentColumn.constraints?.length?.message
}
}
return { rows: updatedRows, table: updatedTable }
}

View file

@ -119,6 +119,7 @@ export interface FieldConstraints {
length?: {
minimum?: string | number | null
maximum?: string | number | null
message?: string
}
numericality?: {
greaterThanOrEqualTo: string | null