Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single attachment column type #13399

Merged
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a4c8fcb
Clean and populate url
adrinr Apr 3, 2024
7d0090a
Fix import/export
adrinr Apr 3, 2024
5437188
Revert "Revert "Single attachment column type""
mike12345567 Apr 3, 2024
dc18b55
Merge pull request #13397 from Budibase/BUDI-8122/dont-persist-url-on…
adrinr Apr 3, 2024
2cd3882
Merge branch 'master' into revert-13398-revert-13356-BUDI-8122/single…
adrinr Apr 4, 2024
6d9d1ac
Update yarn.lock
adrinr Apr 4, 2024
0cb956a
Update submodules
adrinr Apr 4, 2024
c9c3a05
Merge branch 'master' into revert-13398-revert-13356-BUDI-8122/single…
adrinr Apr 4, 2024
615e27c
Merge branch 'master' into revert-13398-revert-13356-BUDI-8122/single…
adrinr Apr 4, 2024
28d10ec
Fix
adrinr Apr 4, 2024
b2ab4e0
Handle singleattachment on AttachmentCleanup
adrinr Apr 4, 2024
e584392
Add attachment_single tests
adrinr Apr 4, 2024
6928e74
Handle single files on imports
adrinr Apr 4, 2024
80dfef9
Test single attachment on outputProcessing
adrinr Apr 4, 2024
1bc5553
Lint
adrinr Apr 4, 2024
5b6c3d0
Merge branch 'master' into revert-13398-revert-13356-BUDI-8122/single…
adrinr Apr 10, 2024
4ca090b
Add single attachment as component on "add component"
adrinr Apr 10, 2024
f69056c
PR comments
adrinr Apr 10, 2024
f6eb27c
Fix merge conflicts
adrinr Apr 10, 2024
8f9dea4
Merge pull request #13408 from Budibase/BUDI-8122/tests
adrinr Apr 10, 2024
b42cc88
Merge pull request #13407 from Budibase/BUDI-8122/attachment_cleanup
adrinr Apr 10, 2024
b4063fa
Merge branch 'master' into revert-13398-revert-13356-BUDI-8122/single…
adrinr Apr 10, 2024
5a93f2b
Change icons to attach
adrinr Apr 10, 2024
38f5302
Revert check
adrinr Apr 10, 2024
e525e0d
Merge branch 'master' into revert-13398-revert-13356-BUDI-8122/single…
adrinr Apr 10, 2024
b707514
Update pro ref to fix flakiness
adrinr Apr 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/account-portal
2 changes: 1 addition & 1 deletion packages/bbui/src/Form/Core/Dropzone.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
}

$: showDropzone =
(!maximum || (maximum && value?.length < maximum)) && !disabled
(!maximum || (maximum && (value?.length || 0) < maximum)) && !disabled

async function processFileList(fileList) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const MAX_DEPTH = 1
const TYPES_TO_SKIP = [
FieldType.FORMULA,
FieldType.LONGFORM,
FieldType.ATTACHMENT,
FieldType.ATTACHMENTS,
//https://github.com/Budibase/budibase/issues/3030
FieldType.INTERNAL,
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,8 @@
FIELDS.BIGINT,
FIELDS.BOOLEAN,
FIELDS.DATETIME,
FIELDS.ATTACHMENT,
FIELDS.ATTACHMENT_SINGLE,
FIELDS.ATTACHMENTS,
FIELDS.LINK,
FIELDS.FORMULA,
FIELDS.JSON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export const FieldTypeToComponentMap = {
[FieldType.BOOLEAN]: "booleanfield",
[FieldType.LONGFORM]: "longformfield",
[FieldType.DATETIME]: "datetimefield",
[FieldType.ATTACHMENT]: "attachmentfield",
[FieldType.ATTACHMENTS]: "attachmentfield",
[FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield",
[FieldType.LINK]: "relationshipfield",
[FieldType.JSON]: "jsonfield",
[FieldType.BARCODEQR]: "codescanner",
Expand Down
16 changes: 12 additions & 4 deletions packages/builder/src/constants/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,18 @@ export const FIELDS = {
},
},
},
ATTACHMENT: {
ATTACHMENT_SINGLE: {
name: "Attachment",
type: FieldType.ATTACHMENT,
icon: "Folder",
type: FieldType.ATTACHMENT_SINGLE,
icon: "Document",
constraints: {
presence: false,
},
},
ATTACHMENTS: {
name: "Attachment List",
type: FieldType.ATTACHMENTS,
icon: "AppleFiles",
constraints: {
type: "array",
presence: false,
Expand Down Expand Up @@ -299,7 +307,7 @@ export const PaginationLocations = [

export const BannedSearchTypes = [
FieldType.LINK,
FieldType.ATTACHMENT,
FieldType.ATTACHMENTS,
FieldType.FORMULA,
FieldType.JSON,
"jsonarray",
Expand Down
3 changes: 0 additions & 3 deletions packages/builder/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"extends": "./tsconfig.build.json",
"compilerOptions": {
"composite": true,
"declaration": true,
"sourceMap": true,
"baseUrl": ".",
"paths": {
"assets/*": ["./assets/*"],
Expand Down
99 changes: 98 additions & 1 deletion packages/client/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4226,7 +4226,7 @@
]
},
"attachmentfield": {
"name": "Attachment",
"name": "Attachment list",
"icon": "Attach",
"styles": ["size"],
"requiredAncestors": ["form"],
Expand Down Expand Up @@ -4322,6 +4322,103 @@
}
]
},
"attachmentsinglefield": {
"name": "Single Attachment",
"icon": "Attach",
"styles": ["size"],
"requiredAncestors": ["form"],
"editable": true,
"size": {
"width": 400,
"height": 200
},
"settings": [
{
"type": "field/attachment_single",
adrinr marked this conversation as resolved.
Show resolved Hide resolved
"label": "Field",
"key": "field",
"required": true
},
{
"type": "text",
"label": "Label",
"key": "label"
},
{
"type": "text",
"label": "Help text",
"key": "helpText"
},
{
"type": "text",
"label": "Extensions",
"key": "extensions"
},
{
"type": "number",
"label": "Max attachments",
"key": "maximum",
adrinr marked this conversation as resolved.
Show resolved Hide resolved
"min": 1
},
{
"type": "event",
"label": "On change",
"key": "onChange",
"context": [
{
"label": "Field Value",
"key": "value"
}
]
},
{
"type": "boolean",
"label": "Compact",
"key": "compact",
"defaultValue": false
},
{
"type": "boolean",
"label": "Read only",
"key": "disabled",
"defaultValue": false
},
{
"type": "validation/attachment",
"label": "Validation",
"key": "validation"
},
{
"type": "select",
"label": "Layout",
"key": "span",
"defaultValue": 6,
"hidden": true,
"showInBar": true,
"barStyle": "buttons",
"options": [
{
"label": "1 column",
"value": 6,
"barIcon": "Stop",
"barTitle": "1 column"
},
{
"label": "2 columns",
"value": 3,
"barIcon": "ColumnTwoA",
"barTitle": "2 columns"
},
{
"label": "3 columns",
"value": 2,
"barIcon": "ViewColumn",
"barTitle": "3 columns"
}
]
}
]
},
"relationshipfield": {
"name": "Relationship Picker",
"icon": "TaskList",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
[FieldType.BOOLEAN]: "booleanfield",
[FieldType.LONGFORM]: "longformfield",
[FieldType.DATETIME]: "datetimefield",
[FieldType.ATTACHMENT]: "attachmentfield",
[FieldType.ATTACHMENTS]: "attachmentfield",
[FieldType.ATTACHMENT_SINGLE]: "attachmentsinglefield",
[FieldType.LINK]: "relationshipfield",
[FieldType.JSON]: "jsonfield",
[FieldType.BARCODEQR]: "codescanner",
Expand Down Expand Up @@ -60,7 +61,7 @@

function getPropsByType(field) {
const propsMapByType = {
[FieldType.ATTACHMENT]: (_field, schema) => {
[FieldType.ATTACHMENTS]: (_field, schema) => {
return {
maximum: schema?.constraints?.length?.maximum,
}
Expand Down
15 changes: 11 additions & 4 deletions packages/client/src/components/app/forms/AttachmentField.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
import Field from "./Field.svelte"
import { CoreDropzone } from "@budibase/bbui"
import { FieldType } from "@budibase/types"
import { getContext } from "svelte"

export let field
Expand All @@ -14,6 +15,11 @@
export let maximum = undefined
export let span
export let helpText = null
export let type = FieldType.ATTACHMENTS
export let fieldApiMapper = {
get: value => value,
set: value => value,
}

let fieldState
let fieldApi
Expand Down Expand Up @@ -63,9 +69,10 @@
}

const handleChange = e => {
const changed = fieldApi.setValue(e.detail)
const value = fieldApiMapper.set(e.detail)
const changed = fieldApi.setValue(value)
if (onChange && changed) {
onChange({ value: e.detail })
onChange({ value })
}
}
</script>
Expand All @@ -78,14 +85,14 @@
{validation}
{span}
{helpText}
type="attachment"
{type}
bind:fieldState
bind:fieldApi
defaultValue={[]}
adrinr marked this conversation as resolved.
Show resolved Hide resolved
>
{#if fieldState}
<CoreDropzone
value={fieldState.value}
value={fieldApiMapper.get(fieldState.value)}
disabled={fieldState.disabled || fieldState.readonly}
error={fieldState.error}
on:change={handleChange}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<script>
import { FieldType } from "@budibase/types"
import AttachmentField from "./AttachmentField.svelte"

const fieldApiMapper = {
get: value => (!Array.isArray(value) && value ? [value] : value) || [],
set: value => value[0] || null,
}
</script>

<AttachmentField
{...$$restProps}
type={FieldType.ATTACHMENT_SINGLE}
maximum={1}
{fieldApiMapper}
/>
1 change: 1 addition & 0 deletions packages/client/src/components/app/forms/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export { default as booleanfield } from "./BooleanField.svelte"
export { default as longformfield } from "./LongFormField.svelte"
export { default as datetimefield } from "./DateTimeField.svelte"
export { default as attachmentfield } from "./AttachmentField.svelte"
export { default as attachmentsinglefield } from "./AttachmentSingleField.svelte"
export { default as relationshipfield } from "./RelationshipField.svelte"
export { default as passwordfield } from "./PasswordField.svelte"
export { default as formstep } from "./FormStep.svelte"
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/components/app/forms/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const parseType = (value, type) => {
}

// Parse attachments, treating no elements as null
if (type === FieldTypes.ATTACHMENT) {
if (type === FieldTypes.ATTACHMENTS) {
if (!Array.isArray(value) || !value.length) {
return null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
export let invertX = false
export let invertY = false
export let schema
export let maximum

const { API, notifications } = getContext("grid")
const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
Expand Down Expand Up @@ -98,7 +99,7 @@
{value}
compact
on:change={e => onChange(e.detail)}
maximum={schema.constraints?.length?.maximum}
maximum={maximum || schema.constraints?.length?.maximum}
{processFiles}
{deleteAttachments}
{handleFileTooLarge}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script>
import AttachmentCell from "./AttachmentCell.svelte"

export let value
export let onChange

$: arrayValue = (!Array.isArray(value) && value ? [value] : value) || []

$: onFileChange = value => {
value = value[0] || null
onChange(value)
}
</script>

<AttachmentCell
{...$$restProps}
maximum={1}
adrinr marked this conversation as resolved.
Show resolved Hide resolved
value={arrayValue}
onChange={onFileChange}
/>
4 changes: 3 additions & 1 deletion packages/frontend-core/src/components/grid/lib/renderers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BooleanCell from "../cells/BooleanCell.svelte"
import FormulaCell from "../cells/FormulaCell.svelte"
import JSONCell from "../cells/JSONCell.svelte"
import AttachmentCell from "../cells/AttachmentCell.svelte"
import AttachmentSingleCell from "../cells/AttachmentSingleCell.svelte"
import BBReferenceCell from "../cells/BBReferenceCell.svelte"

const TypeComponentMap = {
Expand All @@ -22,7 +23,8 @@ const TypeComponentMap = {
[FieldType.ARRAY]: MultiSelectCell,
[FieldType.NUMBER]: NumberCell,
[FieldType.BOOLEAN]: BooleanCell,
[FieldType.ATTACHMENT]: AttachmentCell,
[FieldType.ATTACHMENTS]: AttachmentCell,
[FieldType.ATTACHMENT_SINGLE]: AttachmentSingleCell,
[FieldType.LINK]: RelationshipCell,
[FieldType.FORMULA]: FormulaCell,
[FieldType.JSON]: JSONCell,
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend-core/src/components/grid/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const TypeIconMap = {
[FieldType.ARRAY]: "Dropdown",
[FieldType.NUMBER]: "123",
[FieldType.BOOLEAN]: "Boolean",
[FieldType.ATTACHMENT]: "AppleFiles",
[FieldType.ATTACHMENTS]: "AppleFiles",
[FieldType.ATTACHMENT_SINGLE]: "Document",
[FieldType.LINK]: "DataCorrelated",
[FieldType.FORMULA]: "Calculator",
[FieldType.JSON]: "Brackets",
Expand Down
2 changes: 1 addition & 1 deletion packages/pro
Submodule pro updated from 6b6250 to f8e8f8