From 113de648334ca86cf36607801a358c57652a8253 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 16 Feb 2021 13:56:40 +0000 Subject: [PATCH] Some further UI work for auto-columns. --- .../backend/DataTable/DataTable.svelte | 4 ++ .../components/backend/DataTable/Table.svelte | 25 ++++++--- .../buttons/HideAutocolumnButton.svelte | 29 ++++++++++ .../DataTable/modals/CreateEditColumn.svelte | 6 +- .../modals/CreateTableModal.svelte | 2 +- .../builder/src/constants/backend/index.js | 43 --------------- .../builder/src/utilities/backend/index.js | 55 +++++++++++++++++++ packages/server/src/utilities/rowProcessor.js | 8 ++- 8 files changed, 114 insertions(+), 58 deletions(-) create mode 100644 packages/builder/src/components/backend/DataTable/buttons/HideAutocolumnButton.svelte create mode 100644 packages/builder/src/utilities/backend/index.js diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 577fda62a8..b0a1c0fdfe 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -6,6 +6,7 @@ import ExportButton from "./buttons/ExportButton.svelte" import EditRolesButton from "./buttons/EditRolesButton.svelte" import ManageAccessButton from "./buttons/ManageAccessButton.svelte" + import HideAutocolumnButton from "./buttons/HideAutocolumnButton.svelte" import * as api from "./api" import Table from "./Table.svelte" import { TableNames } from "constants" @@ -14,6 +15,7 @@ let data = [] let loading = false + let hideAutocolumns $: isUsersTable = $backendUiStore.selectedTable?._id === TableNames.USERS $: title = $backendUiStore.selectedTable.name @@ -41,6 +43,7 @@ tableId={$backendUiStore.selectedTable?._id} {data} allowEditing={true} + bind:hideAutocolumns {loading}> {#if schema && Object.keys(schema).length > 0} @@ -50,6 +53,7 @@ + {/if} {#if isUsersTable} diff --git a/packages/builder/src/components/backend/DataTable/Table.svelte b/packages/builder/src/components/backend/DataTable/Table.svelte index 070ebec080..825ed6af7b 100644 --- a/packages/builder/src/components/backend/DataTable/Table.svelte +++ b/packages/builder/src/components/backend/DataTable/Table.svelte @@ -24,6 +24,7 @@ export let allowEditing = false export let loading = false export let theme = "alpine" + export let hideAutocolumns = false let columnDefs = [] let selectedRows = [] @@ -85,7 +86,11 @@ 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({ headerCheckboxSelection: false, headerComponent: TableHeader, @@ -108,7 +113,7 @@ resizable: true, minWidth: 200, }) - }) + } columnDefs = result } @@ -150,13 +155,15 @@
- (selectedRows = detail)} /> + {#key columnDefs.length} + (selectedRows = detail)} /> + {/key}
diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 86a321865d..eba5a99e87 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -12,10 +12,12 @@ import { TableNames, UNEDITABLE_USER_FIELDS } from "constants" import { FIELDS, - getAutoColumnInformation, - buildAutoColumn, AUTO_COLUMN_SUB_TYPES, } from "constants/backend" + import { + getAutoColumnInformation, + buildAutoColumn, + } from "utilities/backend" import { notifier } from "builderStore/store/notifications" import ValuesList from "components/common/ValuesList.svelte" import DatePicker from "components/common/DatePicker.svelte" diff --git a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte index 7365f3e64e..cba0cb02cd 100644 --- a/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte +++ b/packages/builder/src/components/backend/TableNavigator/modals/CreateTableModal.svelte @@ -9,7 +9,7 @@ import { NEW_ROW_TEMPLATE } from "builderStore/store/screenTemplates/newRowScreen" import { ROW_DETAIL_TEMPLATE } from "builderStore/store/screenTemplates/rowDetailScreen" import { ROW_LIST_TEMPLATE } from "builderStore/store/screenTemplates/rowListScreen" - import { buildAutoColumn, getAutoColumnInformation } from "constants/backend" + import { buildAutoColumn, getAutoColumnInformation } from "utilities/backend" const defaultScreens = [ NEW_ROW_TEMPLATE, diff --git a/packages/builder/src/constants/backend/index.js b/packages/builder/src/constants/backend/index.js index 02e62e7e27..9fa9900a2f 100644 --- a/packages/builder/src/constants/backend/index.js +++ b/packages/builder/src/constants/backend/index.js @@ -125,46 +125,3 @@ export function isAutoColumnUserRelationship(subtype) { 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 -} diff --git a/packages/builder/src/utilities/backend/index.js b/packages/builder/src/utilities/backend/index.js new file mode 100644 index 0000000000..464b25f5d3 --- /dev/null +++ b/packages/builder/src/utilities/backend/index.js @@ -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 +} \ No newline at end of file diff --git a/packages/server/src/utilities/rowProcessor.js b/packages/server/src/utilities/rowProcessor.js index ceb31daa3b..5374adf808 100644 --- a/packages/server/src/utilities/rowProcessor.js +++ b/packages/server/src/utilities/rowProcessor.js @@ -101,9 +101,11 @@ async function processAutoColumn(user, table, row) { row[key] = now break case AutoFieldSubTypes.AUTO_ID: - schema.lastID = !schema.lastID ? BASE_AUTO_ID : schema.lastID + 1 - row[key] = schema.lastID - tableUpdated = true + if (creating) { + schema.lastID = !schema.lastID ? BASE_AUTO_ID : schema.lastID + 1 + row[key] = schema.lastID + tableUpdated = true + } break } }