mirror of https://github.com/Budibase/budibase.git
8 changed files with 114 additions and 58 deletions
@ -0,0 +1,29 @@ |
|||
<script> |
|||
import { TextButton } from "@budibase/bbui" |
|||
|
|||
export let hideAutocolumns = true |
|||
|
|||
let anchor |
|||
let dropdown |
|||
|
|||
function hideOrUnhide() { |
|||
hideAutocolumns = !hideAutocolumns |
|||
} |
|||
</script> |
|||
|
|||
<div bind:this={anchor}> |
|||
<TextButton text small on:click={hideOrUnhide}> |
|||
<i class="ri-magic-fill"></i> |
|||
{#if hideAutocolumns} |
|||
Show Auto Columns |
|||
{:else} |
|||
Hide Auto Columns |
|||
{/if} |
|||
</TextButton> |
|||
</div> |
|||
|
|||
<style> |
|||
i { |
|||
margin-right: 4px; |
|||
} |
|||
</style> |
|||
@ -0,0 +1,55 @@ |
|||
import { TableNames } from "../../constants" |
|||
import { |
|||
AUTO_COLUMN_DISPLAY_NAMES, |
|||
AUTO_COLUMN_SUB_TYPES, |
|||
FIELDS, |
|||
isAutoColumnUserRelationship |
|||
} from "../../constants/backend" |
|||
|
|||
export function getAutoColumnInformation(enabled = true) { |
|||
let info = {} |
|||
for (let [key, subtype] of Object.entries(AUTO_COLUMN_SUB_TYPES)) { |
|||
info[subtype] = { enabled, name: AUTO_COLUMN_DISPLAY_NAMES[key] } |
|||
} |
|||
return info |
|||
} |
|||
|
|||
export function buildAutoColumn(tableName, name, subtype) { |
|||
let type, constraints |
|||
switch (subtype) { |
|||
case AUTO_COLUMN_SUB_TYPES.UPDATED_BY: |
|||
case AUTO_COLUMN_SUB_TYPES.CREATED_BY: |
|||
type = FIELDS.LINK.type |
|||
constraints = FIELDS.LINK.constraints |
|||
break |
|||
case AUTO_COLUMN_SUB_TYPES.AUTO_ID: |
|||
type = FIELDS.NUMBER.type |
|||
constraints = FIELDS.NUMBER.constraints |
|||
break |
|||
case AUTO_COLUMN_SUB_TYPES.UPDATED_AT: |
|||
case AUTO_COLUMN_SUB_TYPES.CREATED_AT: |
|||
type = FIELDS.DATETIME.type |
|||
constraints = FIELDS.DATETIME.constraints |
|||
break |
|||
default: |
|||
type = FIELDS.STRING.type |
|||
constraints = FIELDS.STRING.constraints |
|||
break |
|||
} |
|||
if (Object.values(AUTO_COLUMN_SUB_TYPES).indexOf(subtype) === -1) { |
|||
throw "Cannot build auto column with supplied subtype" |
|||
} |
|||
const base = { |
|||
name, |
|||
type, |
|||
subtype, |
|||
icon: "ri-magic-line", |
|||
autocolumn: true, |
|||
constraints, |
|||
} |
|||
if (isAutoColumnUserRelationship(subtype)) { |
|||
base.tableId = TableNames.USERS |
|||
base.fieldName = `${tableName}-${name}` |
|||
} |
|||
return base |
|||
} |
|||
Loading…
Reference in new issue