Skip to content

Commit

Permalink
fix(files): title and inline actions
Browse files Browse the repository at this point in the history
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  • Loading branch information
skjnldsv committed Sep 21, 2023
1 parent b6de02d commit 3501bd7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 16 deletions.
14 changes: 8 additions & 6 deletions apps/comments/src/actions/inlineUnreadCommentsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
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 })
}
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
Expand All @@ -57,5 +61,3 @@ export const action = new FileAction({

order: -140,
})

registerFileAction(action)
15 changes: 13 additions & 2 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)">
<template #icon>
<NcLoadingIcon v-if="loading === action.id" :size="18" />
<CustomSvgIconRender v-else :svg="action.iconSvgInline([source], currentView)" />
</template>
{{ action.displayName([source], currentView) }}
{{ actionDisplayName(action) }}
</NcActionButton>
</NcActions>
</td>
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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,
},
Expand Down
15 changes: 13 additions & 2 deletions apps/files_sharing/src/actions/sharingStatusAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"@nextcloud/capabilities": "^1.0.4",
"@nextcloud/dialogs": "^5.0.0-beta.2",
"@nextcloud/event-bus": "^3.1.0",
"@nextcloud/files": "^3.0.0-beta.21",
"@nextcloud/files": "^3.0.0-beta.22",
"@nextcloud/initial-state": "^2.0.0",
"@nextcloud/l10n": "^2.1.0",
"@nextcloud/logger": "^2.5.0",
Expand Down

0 comments on commit 3501bd7

Please sign in to comment.