This commit is contained in:
Adria Navarro 2025-01-13 13:48:20 +01:00
parent 2fd120c656
commit 819f6f52e3
2 changed files with 24 additions and 8 deletions

View File

@ -17,7 +17,10 @@ export {
export const AUTO_COLUMN_SUB_TYPES = AutoFieldSubType export const AUTO_COLUMN_SUB_TYPES = AutoFieldSubType
export const AUTO_COLUMN_DISPLAY_NAMES = { export const AUTO_COLUMN_DISPLAY_NAMES: Record<
keyof typeof AUTO_COLUMN_SUB_TYPES,
string
> = {
AUTO_ID: "Auto ID", AUTO_ID: "Auto ID",
CREATED_BY: "Created By", CREATED_BY: "Created By",
CREATED_AT: "Created At", CREATED_AT: "Created At",

View File

@ -1,4 +1,4 @@
import { FieldType } from "@budibase/types" import { AutoFieldSubType, Automation, FieldType } from "@budibase/types"
import { ActionStepID } from "@/constants/backend/automations" import { ActionStepID } from "@/constants/backend/automations"
import { TableNames } from "@/constants" import { TableNames } from "@/constants"
import { import {
@ -8,8 +8,14 @@ import {
isAutoColumnUserRelationship, isAutoColumnUserRelationship,
} from "@/constants/backend" } from "@/constants/backend"
export function getAutoColumnInformation(enabled = true) { type AutoColumnInformation = Partial<
let info = {} Record<AutoFieldSubType, { enabled: boolean; name: string }>
>
export function getAutoColumnInformation(
enabled = true
): AutoColumnInformation {
const info: AutoColumnInformation = {}
for (const [key, subtype] of Object.entries(AUTO_COLUMN_SUB_TYPES)) { for (const [key, subtype] of Object.entries(AUTO_COLUMN_SUB_TYPES)) {
// Because it's possible to replicate the functionality of CREATED_AT and // Because it's possible to replicate the functionality of CREATED_AT and
// CREATED_BY columns with user column default values, we disable their creation // CREATED_BY columns with user column default values, we disable their creation
@ -19,13 +25,20 @@ export function getAutoColumnInformation(enabled = true) {
) { ) {
continue continue
} }
const typedKey = key as keyof typeof AUTO_COLUMN_SUB_TYPES
info[subtype] = { enabled, name: AUTO_COLUMN_DISPLAY_NAMES[key] } info[subtype] = {
enabled,
name: AUTO_COLUMN_DISPLAY_NAMES[typedKey],
}
} }
return info return info
} }
export function buildAutoColumn(tableName, name, subtype) { export function buildAutoColumn(
tableName: string,
name: string,
subtype: AutoFieldSubType
) {
let type, constraints let type, constraints
switch (subtype) { switch (subtype) {
case AUTO_COLUMN_SUB_TYPES.UPDATED_BY: case AUTO_COLUMN_SUB_TYPES.UPDATED_BY:
@ -65,7 +78,7 @@ export function buildAutoColumn(tableName, name, subtype) {
return base return base
} }
export function checkForCollectStep(automation) { export function checkForCollectStep(automation: Automation) {
return automation.definition.steps.some( return automation.definition.steps.some(
step => step.stepId === ActionStepID.COLLECT step => step.stepId === ActionStepID.COLLECT
) )