Skip to content

Commit

Permalink
Merge pull request #12020 from Budibase/restrict-display-on-import-table
Browse files Browse the repository at this point in the history
Restrict display on import table
  • Loading branch information
adrinr authored Oct 10, 2023
2 parents 097d3f1 + 63a1ffe commit 8053298
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { FIELDS } from "constants/backend"
import { API } from "api"
import { parseFile } from "./utils"
import { canBeDisplayColumn } from "@budibase/shared-core"
export let rows = []
export let schema = {}
Expand Down Expand Up @@ -97,9 +98,13 @@
let selectedColumnTypes = {}
$: displayColumnOptions = Object.keys(schema || {}).filter(column => {
return validation[column]
return validation[column] && canBeDisplayColumn(schema[column].type)
})
$: if (displayColumn && !canBeDisplayColumn(schema[displayColumn].type)) {
displayColumn = null
}
$: {
// binding in consumer is causing double renders here
const newValidateHash = JSON.stringify(rows) + JSON.stringify(schema)
Expand Down
16 changes: 3 additions & 13 deletions packages/frontend-core/src/components/grid/cells/HeaderCell.svelte
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<script>
import { getContext, onMount, tick } from "svelte"
import { FieldType } from "@budibase/types"
import GridCell from "./GridCell.svelte"
import { canBeDisplayColumn } from "@budibase/shared-core"
import { Icon, Popover, Menu, MenuItem, clickOutside } from "@budibase/bbui"
import GridCell from "./GridCell.svelte"
import { getColumnIcon } from "../lib/utils"
export let column
Expand All @@ -25,15 +25,6 @@
datasource,
} = getContext("grid")
const bannedDisplayColumnTypes = [
FieldType.LINK,
FieldType.ARRAY,
FieldType.ATTACHMENT,
FieldType.BOOLEAN,
FieldType.JSON,
FieldType.BB_REFERENCE,
]
let anchor
let open = false
let editIsOpen = false
Expand Down Expand Up @@ -233,8 +224,7 @@
<MenuItem
icon="Label"
on:click={makeDisplayColumn}
disabled={idx === "sticky" ||
bannedDisplayColumnTypes.includes(column.schema.type)}
disabled={idx === "sticky" || !canBeDisplayColumn(column.schema.type)}
>
Use as display column
</MenuItem>
Expand Down
1 change: 1 addition & 0 deletions packages/shared-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * as dataFilters from "./filters"
export * as helpers from "./helpers"
export * as utils from "./utils"
export * as sdk from "./sdk"
export * from "./table"
25 changes: 25 additions & 0 deletions packages/shared-core/src/table.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { FieldType } from "@budibase/types"

const allowDisplayColumnByType: Record<FieldType, boolean> = {
[FieldType.STRING]: true,
[FieldType.LONGFORM]: true,
[FieldType.OPTIONS]: true,
[FieldType.NUMBER]: true,
[FieldType.DATETIME]: true,
[FieldType.FORMULA]: true,
[FieldType.AUTO]: true,
[FieldType.INTERNAL]: true,
[FieldType.BARCODEQR]: true,
[FieldType.BIGINT]: true,

[FieldType.BOOLEAN]: false,
[FieldType.ARRAY]: false,
[FieldType.ATTACHMENT]: false,
[FieldType.LINK]: false,
[FieldType.JSON]: false,
[FieldType.BB_REFERENCE]: false,
}

export function canBeDisplayColumn(type: FieldType): boolean {
return !!allowDisplayColumnByType[type]
}
3 changes: 2 additions & 1 deletion packages/shared-core/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"skipLibCheck": true,
"paths": {
"@budibase/types": ["../types/src"]
}
},
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
},
"include": ["**/*.js", "**/*.ts"],
"exclude": [
Expand Down
3 changes: 1 addition & 2 deletions packages/shared-core/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"baseUrl": "..",
"rootDir": "src",
"composite": true,
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
"composite": true
},
"exclude": ["node_modules", "dist"]
}
3 changes: 2 additions & 1 deletion packages/types/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"sourceMap": true,
"declaration": true,
"skipLibCheck": true,
"outDir": "dist"
"outDir": "dist",
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "**/*.spec.ts", "**/*.spec.js"]
Expand Down
3 changes: 1 addition & 2 deletions packages/types/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"rootDir": "./src",
"composite": true,
"tsBuildInfoFile": "dist/tsconfig.tsbuildinfo"
"composite": true
},
"exclude": ["node_modules", "dist"]
}

0 comments on commit 8053298

Please sign in to comment.