Signed-off-by: Lucas Azevedo <lhs_azevedo@hotmail.com>
pull/40284/head
Lucas Azevedo 2 years ago committed by John Molakvoæ
parent a2d7a70219
commit f5865216d6
  1. 44
      apps/systemtags/src/actions/inlineSystemTagsAction.spec.ts
  2. 24
      apps/systemtags/src/actions/inlineSystemTagsAction.ts
  3. 2
      apps/systemtags/src/systemtags.js

@ -71,17 +71,17 @@ describe('Inline system tags action render tests', () => {
permissions: Permission.ALL,
attributes: {
'system-tags': {
'system-tag': 'Confidential'
}
}
'system-tag': 'Confidential',
},
},
})
const result = await action.renderInline!(file, view)
expect(result).toBeInstanceOf(HTMLElement)
expect(result!.outerHTML).toBe(
'<ul class="files-list__system-tags" aria-label="This file has the tag Confidential">' +
'<li class="files-list__system-tag">Confidential</li>' +
'</ul>'
'<ul class="files-list__system-tags" aria-label="This file has the tag Confidential">'
+ '<li class="files-list__system-tag">Confidential</li>'
+ '</ul>',
)
})
@ -96,19 +96,19 @@ describe('Inline system tags action render tests', () => {
'system-tags': {
'system-tag': [
'Important',
'Confidential'
]
}
}
'Confidential',
],
},
},
})
const result = await action.renderInline!(file, view)
expect(result).toBeInstanceOf(HTMLElement)
expect(result!.outerHTML).toBe(
'<ul class="files-list__system-tags" aria-label="This file has the tags Important and Confidential">' +
'<li class="files-list__system-tag">Important</li>' +
'<li class="files-list__system-tag files-list__system-tag--more" title="Confidential">+1</li>' +
'</ul>'
'<ul class="files-list__system-tags" aria-label="This file has the tags Important and Confidential">'
+ '<li class="files-list__system-tag">Important</li>'
+ '<li class="files-list__system-tag files-list__system-tag--more" title="Confidential">+1</li>'
+ '</ul>',
)
})
@ -125,19 +125,19 @@ describe('Inline system tags action render tests', () => {
'Important',
'Confidential',
'Secret',
'Classified'
]
}
}
'Classified',
],
},
},
})
const result = await action.renderInline!(file, view)
expect(result).toBeInstanceOf(HTMLElement)
expect(result!.outerHTML).toBe(
'<ul class="files-list__system-tags" aria-label="This file has the tags Important, Confidential, Secret and Classified">' +
'<li class="files-list__system-tag">Important</li>' +
'<li class="files-list__system-tag files-list__system-tag--more" title="Confidential, Secret, Classified">+3</li>' +
'</ul>'
'<ul class="files-list__system-tags" aria-label="This file has the tags Important, Confidential, Secret and Classified">'
+ '<li class="files-list__system-tag">Important</li>'
+ '<li class="files-list__system-tag files-list__system-tag--more" title="Confidential, Secret, Classified">+3</li>'
+ '</ul>',
)
})
})

@ -19,12 +19,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { FileAction, Node, registerDavProperty, registerFileAction } from "@nextcloud/files";
import { FileAction, Node, registerDavProperty, registerFileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import '../css/fileEntryInlineSystemTags.scss'
const getNodeSystemTags = function (node: Node): string[] {
const getNodeSystemTags = function(node: Node): string[] {
const tags = node.attributes?.['system-tags']?.['system-tag'] as string|string[]|undefined
if (tags === undefined) {
@ -34,7 +34,7 @@ const getNodeSystemTags = function (node: Node): string[] {
return [tags].flat()
}
const renderTag = function (tag: string, isMore: boolean = false): HTMLElement {
const renderTag = function(tag: string, isMore = false): HTMLElement {
const tagElement = document.createElement('li')
tagElement.classList.add('files-list__system-tag')
tagElement.textContent = tag
@ -43,7 +43,7 @@ const renderTag = function (tag: string, isMore: boolean = false): HTMLElement {
tagElement.classList.add('files-list__system-tag--more')
}
return tagElement;
return tagElement
}
export const action = new FileAction({
@ -64,26 +64,26 @@ export const action = new FileAction({
systemTagsElement.classList.add('files-list__system-tags')
if (tags.length === 1) {
systemTagsElement.setAttribute('aria-label', t('files', 'This file has the tag {tag}', { tag: tags[0] }));
systemTagsElement.setAttribute('aria-label', t('files', 'This file has the tag {tag}', { tag: tags[0] }))
} else {
var firstTags = tags.slice(0, -1).join(', ');
var lastTag = tags[tags.length - 1];
systemTagsElement.setAttribute('aria-label', t('files', 'This file has the tags {firstTags} and {lastTag}', { firstTags, lastTag }));
const firstTags = tags.slice(0, -1).join(', ')
const lastTag = tags[tags.length - 1]
systemTagsElement.setAttribute('aria-label', t('files', 'This file has the tags {firstTags} and {lastTag}', { firstTags, lastTag }))
}
systemTagsElement.append(renderTag(tags[0]))
// More tags than the one we're showing
if (tags.length > 1) {
const moreTagElement = renderTag('+' + (tags.length - 1), true)
moreTagElement.setAttribute('title', tags.slice(1).join(', '));
systemTagsElement.append(moreTagElement);
moreTagElement.setAttribute('title', tags.slice(1).join(', '))
systemTagsElement.append(moreTagElement)
}
return systemTagsElement
},
order: 0
order: 0,
})
registerDavProperty('nc:system-tags')

@ -24,6 +24,6 @@
import './app.js'
import './systemtagsfilelist.js'
import './css/systemtagsfilelist.scss'
import './actions/inlineSystemTagsAction'
import './actions/inlineSystemTagsAction.ts'
window.OCA.SystemTags = OCA.SystemTags

Loading…
Cancel
Save