Merge pull request #733 from Budibase/bug/casing-table-fix
Fixing column casing issues
This commit is contained in:
commit
e3514b5250
|
@ -1,4 +1,4 @@
|
||||||
import { writable } from "svelte/store"
|
import { writable, get } from "svelte/store"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import api from "../api"
|
import api from "../api"
|
||||||
|
|
||||||
|
@ -62,16 +62,30 @@ export const getBackendUiStore = () => {
|
||||||
}),
|
}),
|
||||||
save: async table => {
|
save: async table => {
|
||||||
const updatedTable = cloneDeep(table)
|
const updatedTable = cloneDeep(table)
|
||||||
|
const oldTable = get(store).tables.filter(t => t._id === table._id)[0]
|
||||||
|
|
||||||
|
const fieldNames = []
|
||||||
// update any renamed schema keys to reflect their names
|
// update any renamed schema keys to reflect their names
|
||||||
for (let key in updatedTable.schema) {
|
for (let key of Object.keys(updatedTable.schema)) {
|
||||||
|
// if field name has been seen before remove it
|
||||||
|
if (fieldNames.indexOf(key.toLowerCase()) !== -1) {
|
||||||
|
delete updatedTable.schema[key]
|
||||||
|
continue
|
||||||
|
}
|
||||||
const field = updatedTable.schema[key]
|
const field = updatedTable.schema[key]
|
||||||
|
const oldField = oldTable?.schema[key]
|
||||||
|
// if the type has changed then revert back to the old field
|
||||||
|
if (oldField != null && oldField.type !== field.type) {
|
||||||
|
updatedTable.schema[key] = oldField
|
||||||
|
}
|
||||||
// field has been renamed
|
// field has been renamed
|
||||||
if (field.name && field.name !== key) {
|
if (field.name && field.name !== key) {
|
||||||
updatedTable.schema[field.name] = field
|
updatedTable.schema[field.name] = field
|
||||||
updatedTable._rename = { old: key, updated: field.name }
|
updatedTable._rename = { old: key, updated: field.name }
|
||||||
delete updatedTable.schema[key]
|
delete updatedTable.schema[key]
|
||||||
}
|
}
|
||||||
|
// finally record this field has been used
|
||||||
|
fieldNames.push(key.toLowerCase())
|
||||||
}
|
}
|
||||||
|
|
||||||
const SAVE_TABLE_URL = `/api/tables`
|
const SAVE_TABLE_URL = `/api/tables`
|
||||||
|
|
|
@ -132,7 +132,6 @@
|
||||||
font-size: 24px;
|
font-size: 24px;
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
text-rendering: optimizeLegibility;
|
text-rendering: optimizeLegibility;
|
||||||
text-transform: capitalize;
|
|
||||||
margin-top: 0;
|
margin-top: 0;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
|
@ -110,9 +110,6 @@
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: var(--spacing-xs);
|
gap: var(--spacing-xs);
|
||||||
}
|
}
|
||||||
.container span {
|
|
||||||
text-transform: capitalize;
|
|
||||||
}
|
|
||||||
|
|
||||||
h5 {
|
h5 {
|
||||||
padding: var(--spacing-xl) 0 0 var(--spacing-xl);
|
padding: var(--spacing-xl) 0 0 var(--spacing-xl);
|
||||||
|
|
|
@ -27,15 +27,12 @@
|
||||||
const joinPath = join("/")
|
const joinPath = join("/")
|
||||||
|
|
||||||
const normalizedName = name =>
|
const normalizedName = name =>
|
||||||
pipe(
|
pipe(name, [
|
||||||
name,
|
trimCharsStart("./"),
|
||||||
[
|
trimCharsStart("~/"),
|
||||||
trimCharsStart("./"),
|
trimCharsStart("../"),
|
||||||
trimCharsStart("~/"),
|
trimChars(" "),
|
||||||
trimCharsStart("../"),
|
])
|
||||||
trimChars(" "),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
const changeScreen = screen => {
|
const changeScreen = screen => {
|
||||||
store.setCurrentScreen(screen.props._instanceName)
|
store.setCurrentScreen(screen.props._instanceName)
|
||||||
|
|
|
@ -41,6 +41,18 @@ exports.save = async function(ctx) {
|
||||||
oldTable = await db.get(ctx.request.body._id)
|
oldTable = await db.get(ctx.request.body._id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make sure that types don't change of a column, have to remove
|
||||||
|
// the column if you want to change the type
|
||||||
|
if (oldTable && oldTable.schema) {
|
||||||
|
for (let propKey of Object.keys(tableToSave.schema)) {
|
||||||
|
let column = tableToSave.schema[propKey]
|
||||||
|
let oldColumn = oldTable.schema[propKey]
|
||||||
|
if (oldColumn && oldColumn.type !== column.type) {
|
||||||
|
ctx.throw(400, "Cannot change the type of a column")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Don't rename if the name is the same
|
// Don't rename if the name is the same
|
||||||
let { _rename } = tableToSave
|
let { _rename } = tableToSave
|
||||||
if (_rename && _rename.old === _rename.updated) {
|
if (_rename && _rename.old === _rename.updated) {
|
||||||
|
@ -50,9 +62,9 @@ exports.save = async function(ctx) {
|
||||||
|
|
||||||
// rename row fields when table column is renamed
|
// rename row fields when table column is renamed
|
||||||
if (_rename && tableToSave.schema[_rename.updated].type === "link") {
|
if (_rename && tableToSave.schema[_rename.updated].type === "link") {
|
||||||
throw "Cannot rename a linked field."
|
ctx.throw(400, "Cannot rename a linked column.")
|
||||||
} else if (_rename && tableToSave.primaryDisplay === _rename.old) {
|
} else if (_rename && tableToSave.primaryDisplay === _rename.old) {
|
||||||
throw "Cannot rename the display column."
|
ctx.throw(400, "Cannot rename the display column.")
|
||||||
} else if (_rename) {
|
} else if (_rename) {
|
||||||
const rows = await db.allDocs(
|
const rows = await db.allDocs(
|
||||||
getRowParams(tableToSave._id, null, {
|
getRowParams(tableToSave._id, null, {
|
||||||
|
|
|
@ -1,5 +1,10 @@
|
||||||
const LinkController = require("./LinkController")
|
const LinkController = require("./LinkController")
|
||||||
const { IncludeDocs, getLinkDocuments, createLinkView } = require("./linkUtils")
|
const {
|
||||||
|
IncludeDocs,
|
||||||
|
getLinkDocuments,
|
||||||
|
createLinkView,
|
||||||
|
getUniqueByProp,
|
||||||
|
} = require("./linkUtils")
|
||||||
const _ = require("lodash")
|
const _ = require("lodash")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,7 +115,12 @@ exports.attachLinkInfo = async (instanceId, rows) => {
|
||||||
// now iterate through the rows and all field information
|
// now iterate through the rows and all field information
|
||||||
for (let row of rows) {
|
for (let row of rows) {
|
||||||
// get all links for row, ignore fieldName for now
|
// get all links for row, ignore fieldName for now
|
||||||
const linkVals = responses.filter(el => el.thisId === row._id)
|
// have to get unique as the previous table query can
|
||||||
|
// return duplicates, could be querying for both tables in a relation
|
||||||
|
const linkVals = getUniqueByProp(
|
||||||
|
responses.filter(el => el.thisId === row._id),
|
||||||
|
"id"
|
||||||
|
)
|
||||||
for (let linkVal of linkVals) {
|
for (let linkVal of linkVals) {
|
||||||
// work out which link pertains to this row
|
// work out which link pertains to this row
|
||||||
if (!(row[linkVal.fieldName] instanceof Array)) {
|
if (!(row[linkVal.fieldName] instanceof Array)) {
|
||||||
|
|
|
@ -92,3 +92,9 @@ exports.getLinkDocuments = async function({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getUniqueByProp = (array, prop) => {
|
||||||
|
return array.filter((obj, pos, arr) => {
|
||||||
|
return arr.map(mapObj => mapObj[prop]).indexOf(obj[prop]) === pos
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -66,7 +66,7 @@
|
||||||
headerCheckboxSelection: i === 0 && canEdit,
|
headerCheckboxSelection: i === 0 && canEdit,
|
||||||
checkboxSelection: i === 0 && canEdit,
|
checkboxSelection: i === 0 && canEdit,
|
||||||
valueSetter: setters.get(schema[key].type),
|
valueSetter: setters.get(schema[key].type),
|
||||||
headerName: key.charAt(0).toUpperCase() + key.slice(1),
|
headerName: key,
|
||||||
field: key,
|
field: key,
|
||||||
hide: shouldHideField(key),
|
hide: shouldHideField(key),
|
||||||
sortable: true,
|
sortable: true,
|
||||||
|
@ -75,19 +75,22 @@
|
||||||
autoHeight: true,
|
autoHeight: true,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
columnDefs = [...columnDefs, {
|
columnDefs = [
|
||||||
headerName: 'Details',
|
...columnDefs,
|
||||||
field: '_id',
|
{
|
||||||
|
headerName: "Details",
|
||||||
|
field: "_id",
|
||||||
width: 25,
|
width: 25,
|
||||||
flex: 0,
|
flex: 0,
|
||||||
editable: false,
|
editable: false,
|
||||||
sortable: false,
|
sortable: false,
|
||||||
cellRenderer: getRenderer({
|
cellRenderer: getRenderer({
|
||||||
type: '_id',
|
type: "_id",
|
||||||
options: detailUrl
|
options: detailUrl,
|
||||||
}),
|
}),
|
||||||
autoHeight: true,
|
autoHeight: true,
|
||||||
}]
|
},
|
||||||
|
]
|
||||||
dataLoaded = true
|
dataLoaded = true
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<script>
|
<script>
|
||||||
import { Icon } from '@budibase/bbui'
|
import { Icon } from "@budibase/bbui"
|
||||||
export let url
|
export let url
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a href={url}><Icon name="view" /></a>
|
<a href={url}><Icon name="view" /></a>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
a {
|
a {
|
||||||
color: var(--grey-6)
|
color: var(--grey-6);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
Loading…
Reference in New Issue