remove file size limit on self host

This commit is contained in:
Martin McKeaveney 2024-05-15 14:23:08 +01:00
parent 2a09e591dc
commit 1b2053633d
9 changed files with 74 additions and 6 deletions

View File

@ -2,7 +2,7 @@
import "@spectrum-css/dropzone/dist/index-vars.css" import "@spectrum-css/dropzone/dist/index-vars.css"
import "@spectrum-css/typography/dist/index-vars.css" import "@spectrum-css/typography/dist/index-vars.css"
import "@spectrum-css/illustratedmessage/dist/index-vars.css" import "@spectrum-css/illustratedmessage/dist/index-vars.css"
import { createEventDispatcher } from "svelte" import { createEventDispatcher, getContext } from "svelte"
import { uuid } from "../../helpers" import { uuid } from "../../helpers"
import Icon from "../../Icon/Icon.svelte" import Icon from "../../Icon/Icon.svelte"
import Link from "../../Link/Link.svelte" import Link from "../../Link/Link.svelte"

View File

@ -1,5 +1,6 @@
<script> <script>
import { datasources, tables, integrations, appStore } from "stores/builder" import { datasources, tables, integrations, appStore } from "stores/builder"
import { admin } from "stores/portal"
import EditRolesButton from "./buttons/EditRolesButton.svelte" import EditRolesButton from "./buttons/EditRolesButton.svelte"
import { TableNames } from "constants" import { TableNames } from "constants"
import { Grid } from "@budibase/frontend-core" import { Grid } from "@budibase/frontend-core"
@ -63,6 +64,7 @@
schemaOverrides={isUsersTable ? userSchemaOverrides : null} schemaOverrides={isUsersTable ? userSchemaOverrides : null}
showAvatars={false} showAvatars={false}
on:updatedatasource={handleGridTableUpdate} on:updatedatasource={handleGridTableUpdate}
isCloud={$admin.cloud}
> >
<svelte:fragment slot="filter"> <svelte:fragment slot="filter">
{#if isUsersTable && $appStore.features.disableUserMetadata} {#if isUsersTable && $appStore.features.disableUserMetadata}

View File

@ -1,5 +1,6 @@
<script> <script>
import { viewsV2 } from "stores/builder" import { viewsV2 } from "stores/builder"
import { admin } from "stores/portal"
import { Grid } from "@budibase/frontend-core" import { Grid } from "@budibase/frontend-core"
import { API } from "api" import { API } from "api"
import GridCreateEditRowModal from "components/backend/DataTable/modals/grid/GridCreateEditRowModal.svelte" import GridCreateEditRowModal from "components/backend/DataTable/modals/grid/GridCreateEditRowModal.svelte"
@ -26,6 +27,7 @@
allowDeleteRows allowDeleteRows
showAvatars={false} showAvatars={false}
on:updatedatasource={handleGridViewUpdate} on:updatedatasource={handleGridViewUpdate}
isCloud={$admin.cloud}
> >
<svelte:fragment slot="filter"> <svelte:fragment slot="filter">
<GridFilterButton /> <GridFilterButton />

View File

@ -0,0 +1,57 @@
import { it, expect, describe, vi } from "vitest"
import Dropzone from "./Dropzone.svelte"
import { render, fireEvent } from "@testing-library/svelte"
import { notifications } from "@budibase/bbui";
import { admin } from "stores/portal"
vi.spyOn(notifications, "error").mockImplementation(() => {});
describe("Dropzone", () => {
let instance = null
afterEach(() => {
vi.restoreAllMocks()
})
it("that the Dropzone is rendered", () => {
instance = render(Dropzone, {})
expect(instance).toBeDefined()
})
it("Ensure the correct error message is shown when uploading the file in cloud", async () => {
admin.subscribe = vi.fn().mockImplementation(callback => {
callback({ cloud: true })
return () => {}
})
instance = render(Dropzone, { props: { fileSizeLimit: 1000000 } }) // 1MB
const fileInput = instance.getByLabelText("Select a file to upload")
const file = new File(
["hello".repeat(2000000)],
"hello.png",
{
type: "image/png"
}
)
await fireEvent.change(fileInput, { target: { files: [file] } });
expect(notifications.error).toHaveBeenCalledWith("Files cannot exceed 1MB. Please try again with smaller files.")
})
it("Ensure the file size error message is not shown when running on self host", async () => {
admin.subscribe = vi.fn().mockImplementation(callback => {
callback({ cloud: false })
return () => {}
})
instance = render(Dropzone, { props: { fileSizeLimit: 1000000 } }) // 1MB
const fileInput = instance.getByLabelText("Select a file to upload")
const file = new File(
["hello".repeat(2000000)],
"hello.png",
{
type: "image/png"
}
)
await fireEvent.change(fileInput, { target: { files: [file] } });
expect(notifications.error).not.toHaveBeenCalledWith("Files cannot exceed 1MB. Please try again with smaller files.")
})
})

View File

@ -1,9 +1,11 @@
<script> <script>
import { Dropzone, notifications } from "@budibase/bbui" import { Dropzone, notifications } from "@budibase/bbui"
import { admin } from "stores/portal"
import { API } from "api" import { API } from "api"
export let value = [] export let value = []
export let label export let label
export let fileSizeLimit = undefined
const BYTES_IN_MB = 1000000 const BYTES_IN_MB = 1000000
@ -34,5 +36,6 @@
{label} {label}
{...$$restProps} {...$$restProps}
{processFiles} {processFiles}
{handleFileTooLarge} handleFileTooLarge={$admin.cloud ? handleFileTooLarge : null}
{fileSizeLimit}
/> />

View File

@ -22,6 +22,7 @@
const context = getContext("context") const context = getContext("context")
const component = getContext("component") const component = getContext("component")
const { environmentStore } = getContext("sdk")
const { const {
styleable, styleable,
API, API,
@ -168,6 +169,7 @@
notifySuccess={notificationStore.actions.success} notifySuccess={notificationStore.actions.success}
notifyError={notificationStore.actions.error} notifyError={notificationStore.actions.error}
buttons={enrichedButtons} buttons={enrichedButtons}
isCloud={$environmentStore.cloud}
on:rowclick={e => onRowClick?.({ row: e.detail })} on:rowclick={e => onRowClick?.({ row: e.detail })}
/> />
</span> </span>

View File

@ -25,7 +25,7 @@
let fieldState let fieldState
let fieldApi let fieldApi
const { API, notificationStore } = getContext("sdk") const { API, notificationStore, environmentStore } = getContext("sdk")
const formContext = getContext("form") const formContext = getContext("form")
const BYTES_IN_MB = 1000000 const BYTES_IN_MB = 1000000
@ -87,7 +87,7 @@
error={fieldState.error} error={fieldState.error}
on:change={handleChange} on:change={handleChange}
{processFiles} {processFiles}
{handleFileTooLarge} handleFileTooLarge={$environmentStore.cloud ? handleFileTooLarge : null}
{handleTooManyFiles} {handleTooManyFiles}
{maximum} {maximum}
{extensions} {extensions}

View File

@ -12,7 +12,7 @@
export let schema export let schema
export let maximum export let maximum
const { API, notifications } = getContext("grid") const { API, notifications, isCloud } = getContext("grid")
const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"] const imageExtensions = ["png", "tiff", "gif", "raw", "jpg", "jpeg"]
let isOpen = false let isOpen = false
@ -106,7 +106,7 @@
on:change={e => onChange(e.detail)} on:change={e => onChange(e.detail)}
maximum={maximum || schema.constraints?.length?.maximum} maximum={maximum || schema.constraints?.length?.maximum}
{processFiles} {processFiles}
{handleFileTooLarge} handleFileTooLarge={isCloud ? handleFileTooLarge : null}
/> />
</div> </div>
</GridPopover> </GridPopover>

View File

@ -54,6 +54,7 @@
export let notifySuccess = null export let notifySuccess = null
export let notifyError = null export let notifyError = null
export let buttons = null export let buttons = null
export let isCloud = null
// Unique identifier for DOM nodes inside this instance // Unique identifier for DOM nodes inside this instance
const gridID = `grid-${Math.random().toString().slice(2)}` const gridID = `grid-${Math.random().toString().slice(2)}`
@ -108,6 +109,7 @@
notifySuccess, notifySuccess,
notifyError, notifyError,
buttons, buttons,
isCloud,
}) })
$: minHeight = $: minHeight =
Padding + SmallRowHeight + $rowHeight + (showControls ? ControlsHeight : 0) Padding + SmallRowHeight + $rowHeight + (showControls ? ControlsHeight : 0)