Skip to content

Commit eda5bbb

Browse files
authored
Feat: Add warning popup to editors, when file exceeds threshold (#11731)
* Feat: Add warning popup to editors, when file exceeds threshold
1 parent 923b63b commit eda5bbb

File tree

4 files changed

+57
-7
lines changed

4 files changed

+57
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Enhancement: File size warning in editors
2+
3+
We've added a warning to the editors, when the respective file size exceeds 2MB.
4+
This will help the user to avoid performance issues when working with large files.
5+
6+
https://github.com/owncloud/web/pull/11731
7+
https://github.com/owncloud/web/issues/8038

packages/web-app-text-editor/src/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ export default defineWebApplication({
105105
icon: 'file-text',
106106
color: '#0D856F',
107107
defaultExtension: 'txt',
108+
meta: {
109+
fileSizeLimit: 2000000
110+
},
108111
extensions: fileExtensions().map((extensionItem) => {
109112
return {
110113
extension: extensionItem.extension,

packages/web-pkg/src/apps/types.ts

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export interface ApplicationInformation {
7474
iconFillType?: IconFillType
7575
iconColor?: string
7676
img?: string
77+
meta?: {
78+
fileSizeLimit?: number
79+
}
7780
/** @deprecated */
7881
isFileEditor?: boolean
7982
extensions?: ApplicationFileExtension[]

packages/web-pkg/src/components/AppTemplates/AppWrapper.vue

+44-7
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ import { HttpError } from '@ownclouders/web-client'
9191
import { dirname } from 'path'
9292
import { useFileActionsOpenWithApp } from '../../composables/actions/files/useFileActionsOpenWithApp'
9393
import { UnsavedChangesModal } from '../Modals'
94+
import { formatFileSize } from '../../helpers'
95+
import toNumber from 'lodash-es/toNumber'
9496
9597
export default defineComponent({
9698
name: 'AppWrapper',
@@ -126,7 +128,7 @@ export default defineComponent({
126128
}
127129
},
128130
setup(props) {
129-
const { $gettext } = useGettext()
131+
const { $gettext, current: currentLanguage } = useGettext()
130132
const appsStore = useAppsStore()
131133
const { showMessage, showErrorMessage } = useMessages()
132134
const router = useRouter()
@@ -209,6 +211,10 @@ export default defineComponent({
209211
210212
const { applicationMeta } = useAppMeta({ applicationId: props.applicationId, appsStore })
211213
214+
const fileSizeLimit = computed(() => {
215+
return unref(applicationMeta).meta?.fileSizeLimit
216+
})
217+
212218
const pageTitle = computed(() => {
213219
const { name: appName } = unref(applicationMeta)
214220
@@ -264,17 +270,24 @@ export default defineComponent({
264270
})
265271
}
266272
267-
const loadFileTask = useTask(function* (signal) {
273+
const loadResourceTask = useTask(function* (signal) {
268274
try {
269275
if (!unref(driveAliasAndItem)) {
270276
yield addMissingDriveAliasAndItem()
271277
}
272-
273278
space.value = unref(unref(currentFileContext).space)
274-
resource.value = yield getFileInfo(currentFileContext)
279+
resource.value = yield getFileInfo(currentFileContext, { signal })
275280
resourcesStore.initResourceList({ currentFolder: null, resources: [unref(resource)] })
276281
selectedResources.value = [unref(resource)]
282+
} catch (e) {
283+
console.error(e)
284+
loadingError.value = e
285+
loading.value = false
286+
}
287+
}).restartable()
277288
289+
const loadFileTask = useTask(function* (signal) {
290+
try {
278291
const newExtension = props.importResourceWithExtension(unref(resource))
279292
if (newExtension) {
280293
const timestamp = DateTime.local().toFormat('yyyyMMddHHmmss')
@@ -318,19 +331,43 @@ export default defineComponent({
318331
signal
319332
})
320333
}
321-
loading.value = false
322334
} catch (e) {
323335
console.error(e)
324336
loadingError.value = e
337+
} finally {
325338
loading.value = false
326339
}
327340
}).restartable()
328341
329342
watch(
330343
currentFileContext,
331-
() => {
344+
async () => {
332345
if (!unref(noResourceLoading)) {
333-
loadFileTask.perform()
346+
await loadResourceTask.perform()
347+
348+
if (unref(fileSizeLimit) && toNumber(unref(resource).size) > unref(fileSizeLimit)) {
349+
dispatchModal({
350+
title: $gettext('File exceeds %{threshold}', {
351+
threshold: formatFileSize(unref(fileSizeLimit), currentLanguage)
352+
}),
353+
message: $gettext(
354+
'%{resource} exceeds the recommended size of %{threshold} for editing, and may cause performance issues.',
355+
{
356+
resource: unref(resource).name,
357+
threshold: formatFileSize(unref(fileSizeLimit), currentLanguage)
358+
}
359+
),
360+
confirmText: $gettext('Continue'),
361+
onCancel: () => {
362+
closeApp()
363+
},
364+
onConfirm: () => {
365+
loadFileTask.perform()
366+
}
367+
})
368+
} else {
369+
loadFileTask.perform()
370+
}
334371
}
335372
},
336373
{ immediate: true }

0 commit comments

Comments
 (0)