diff --git a/changelog/unreleased/enhancement-hide-active-editor-action.md b/changelog/unreleased/enhancement-hide-active-editor-action.md new file mode 100644 index 00000000000..96f49cfb664 --- /dev/null +++ b/changelog/unreleased/enhancement-hide-active-editor-action.md @@ -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 diff --git a/packages/web-pkg/src/composables/actions/files/useFileActions.ts b/packages/web-pkg/src/composables/actions/files/useFileActions.ts index 258427ebf47..c096efa3e72 100644 --- a/packages/web-pkg/src/composables/actions/files/useFileActions.ts +++ b/packages/web-pkg/src/composables/actions/files/useFileActions.ts @@ -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' @@ -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() } diff --git a/packages/web-pkg/tests/unit/composables/actions/files/useFileActions.spec.ts b/packages/web-pkg/tests/unit/composables/actions/files/useFileActions.spec.ts index 40270c1d5a2..7037aafbf10 100644 --- a/packages/web-pkg/tests/unit/composables/actions/files/useFileActions.spec.ts +++ b/packages/web-pkg/tests/unit/composables/actions/files/useFileActions.spec.ts @@ -1,5 +1,5 @@ import { mock } from 'vitest-mock-extended' -import { useFileActions } from '../../../../../src/composables/actions' +import { Action, FileActionOptions, useFileActions } from '../../../../../src/composables/actions' import { defaultComponentMocks, RouteLocation, @@ -7,7 +7,7 @@ import { } 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', () => ({ @@ -33,6 +33,29 @@ describe('fileActions', () => { } }) }) + + it('should hide action when editor with matching routeName is opened', () => { + getWrapper({ + currentRoute: mock({ name: 'text-editor' }), + setup: ({ editorActions }) => { + const [textEditor] = unref(editorActions) + + expect( + (textEditor as Action).isVisible({ + space: mock(), + resources: [ + mock({ + id: '2', + extension: 'txt', + mimeType: 'text/txt', + canDownload: () => true + }) + ] + }) + ).toStrictEqual(false) + } + }) + }) }) describe('secure view context', () => { describe('computed property "editorActions"', () => { @@ -60,10 +83,16 @@ describe('fileActions', () => { }) }) -function getWrapper({ setup }: { setup: (instance: ReturnType) => void }) { +function getWrapper({ + setup, + currentRoute = mock({ name: 'files-spaces-generic' }) +}: { + setup: (instance: ReturnType) => void + currentRoute?: RouteLocation +}) { const mocks = { ...defaultComponentMocks({ - currentRoute: mock({ name: 'files-spaces-generic' }) + currentRoute }) } return { @@ -112,7 +141,8 @@ function getWrapper({ setup }: { setup: (instance: ReturnType