Skip to content
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
6 changes: 6 additions & 0 deletions changelog/unreleased/enhancement-hide-active-editor-action.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Hide active editor action

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.

https://github.com/owncloud/web/pull/12110
https://github.com/owncloud/web/issues/12108
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { Resource, SpaceResource } from '@ownclouders/web-client'
import { storeToRefs } from 'pinia'
import { useEmbedMode } from '../../embedMode'
import { RouteRecordName } from 'vue-router'
import { isLocationActive } from '../../../router/utils'

export const EDITOR_MODE_EDIT = 'edit'
export const EDITOR_MODE_CREATE = 'create'
Expand Down Expand Up @@ -159,6 +160,10 @@ export const useFileActions = () => {
return false
}

if (isLocationActive(router, { name: fileExtension.routeName || fileExtension.app })) {
return false
}

if (resources[0].extension && fileExtension.extension) {
return resources[0].extension.toLowerCase() === fileExtension.extension.toLowerCase()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { mock } from 'vitest-mock-extended'
import { useFileActions } from '../../../../../src/composables/actions'
import { Action, FileActionOptions, useFileActions } from '../../../../../src/composables/actions'
import {
defaultComponentMocks,
RouteLocation,
getComposableWrapper
} from '@ownclouders/web-test-helpers'
import { computed, unref } from 'vue'
import { describe } from 'vitest'
import { Resource } from '@ownclouders/web-client'
import { Resource, SpaceResource } from '@ownclouders/web-client'

const mockUseEmbedMode = vi.fn().mockReturnValue({ isEnabled: computed(() => false) })
vi.mock('../../../../../src/composables/embedMode', () => ({
Expand All @@ -33,6 +33,29 @@ describe('fileActions', () => {
}
})
})

it('should hide action when editor with matching routeName is opened', () => {
getWrapper({
currentRoute: mock<RouteLocation>({ name: 'text-editor' }),
setup: ({ editorActions }) => {
const [textEditor] = unref(editorActions)

expect(
(textEditor as Action<FileActionOptions>).isVisible({
space: mock<SpaceResource>(),
resources: [
mock<Resource>({
id: '2',
extension: 'txt',
mimeType: 'text/txt',
canDownload: () => true
})
]
})
).toStrictEqual(false)
}
})
})
})
describe('secure view context', () => {
describe('computed property "editorActions"', () => {
Expand Down Expand Up @@ -60,10 +83,16 @@ describe('fileActions', () => {
})
})

function getWrapper({ setup }: { setup: (instance: ReturnType<typeof useFileActions>) => void }) {
function getWrapper({
setup,
currentRoute = mock<RouteLocation>({ name: 'files-spaces-generic' })
}: {
setup: (instance: ReturnType<typeof useFileActions>) => void
currentRoute?: RouteLocation
}) {
const mocks = {
...defaultComponentMocks({
currentRoute: mock<RouteLocation>({ name: 'files-spaces-generic' })
currentRoute
})
}
return {
Expand Down Expand Up @@ -112,7 +141,8 @@ function getWrapper({ setup }: { setup: (instance: ReturnType<typeof useFileActi
{
app: 'text-editor',
extension: 'txt',
hasPriority: false
hasPriority: false,
routeName: 'text-editor'
},
{
app: 'external',
Expand Down