Skip to content

feat: resource indicator extensions #12159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import { Item } from '@ownclouders/web-client'
import { FolderView } from '../../../ui'
import { Component, Slot } from 'vue'
import { StringUnionOrAnyString } from '../../../utils'
import { ResourceIndicator } from '../../../helpers'

export type ExtensionType = StringUnionOrAnyString<
| 'action'
| 'appMenuItem'
| 'customComponent'
| 'folderView'
| 'resourceIndicator'
| 'search'
| 'sidebarNav'
| 'sidebarPanel'
Expand Down Expand Up @@ -67,6 +69,11 @@ export interface AppMenuItemExtension extends Extension {
url?: string
}

export interface ResourceIndicatorExtension extends Extension {
type: 'resourceIndicator'
getResourceIndicators: (Resource) => ResourceIndicator[] | void
}

export type ExtensionPoint<T extends Extension> = {
id: string
extensionType: ExtensionType
Expand Down
14 changes: 14 additions & 0 deletions packages/web-pkg/src/extensionPoints.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Extension, ExtensionPoint, ResourceIndicatorExtension } from './'
import { computed } from 'vue'

export const resourceIndicatorExtensionPoint: ExtensionPoint<ResourceIndicatorExtension> = {
id: 'global.files.resource-indicator',
extensionType: 'resourceIndicator',
multiple: true
}

export const extensionPoints = () => {
return computed<ExtensionPoint<Extension>[]>(() => {
return [resourceIndicatorExtensionPoint]
})
}
11 changes: 11 additions & 0 deletions packages/web-pkg/src/helpers/statusIndicators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ShareTypes } from '@ownclouders/web-client'
import { eventBus } from '../services'
import { SideBarEventTopics } from '../composables/sideBar'
import { useExtensionRegistry } from '../composables/piniaStores/extensionRegistry'
import { Resource } from '@ownclouders/web-client'
import { AncestorMetaData } from '../types'
import {
Expand All @@ -10,6 +11,7 @@ import {
} from '@ownclouders/web-client'
import { User } from '@ownclouders/web-client/graph/generated'
import { IconFillType } from './resource'
import { resourceIndicatorExtensionPoint } from '../extensionPoints'

// dummy to trick gettext string extraction into recognizing strings
const $gettext = (str: string): string => {
Expand Down Expand Up @@ -157,5 +159,14 @@ export const getIndicators = ({
}
}

;(useExtensionRegistry().requestExtensions(resourceIndicatorExtensionPoint) || []).forEach(
(extension) => {
const extensionIndicators = extension.getResourceIndicators(resource)
if (extensionIndicators) {
indicators.push(...extensionIndicators)
}
}
)

return indicators
}
1 change: 1 addition & 0 deletions packages/web-pkg/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './components'
export * from './composables'
export * from './constants'
export * from './errors'
export * from './extensionPoints'
export * from './helpers'
export * from './http'
export * from './observer'
Expand Down
42 changes: 42 additions & 0 deletions packages/web-pkg/tests/unit/helpers/statusIndicator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,52 @@ import { Resource, SpaceResource } from '@ownclouders/web-client'
import { getIndicators } from '../../../src/helpers/statusIndicators'
import { User } from '@ownclouders/web-client/graph/generated'
import { AncestorMetaDataValue } from '../../../src/types'
import { ResourceIndicator } from '../../../src/helpers'
import { createTestingPinia } from '@ownclouders/web-test-helpers'
import {
ResourceIndicatorExtension,
useExtensionRegistry
} from '../../../src/composables/piniaStores/extensionRegistry'

describe('status indicators', () => {
const user = mock<User>()

createTestingPinia()

describe('indicator extensions', () => {
it('should be requested from the extension registry', () => {
const space = mock<SpaceResource>({ driveType: 'project' })
const resource = mock<Resource>({ id: 'resource' })

const { requestExtensions } = useExtensionRegistry()
vi.mocked(requestExtensions<ResourceIndicatorExtension>).mockReturnValue([
{
id: 'test.files.resource-indicator.stub',
type: 'resourceIndicator',
extensionPointIds: ['global.files.resource-indicator'],
getResourceIndicators: (resource: Resource): ResourceIndicator[] => {
return [
{
id: 'some-id',
accessibleDescription: 'some accessible description',
label: 'some label',
icon: 'check_box_outline_blank',
fillType: 'line',
type: 'some-type',
category: 'system'
}
]
}
} satisfies ResourceIndicatorExtension
])

const indicators = getIndicators({ space, resource, ancestorMetaData: {}, user })

expect(requestExtensions).toHaveBeenCalled()
expect(indicators.some(({ id }) => id === 'some-id')).toBeTruthy()
})
})

describe('locked indicator', () => {
it.each([true, false])('should only be present if the file is locked', (locked) => {
const space = mock<SpaceResource>({ id: 'space' })
Expand Down