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
11 changes: 1 addition & 10 deletions apps/systemtags/src/actions/inlineSystemTagsAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,7 @@ import { FileAction, Node, registerDavProperty, registerFileAction } from '@next
import { translate as t } from '@nextcloud/l10n'

import '../css/fileEntryInlineSystemTags.scss'

const getNodeSystemTags = function(node: Node): string[] {
const tags = node.attributes?.['system-tags']?.['system-tag'] as string|string[]|undefined

if (tags === undefined) {
return []
}

return [tags].flat()
}
import { getNodeSystemTags } from '../utils'

const renderTag = function(tag: string, isMore = false): HTMLElement {
const tagElement = document.createElement('li')
Expand Down
91 changes: 90 additions & 1 deletion apps/systemtags/src/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import type { DAVResultResponseProps } from 'webdav'
import type { ServerTag, Tag } from './types.js'

import { describe, it, expect } from '@jest/globals'
import { formatTag, parseIdFromLocation, parseTags } from './utils'
import { formatTag, getNodeSystemTags, parseIdFromLocation, parseTags } from './utils'
import { Folder } from '@nextcloud/files'

describe('systemtags - utils', () => {
describe('parseTags', () => {
Expand Down Expand Up @@ -102,4 +103,92 @@ describe('systemtags - utils', () => {
})
})
})

describe('getNodeSystemTags', () => {
it('parses a plain tag', () => {
const node = new Folder({
owner: 'test',
source: 'https://example.com/remote.php/dav/files/test/folder',
attributes: {
'system-tags': {
'system-tag': 'tag',
},
},
})
expect(getNodeSystemTags(node)).toStrictEqual(['tag'])
})

it('parses plain tags', () => {
const node = new Folder({
owner: 'test',
source: 'https://example.com/remote.php/dav/files/test/folder',
attributes: {
'system-tags': {
'system-tag': [
'tag',
'my-tag',
],
},
},
})
expect(getNodeSystemTags(node)).toStrictEqual(['tag', 'my-tag'])
})

it('parses tag with attributes', () => {
const node = new Folder({
owner: 'test',
source: 'https://example.com/remote.php/dav/files/test/folder',
attributes: {
'system-tags': {
'system-tag': {
text: 'tag',
'@can-assign': true,
},
},
},
})
expect(getNodeSystemTags(node)).toStrictEqual(['tag'])
})

it('parses tags with attributes', () => {
const node = new Folder({
owner: 'test',
source: 'https://example.com/remote.php/dav/files/test/folder',
attributes: {
'system-tags': {
'system-tag': [
{
text: 'tag',
'@can-assign': true,
},
{
text: 'my-tag',
'@can-assign': false,
},
],
},
},
})
expect(getNodeSystemTags(node)).toStrictEqual(['tag', 'my-tag'])
})

it('parses tags mixed with and without attributes', () => {
const node = new Folder({
owner: 'test',
source: 'https://example.com/remote.php/dav/files/test/folder',
attributes: {
'system-tags': {
'system-tag': [
'tag',
{
text: 'my-tag',
'@can-assign': false,
},
],
},
},
})
expect(getNodeSystemTags(node)).toStrictEqual(['tag', 'my-tag'])
})
})
})
20 changes: 20 additions & 0 deletions apps/systemtags/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import camelCase from 'camelcase'

import type { DAVResultResponseProps } from 'webdav'

import type { Node } from '@nextcloud/files'
import type { BaseTag, ServerTag, Tag, TagWithId } from './types.js'

export const defaultBaseTag: BaseTag = {
Expand Down Expand Up @@ -71,3 +72,22 @@ export const formatTag = (initialTag: Tag | ServerTag): ServerTag => {

return tag
}

export const getNodeSystemTags = function(node: Node): string[] {
const attribute = node.attributes?.['system-tags']?.['system-tag']
if (attribute === undefined) {
return []
}

// if there is only one tag it is a single string or prop object
// if there are multiple then its an array - so we flatten it to be always an array of string or prop objects
return [attribute]
.flat()
.map((tag: string|{ text: string }) => (
typeof tag === 'string'
// its a plain text prop (the tag name) without prop attributes
? tag
// its a prop object with attributes, the tag name is in the 'text' attribute
: tag.text
))
}
4 changes: 2 additions & 2 deletions dist/core-common.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/core-common.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/files-sidebar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-sidebar.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/systemtags-admin.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/systemtags-admin.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/systemtags-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/systemtags-init.js.map

Large diffs are not rendered by default.

Loading