From 216804f83d5af391a8a4cc56de89280e3fcdd3bf Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Thu, 21 Sep 2023 12:15:37 +0200 Subject: fix(files): title and inline actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) Signed-off-by: nextcloud-command --- .../src/actions/inlineUnreadCommentsAction.spec.ts | 6 ++++-- apps/comments/src/actions/inlineUnreadCommentsAction.ts | 14 ++++++++------ apps/files/src/components/FileEntry.vue | 15 +++++++++++++-- apps/files_sharing/src/actions/sharingStatusAction.ts | 15 +++++++++++++-- 4 files changed, 38 insertions(+), 12 deletions(-) (limited to 'apps') diff --git a/apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts b/apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts index 9ce192bb477..aabbf42fadb 100644 --- a/apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts +++ b/apps/comments/src/actions/inlineUnreadCommentsAction.spec.ts @@ -44,7 +44,8 @@ describe('Inline unread comments action display name tests', () => { expect(action).toBeInstanceOf(FileAction) expect(action.id).toBe('comments-unread') - expect(action.displayName([file], view)).toBe('1 new comment') + expect(action.displayName([file], view)).toBe('') + expect(action.title!([file], view)).toBe('1 new comment') expect(action.iconSvgInline([], view)).toBe('SvgMock') expect(action.enabled!([file], view)).toBe(true) expect(action.inline!(file, view)).toBe(true) @@ -64,7 +65,8 @@ describe('Inline unread comments action display name tests', () => { }, }) - expect(action.displayName([file], view)).toBe('2 new comments') + expect(action.displayName([file], view)).toBe('') + expect(action.title!([file], view)).toBe('2 new comments') }) }) diff --git a/apps/comments/src/actions/inlineUnreadCommentsAction.ts b/apps/comments/src/actions/inlineUnreadCommentsAction.ts index e29e7d50b28..b537923b30e 100644 --- a/apps/comments/src/actions/inlineUnreadCommentsAction.ts +++ b/apps/comments/src/actions/inlineUnreadCommentsAction.ts @@ -19,15 +19,16 @@ * along with this program. If not, see . * */ -import { FileAction, Node, registerFileAction } from '@nextcloud/files' +import { FileAction, Node } from '@nextcloud/files' import { translate as t, translatePlural as n } from '@nextcloud/l10n' -import commentProcessingSvg from '@mdi/svg/svg/comment-processing.svg?raw' +import CommentProcessingSvg from '@mdi/svg/svg/comment-processing.svg?raw' + import logger from '../logger' export const action = new FileAction({ id: 'comments-unread', - displayName(nodes: Node[]) { + title(nodes: Node[]) { const unread = nodes[0].attributes['comments-unread'] as number if (unread >= 0) { return n('comments', '1 new comment', '{unread} new comments', unread, { unread }) @@ -35,7 +36,10 @@ export const action = new FileAction({ return t('comments', 'Comment') }, - iconSvgInline: () => commentProcessingSvg, + // Empty string when rendered inline + displayName: () => '', + + iconSvgInline: () => CommentProcessingSvg, enabled(nodes: Node[]) { const unread = nodes[0].attributes['comments-unread'] as number|undefined @@ -57,5 +61,3 @@ export const action = new FileAction({ order: -140, }) - -registerFileAction(action) diff --git a/apps/files/src/components/FileEntry.vue b/apps/files/src/components/FileEntry.vue index 83b991dcd50..f9320a55e15 100644 --- a/apps/files/src/components/FileEntry.vue +++ b/apps/files/src/components/FileEntry.vue @@ -130,12 +130,13 @@ :class="'files-list__row-action-' + action.id" :close-after-click="true" :data-cy-files-list-row-action="action.id" + :title="action.title?.([source], currentView)" @click="onActionClick(action)"> - {{ action.displayName([source], currentView) }} + {{ actionDisplayName(action) }} @@ -180,7 +181,7 @@ import { debounce } from 'debounce' import { emit } from '@nextcloud/event-bus' import { extname } from 'path' import { generateUrl } from '@nextcloud/router' -import { getFileActions, DefaultType, FileType, formatFileSize, Permission, Folder, File, Node } from '@nextcloud/files' +import { getFileActions, DefaultType, FileType, formatFileSize, Permission, Folder, File, Node, FileAction } from '@nextcloud/files' import { Type as ShareType } from '@nextcloud/sharing' import { showError, showSuccess } from '@nextcloud/dialogs' import { translate } from '@nextcloud/l10n' @@ -918,6 +919,16 @@ export default Vue.extend({ return document.querySelector('.app-content > .files-list') }, + actionDisplayName(action: FileAction) { + if (this.filesListWidth < 768 && action.inline && typeof action.title === 'function') { + // if an inline action is rendered in the menu for + // lack of space we use the title first if defined + const title = action.title([this.source], this.currentView) + if (title) return title + } + return action.displayName([this.source], this.currentView) + }, + t: translate, formatFileSize, }, diff --git a/apps/files_sharing/src/actions/sharingStatusAction.ts b/apps/files_sharing/src/actions/sharingStatusAction.ts index 054d6617ac9..01052676aa4 100644 --- a/apps/files_sharing/src/actions/sharingStatusAction.ts +++ b/apps/files_sharing/src/actions/sharingStatusAction.ts @@ -47,17 +47,28 @@ export const action = new FileAction({ displayName(nodes: Node[]) { const node = nodes[0] const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[] - if (shareTypes.length > 0) { + const ownerId = node?.attributes?.['owner-id'] + + if (shareTypes.length > 0 + || (ownerId && ownerId !== getCurrentUser()?.uid)) { return t('files_sharing', 'Shared') } + return '' + }, + + title(nodes: Node[]) { + const node = nodes[0] const ownerId = node?.attributes?.['owner-id'] + const ownerDisplayName = node?.attributes?.['owner-display-name'] + if (ownerId && ownerId !== getCurrentUser()?.uid) { - return t('files_sharing', 'Shared') + return t('files_sharing', 'Shared by {ownerDisplayName}', { ownerDisplayName }) } return '' }, + iconSvgInline(nodes: Node[]) { const node = nodes[0] const shareTypes = Object.values(node?.attributes?.['share-types'] || {}).flat() as number[] -- cgit v1.2.3