Merge pull request #14204 from Budibase/budi-8433-default-value-column-ui

[BUDI-8433] Default value column UI
This commit is contained in:
Sam Rose 2024-08-12 13:45:18 +01:00 committed by GitHub
commit 8b9576a55f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 73 additions and 10 deletions

View File

@ -19,6 +19,8 @@
helpers, helpers,
PROTECTED_INTERNAL_COLUMNS, PROTECTED_INTERNAL_COLUMNS,
PROTECTED_EXTERNAL_COLUMNS, PROTECTED_EXTERNAL_COLUMNS,
canBeDisplayColumn,
canHaveDefaultColumn,
} from "@budibase/shared-core" } from "@budibase/shared-core"
import { createEventDispatcher, getContext, onMount } from "svelte" import { createEventDispatcher, getContext, onMount } from "svelte"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
@ -44,6 +46,7 @@
import { RowUtils } from "@budibase/frontend-core" import { RowUtils } from "@budibase/frontend-core"
import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte" import ServerBindingPanel from "components/common/bindings/ServerBindingPanel.svelte"
import OptionsEditor from "./OptionsEditor.svelte" import OptionsEditor from "./OptionsEditor.svelte"
import { isEnabled, TENANT_FEATURE_FLAGS } from "helpers/featureFlags"
const AUTO_TYPE = FieldType.AUTO const AUTO_TYPE = FieldType.AUTO
const FORMULA_TYPE = FieldType.FORMULA const FORMULA_TYPE = FieldType.FORMULA
@ -133,7 +136,9 @@
} }
$: initialiseField(field, savingColumn) $: initialiseField(field, savingColumn)
$: checkConstraints(editableColumn) $: checkConstraints(editableColumn)
$: required = !!editableColumn?.constraints?.presence || primaryDisplay $: required = hasDefault
? false
: !!editableColumn?.constraints?.presence || primaryDisplay
$: uneditable = $: uneditable =
$tables.selected?._id === TableNames.USERS && $tables.selected?._id === TableNames.USERS &&
UNEDITABLE_USER_FIELDS.includes(editableColumn.name) UNEDITABLE_USER_FIELDS.includes(editableColumn.name)
@ -161,15 +166,17 @@
: availableAutoColumns : availableAutoColumns
// used to select what different options can be displayed for column type // used to select what different options can be displayed for column type
$: canBeDisplay = $: canBeDisplay =
editableColumn?.type !== LINK_TYPE && canBeDisplayColumn(editableColumn.type) && !editableColumn.autocolumn
editableColumn?.type !== AUTO_TYPE && $: canHaveDefault =
editableColumn?.type !== JSON_TYPE && isEnabled(TENANT_FEATURE_FLAGS.DEFAULT_VALUES) &&
!editableColumn.autocolumn canHaveDefaultColumn(editableColumn.type)
$: canBeRequired = $: canBeRequired =
editableColumn?.type !== LINK_TYPE && editableColumn?.type !== LINK_TYPE &&
!uneditable && !uneditable &&
editableColumn?.type !== AUTO_TYPE && editableColumn?.type !== AUTO_TYPE &&
!editableColumn.autocolumn !editableColumn.autocolumn
$: hasDefault =
editableColumn?.default != null && editableColumn?.default !== ""
$: externalTable = table.sourceType === DB_TYPE_EXTERNAL $: externalTable = table.sourceType === DB_TYPE_EXTERNAL
// in the case of internal tables the sourceId will just be undefined // in the case of internal tables the sourceId will just be undefined
$: tableOptions = $tables.list.filter( $: tableOptions = $tables.list.filter(
@ -349,12 +356,15 @@
} }
} }
function onChangeRequired(e) { function setRequired(req) {
const req = e.detail
editableColumn.constraints.presence = req ? { allowEmpty: false } : false editableColumn.constraints.presence = req ? { allowEmpty: false } : false
required = req required = req
} }
function onChangeRequired(e) {
setRequired(e.detail)
}
function openJsonSchemaEditor() { function openJsonSchemaEditor() {
jsonSchemaModal.show() jsonSchemaModal.show()
} }
@ -748,13 +758,37 @@
<Toggle <Toggle
value={required} value={required}
on:change={onChangeRequired} on:change={onChangeRequired}
disabled={primaryDisplay} disabled={primaryDisplay || hasDefault}
thin thin
text="Required" text="Required"
/> />
{/if} {/if}
</div> </div>
{/if} {/if}
{#if canHaveDefault}
<div>
<ModalBindableInput
panel={ServerBindingPanel}
title="Default"
label="Default"
value={editableColumn.default}
on:change={e => {
editableColumn = {
...editableColumn,
default: e.detail,
}
if (e.detail) {
setRequired(false)
}
}}
bindings={getBindings({ table })}
allowJS
context={rowGoldenSample}
/>
</div>
{/if}
</Layout> </Layout>
<div class="action-buttons"> <div class="action-buttons">

View File

@ -6,6 +6,7 @@ export const TENANT_FEATURE_FLAGS = {
USER_GROUPS: "USER_GROUPS", USER_GROUPS: "USER_GROUPS",
ONBOARDING_TOUR: "ONBOARDING_TOUR", ONBOARDING_TOUR: "ONBOARDING_TOUR",
GOOGLE_SHEETS: "GOOGLE_SHEETS", GOOGLE_SHEETS: "GOOGLE_SHEETS",
DEFAULT_VALUES: "DEFAULT_VALUES",
} }
export const isEnabled = featureFlag => { export const isEnabled = featureFlag => {

View File

@ -11,6 +11,7 @@ const allowDisplayColumnByType: Record<FieldType, boolean> = {
[FieldType.AUTO]: true, [FieldType.AUTO]: true,
[FieldType.INTERNAL]: true, [FieldType.INTERNAL]: true,
[FieldType.BARCODEQR]: true, [FieldType.BARCODEQR]: true,
[FieldType.BIGINT]: true, [FieldType.BIGINT]: true,
[FieldType.BOOLEAN]: false, [FieldType.BOOLEAN]: false,
[FieldType.ARRAY]: false, [FieldType.ARRAY]: false,
@ -35,6 +36,30 @@ const allowSortColumnByType: Record<FieldType, boolean> = {
[FieldType.BIGINT]: true, [FieldType.BIGINT]: true,
[FieldType.BOOLEAN]: true, [FieldType.BOOLEAN]: true,
[FieldType.JSON]: true, [FieldType.JSON]: true,
[FieldType.FORMULA]: false,
[FieldType.ATTACHMENTS]: false,
[FieldType.ATTACHMENT_SINGLE]: false,
[FieldType.SIGNATURE_SINGLE]: false,
[FieldType.ARRAY]: false,
[FieldType.LINK]: false,
[FieldType.BB_REFERENCE]: false,
[FieldType.BB_REFERENCE_SINGLE]: false,
}
const allowDefaultColumnByType: Record<FieldType, boolean> = {
[FieldType.NUMBER]: true,
[FieldType.JSON]: true,
[FieldType.DATETIME]: true,
[FieldType.LONGFORM]: true,
[FieldType.STRING]: true,
[FieldType.OPTIONS]: false,
[FieldType.AUTO]: false,
[FieldType.INTERNAL]: false,
[FieldType.BARCODEQR]: false,
[FieldType.BIGINT]: false,
[FieldType.BOOLEAN]: false,
[FieldType.FORMULA]: false, [FieldType.FORMULA]: false,
[FieldType.ATTACHMENTS]: false, [FieldType.ATTACHMENTS]: false,
[FieldType.ATTACHMENT_SINGLE]: false, [FieldType.ATTACHMENT_SINGLE]: false,
@ -53,6 +78,10 @@ export function canBeSortColumn(type: FieldType): boolean {
return !!allowSortColumnByType[type] return !!allowSortColumnByType[type]
} }
export function canHaveDefaultColumn(type: FieldType): boolean {
return !!allowDefaultColumnByType[type]
}
export function findDuplicateInternalColumns(table: Table): string[] { export function findDuplicateInternalColumns(table: Table): string[] {
// maintains the case of keys // maintains the case of keys
const casedKeys = Object.keys(table.schema) const casedKeys = Object.keys(table.schema)

View File

@ -114,7 +114,6 @@ export interface FormulaFieldMetadata extends BaseFieldSchema {
type: FieldType.FORMULA type: FieldType.FORMULA
formula: string formula: string
formulaType?: FormulaType formulaType?: FormulaType
default?: string
} }
export interface BBReferenceFieldMetadata export interface BBReferenceFieldMetadata

View File

@ -96,11 +96,11 @@ export default server.listen(parseInt(env.PORT || "4002"), async () => {
console.log(startupLog) console.log(startupLog)
await initPro() await initPro()
await redis.clients.init() await redis.clients.init()
features.init()
cache.docWritethrough.init() cache.docWritethrough.init()
// configure events to use the pro audit log write // configure events to use the pro audit log write
// can't integrate directly into backend-core due to cyclic issues // can't integrate directly into backend-core due to cyclic issues
await events.processors.init(proSdk.auditLogs.write) await events.processors.init(proSdk.auditLogs.write)
features.init()
}) })
process.on("uncaughtException", err => { process.on("uncaughtException", err => {