Skip to content

Commit dea4bbb

Browse files
committed
fix(web-pkg): hide sidebar editor action when the editor is already opened
When an editor is already opened and the user clicks on the Open in ... action, it pushes the same editor route into the history causing a bug where the user needs to click twice on the close button to actually close the editor. This change hides the editor action if an editor with matching route name is already opened which prevents this behaviour.
1 parent 9bd1cb6 commit dea4bbb

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Enhancement: Hide active editor action
2+
3+
We've hidden the sidebar file action of a currently opened editor. This prevents confusion where user might try to re-open the current editor.
4+
5+
https://github.com/owncloud/web/pull/12110
6+
https://github.com/owncloud/web/issues/12108

packages/web-pkg/src/composables/actions/files/useFileActions.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import { Resource, SpaceResource } from '@ownclouders/web-client'
4040
import { storeToRefs } from 'pinia'
4141
import { useEmbedMode } from '../../embedMode'
4242
import { RouteRecordName } from 'vue-router'
43+
import { isLocationActive } from '../../../router/utils'
4344

4445
export const EDITOR_MODE_EDIT = 'edit'
4546
export const EDITOR_MODE_CREATE = 'create'
@@ -155,6 +156,10 @@ export const useFileActions = () => {
155156
return false
156157
}
157158

159+
if (isLocationActive(router, { name: fileExtension.routeName })) {
160+
return false
161+
}
162+
158163
if (resources[0].extension && fileExtension.extension) {
159164
return resources[0].extension.toLowerCase() === fileExtension.extension.toLowerCase()
160165
}

packages/web-pkg/tests/unit/composables/actions/files/useFileActions.spec.ts

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { mock } from 'vitest-mock-extended'
2-
import { useFileActions } from '../../../../../src/composables/actions'
2+
import { Action, FileActionOptions, useFileActions } from '../../../../../src/composables/actions'
33
import {
44
defaultComponentMocks,
55
RouteLocation,
66
getComposableWrapper
77
} from '@ownclouders/web-test-helpers'
88
import { computed, unref } from 'vue'
99
import { describe } from 'vitest'
10-
import { Resource } from '@ownclouders/web-client'
10+
import { Resource, SpaceResource } from '@ownclouders/web-client'
1111

1212
const mockUseEmbedMode = vi.fn().mockReturnValue({ isEnabled: computed(() => false) })
1313
vi.mock('../../../../../src/composables/embedMode', () => ({
@@ -33,6 +33,29 @@ describe('fileActions', () => {
3333
}
3434
})
3535
})
36+
37+
it('should hide action when editor with matching routeName is opened', () => {
38+
getWrapper({
39+
currentRoute: mock<RouteLocation>({ name: 'text-editor' }),
40+
setup: ({ editorActions }) => {
41+
const [textEditor] = unref(editorActions)
42+
43+
expect(
44+
(textEditor as Action<FileActionOptions>).isVisible({
45+
space: mock<SpaceResource>(),
46+
resources: [
47+
mock<Resource>({
48+
id: '2',
49+
extension: 'txt',
50+
mimeType: 'text/txt',
51+
canDownload: () => true
52+
})
53+
]
54+
})
55+
).toStrictEqual(false)
56+
}
57+
})
58+
})
3659
})
3760
describe('secure view context', () => {
3861
describe('computed property "editorActions"', () => {
@@ -60,10 +83,16 @@ describe('fileActions', () => {
6083
})
6184
})
6285

63-
function getWrapper({ setup }: { setup: (instance: ReturnType<typeof useFileActions>) => void }) {
86+
function getWrapper({
87+
setup,
88+
currentRoute = mock<RouteLocation>({ name: 'files-spaces-generic' })
89+
}: {
90+
setup: (instance: ReturnType<typeof useFileActions>) => void
91+
currentRoute?: RouteLocation
92+
}) {
6493
const mocks = {
6594
...defaultComponentMocks({
66-
currentRoute: mock<RouteLocation>({ name: 'files-spaces-generic' })
95+
currentRoute
6796
})
6897
}
6998
return {
@@ -103,7 +132,8 @@ function getWrapper({ setup }: { setup: (instance: ReturnType<typeof useFileActi
103132
{
104133
app: 'text-editor',
105134
extension: 'txt',
106-
hasPriority: false
135+
hasPriority: false,
136+
routeName: 'text-editor'
107137
},
108138
{
109139
app: 'external',

0 commit comments

Comments
 (0)