From b310918ec40bf532412770778ecc7cb5334508f3 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 8 Nov 2021 17:25:05 +0000 Subject: [PATCH] Fixing #3182 so that sorting is disabled for certain column types that we cannot use, as well as fixing some issues with MS-SQL plus tables. --- .../components/backend/DataTable/Table.svelte | 15 +++++++++++++- .../DataTable/modals/CreateEditColumn.svelte | 1 - packages/builder/src/constants/index.js | 9 +++++++++ .../[selectedDatasource]/index.svelte | 4 ++++ packages/client/src/api/datasources.js | 3 ++- packages/client/src/api/rows.js | 3 ++- .../client/src/components/app/Layout.svelte | 9 +++++++-- .../app/forms/RelationshipField.svelte | 3 ++- .../src/components/app/forms/validation.js | 15 +++++++------- .../src/components/app/table/Table.svelte | 5 +++++ packages/client/src/constants.js | 20 +++++++++++++++++++ packages/client/src/stores/dataSource.js | 5 +++-- .../src/integrations/microsoftSqlServer.ts | 4 ++-- .../worker/src/api/controllers/global/auth.js | 3 +-- 14 files changed, 79 insertions(+), 20 deletions(-) diff --git a/packages/builder/src/components/backend/DataTable/Table.svelte b/packages/builder/src/components/backend/DataTable/Table.svelte index 512324254c..1ffac83b1a 100644 --- a/packages/builder/src/components/backend/DataTable/Table.svelte +++ b/packages/builder/src/components/backend/DataTable/Table.svelte @@ -8,7 +8,11 @@ import CreateEditRow from "./modals/CreateEditRow.svelte" import CreateEditUser from "./modals/CreateEditUser.svelte" import CreateEditColumn from "./modals/CreateEditColumn.svelte" - import { TableNames, UNEDITABLE_USER_FIELDS } from "constants" + import { + TableNames, + UNEDITABLE_USER_FIELDS, + UNSORTABLE_TYPES, + } from "constants" import RoleCell from "./cells/RoleCell.svelte" export let schema = {} @@ -33,6 +37,15 @@ $: isUsersTable = tableId === TableNames.USERS $: data && resetSelectedRows() $: editRowComponent = isUsersTable ? CreateEditUser : CreateEditRow + $: { + UNSORTABLE_TYPES.forEach(type => { + Object.values(schema).forEach(col => { + if (col.type === type) { + col.sortable = false + } + }) + }) + } $: { if (isUsersTable) { customRenderers = [ diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 6ee0c48d2a..aa21799ca2 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -92,7 +92,6 @@ opt.type === table.type && table.sourceId === opt.sourceId ) - $: console.log(tableOptions) async function saveColumn() { if (field.type === AUTO_TYPE) { diff --git a/packages/builder/src/constants/index.js b/packages/builder/src/constants/index.js index c0d283b0ea..f13d2b80f0 100644 --- a/packages/builder/src/constants/index.js +++ b/packages/builder/src/constants/index.js @@ -1,3 +1,5 @@ +import { FIELDS } from "constants/backend" + export const TableNames = { USERS: "ta_users", } @@ -39,6 +41,13 @@ export const UNEDITABLE_USER_FIELDS = [ "lastName", ] +export const UNSORTABLE_TYPES = [ + FIELDS.FORMULA.type, + FIELDS.ATTACHMENT.type, + FIELDS.ARRAY.type, + FIELDS.LINK.type, +] + export const LAYOUT_NAMES = { MASTER: { PRIVATE: "layout_private_master", diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte index b1867db248..6cbe0c8359 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte @@ -79,6 +79,10 @@ try { // Create datasource await datasources.save(datasource) + if (datasource?.plus) { + await tables.fetch() + } + await datasources.fetch() notifications.success(`Datasource ${name} updated successfully.`) } catch (err) { notifications.error(`Error saving datasource: ${err}`) diff --git a/packages/client/src/api/datasources.js b/packages/client/src/api/datasources.js index 508e1e8db0..05d06864e2 100644 --- a/packages/client/src/api/datasources.js +++ b/packages/client/src/api/datasources.js @@ -3,6 +3,7 @@ import { fetchTableData } from "./tables" import { fetchViewData } from "./views" import { fetchRelationshipData } from "./relationships" import { executeQuery } from "./queries" +import { FieldTypes } from "../constants" /** * Fetches all rows for a particular Budibase data source. @@ -28,7 +29,7 @@ export const fetchDatasource = async dataSource => { } } rows = await executeQuery({ queryId: dataSource._id, parameters }) - } else if (type === "link") { + } else if (type === FieldTypes.LINK) { rows = await fetchRelationshipData({ rowId: dataSource.rowId, tableId: dataSource.rowTableId, diff --git a/packages/client/src/api/rows.js b/packages/client/src/api/rows.js index acd083454d..7deec349e6 100644 --- a/packages/client/src/api/rows.js +++ b/packages/client/src/api/rows.js @@ -1,6 +1,7 @@ import { notificationStore, dataSourceStore } from "stores" import API from "./api" import { fetchTableDefinition } from "./tables" +import { FieldTypes } from "../constants" /** * Fetches data about a certain row in a table. @@ -129,7 +130,7 @@ export const enrichRows = async (rows, tableId) => { const keys = Object.keys(schema) for (let key of keys) { const type = schema[key].type - if (type === "link" && Array.isArray(row[key])) { + if (type === FieldTypes.LINK && Array.isArray(row[key])) { // Enrich row a string join of relationship fields row[`${key}_text`] = row[key] diff --git a/packages/client/src/components/app/Layout.svelte b/packages/client/src/components/app/Layout.svelte index 0ffbbf7ab1..87e5ac3b5b 100644 --- a/packages/client/src/components/app/Layout.svelte +++ b/packages/client/src/components/app/Layout.svelte @@ -1,6 +1,7 @@