Some further UI work for auto-columns.

This commit is contained in:
mike12345567 2021-02-16 13:56:40 +00:00
parent 0b891eb283
commit 02a68beee1
8 changed files with 114 additions and 58 deletions

View File

@ -6,6 +6,7 @@
import ExportButton from "./buttons/ExportButton.svelte" import ExportButton from "./buttons/ExportButton.svelte"
import EditRolesButton from "./buttons/EditRolesButton.svelte" import EditRolesButton from "./buttons/EditRolesButton.svelte"
import ManageAccessButton from "./buttons/ManageAccessButton.svelte" import ManageAccessButton from "./buttons/ManageAccessButton.svelte"
import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte"
import * as api from "./api" import * as api from "./api"
import Table from "./Table.svelte" import Table from "./Table.svelte"
import { TableNames } from "constants" import { TableNames } from "constants"
@ -14,6 +15,7 @@
let data = [] let data = []
let loading = false let loading = false
let hideAutocolumns
$: isUsersTable = $backendUiStore.selectedTable?._id === TableNames.USERS $: isUsersTable = $backendUiStore.selectedTable?._id === TableNames.USERS
$: title = $backendUiStore.selectedTable.name $: title = $backendUiStore.selectedTable.name
@ -41,6 +43,7 @@
tableId={$backendUiStore.selectedTable?._id} tableId={$backendUiStore.selectedTable?._id}
{data} {data}
allowEditing={true} allowEditing={true}
bind:hideAutocolumns
{loading}> {loading}>
<CreateColumnButton /> <CreateColumnButton />
{#if schema && Object.keys(schema).length > 0} {#if schema && Object.keys(schema).length > 0}
@ -50,6 +53,7 @@
<CreateViewButton /> <CreateViewButton />
<ManageAccessButton resourceId={$backendUiStore.selectedTable?._id} /> <ManageAccessButton resourceId={$backendUiStore.selectedTable?._id} />
<ExportButton view={tableView} /> <ExportButton view={tableView} />
<HideAutocolumnButton bind:hideAutocolumns />
{/if} {/if}
{#if isUsersTable} {#if isUsersTable}
<EditRolesButton /> <EditRolesButton />

View File

@ -24,6 +24,7 @@
export let allowEditing = false export let allowEditing = false
export let loading = false export let loading = false
export let theme = "alpine" export let theme = "alpine"
export let hideAutocolumns = false
let columnDefs = [] let columnDefs = []
let selectedRows = [] let selectedRows = []
@ -85,7 +86,11 @@
return !(isUsersTable && ["email", "roleId"].includes(key)) return !(isUsersTable && ["email", "roleId"].includes(key))
} }
Object.entries(schema || {}).forEach(([key, value]) => { for (let [key, value] of Object.entries(schema || {})) {
// skip autocolumns if hiding
if (hideAutocolumns && value.autocolumn) {
continue
}
result.push({ result.push({
headerCheckboxSelection: false, headerCheckboxSelection: false,
headerComponent: TableHeader, headerComponent: TableHeader,
@ -108,7 +113,7 @@
resizable: true, resizable: true,
minWidth: 200, minWidth: 200,
}) })
}) }
columnDefs = result columnDefs = result
} }
@ -150,6 +155,7 @@
</div> </div>
</div> </div>
<div class="grid-wrapper"> <div class="grid-wrapper">
{#key columnDefs.length}
<AgGrid <AgGrid
{theme} {theme}
{options} {options}
@ -157,6 +163,7 @@
{columnDefs} {columnDefs}
{loading} {loading}
on:select={({ detail }) => (selectedRows = detail)} /> on:select={({ detail }) => (selectedRows = detail)} />
{/key}
</div> </div>
<style> <style>

View File

@ -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>

View File

@ -12,10 +12,12 @@
import { TableNames, UNEDITABLE_USER_FIELDS } from "constants" import { TableNames, UNEDITABLE_USER_FIELDS } from "constants"
import { import {
FIELDS, FIELDS,
getAutoColumnInformation,
buildAutoColumn,
AUTO_COLUMN_SUB_TYPES, AUTO_COLUMN_SUB_TYPES,
} from "constants/backend" } from "constants/backend"
import {
getAutoColumnInformation,
buildAutoColumn,
} from "utilities/backend"
import { notifier } from "builderStore/store/notifications" import { notifier } from "builderStore/store/notifications"
import ValuesList from "components/common/ValuesList.svelte" import ValuesList from "components/common/ValuesList.svelte"
import DatePicker from "components/common/DatePicker.svelte" import DatePicker from "components/common/DatePicker.svelte"

View File

@ -9,7 +9,7 @@
import { NEW_ROW_TEMPLATE } from "builderStore/store/screenTemplates/newRowScreen" import { NEW_ROW_TEMPLATE } from "builderStore/store/screenTemplates/newRowScreen"
import { ROW_DETAIL_TEMPLATE } from "builderStore/store/screenTemplates/rowDetailScreen" import { ROW_DETAIL_TEMPLATE } from "builderStore/store/screenTemplates/rowDetailScreen"
import { ROW_LIST_TEMPLATE } from "builderStore/store/screenTemplates/rowListScreen" import { ROW_LIST_TEMPLATE } from "builderStore/store/screenTemplates/rowListScreen"
import { buildAutoColumn, getAutoColumnInformation } from "constants/backend" import { buildAutoColumn, getAutoColumnInformation } from "utilities/backend"
const defaultScreens = [ const defaultScreens = [
NEW_ROW_TEMPLATE, NEW_ROW_TEMPLATE,

View File

@ -125,46 +125,3 @@ export function isAutoColumnUserRelationship(subtype) {
subtype === AUTO_COLUMN_SUB_TYPES.UPDATED_BY subtype === AUTO_COLUMN_SUB_TYPES.UPDATED_BY
) )
} }
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
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
}

View File

@ -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
}

View File

@ -101,9 +101,11 @@ async function processAutoColumn(user, table, row) {
row[key] = now row[key] = now
break break
case AutoFieldSubTypes.AUTO_ID: case AutoFieldSubTypes.AUTO_ID:
if (creating) {
schema.lastID = !schema.lastID ? BASE_AUTO_ID : schema.lastID + 1 schema.lastID = !schema.lastID ? BASE_AUTO_ID : schema.lastID + 1
row[key] = schema.lastID row[key] = schema.lastID
tableUpdated = true tableUpdated = true
}
break break
} }
} }