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

Feat: Add warning popup to editors, when file exceeds threshold #11731

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions changelog/unreleased/enhancement-file-size-warning-in-editors
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Enhancement: File size warning in editors

We've added a warning to the editors, when the respective file size exceeds 2MB.
This will help the user to avoid performance issues when working with large files.

https://github.com/owncloud/web/pull/11731
https://github.com/owncloud/web/issues/8038
3 changes: 3 additions & 0 deletions packages/web-app-text-editor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ export default defineWebApplication({
icon: 'file-text',
color: '#0D856F',
defaultExtension: 'txt',
meta: {
fileSizeLimit: 2000000
},
extensions: fileExtensions().map((extensionItem) => {
return {
extension: extensionItem.extension,
Expand Down
3 changes: 3 additions & 0 deletions packages/web-pkg/src/apps/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ export interface ApplicationInformation {
iconFillType?: IconFillType
iconColor?: string
img?: string
meta?: {
fileSizeLimit?: number
}
/** @deprecated */
isFileEditor?: boolean
extensions?: ApplicationFileExtension[]
Expand Down
51 changes: 44 additions & 7 deletions packages/web-pkg/src/components/AppTemplates/AppWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ import { HttpError } from '@ownclouders/web-client'
import { dirname } from 'path'
import { useFileActionsOpenWithApp } from '../../composables/actions/files/useFileActionsOpenWithApp'
import { UnsavedChangesModal } from '../Modals'
import { formatFileSize } from '../../helpers'
import toNumber from 'lodash-es/toNumber'

export default defineComponent({
name: 'AppWrapper',
Expand Down Expand Up @@ -126,7 +128,7 @@ export default defineComponent({
}
},
setup(props) {
const { $gettext } = useGettext()
const { $gettext, current: currentLanguage } = useGettext()
const appsStore = useAppsStore()
const { showMessage, showErrorMessage } = useMessages()
const router = useRouter()
Expand Down Expand Up @@ -209,6 +211,10 @@ export default defineComponent({

const { applicationMeta } = useAppMeta({ applicationId: props.applicationId, appsStore })

const fileSizeLimit = computed(() => {
return unref(applicationMeta).meta?.fileSizeLimit
})

const pageTitle = computed(() => {
const { name: appName } = unref(applicationMeta)

Expand Down Expand Up @@ -264,17 +270,24 @@ export default defineComponent({
})
}

const loadFileTask = useTask(function* (signal) {
const loadResourceTask = useTask(function* (signal) {
try {
if (!unref(driveAliasAndItem)) {
yield addMissingDriveAliasAndItem()
}

space.value = unref(unref(currentFileContext).space)
resource.value = yield getFileInfo(currentFileContext)
resource.value = yield getFileInfo(currentFileContext, { signal })
resourcesStore.initResourceList({ currentFolder: null, resources: [unref(resource)] })
selectedResources.value = [unref(resource)]
} catch (e) {
console.error(e)
loadingError.value = e
loading.value = false
}
}).restartable()

const loadFileTask = useTask(function* (signal) {
try {
const newExtension = props.importResourceWithExtension(unref(resource))
if (newExtension) {
const timestamp = DateTime.local().toFormat('yyyyMMddHHmmss')
Expand Down Expand Up @@ -318,19 +331,43 @@ export default defineComponent({
signal
})
}
loading.value = false
} catch (e) {
console.error(e)
loadingError.value = e
} finally {
loading.value = false
}
}).restartable()

watch(
currentFileContext,
() => {
async () => {
if (!unref(noResourceLoading)) {
loadFileTask.perform()
await loadResourceTask.perform()

if (unref(fileSizeLimit) && toNumber(unref(resource).size) > unref(fileSizeLimit)) {
dispatchModal({
title: $gettext('File exceeds %{threshold}', {
threshold: formatFileSize(unref(fileSizeLimit), currentLanguage)
}),
message: $gettext(
'%{resource} exceeds the recommended size of %{threshold} for editing, and may cause performance issues.',
{
resource: unref(resource).name,
threshold: formatFileSize(unref(fileSizeLimit), currentLanguage)
}
),
confirmText: $gettext('Continue'),
onCancel: () => {
closeApp()
},
onConfirm: () => {
loadFileTask.perform()
}
})
} else {
loadFileTask.perform()
}
}
},
{ immediate: true }
Expand Down