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
20 changes: 10 additions & 10 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
@@ -1,6 +1,6 @@
{
"name": "solid-ui",
"version": "5.0.2-3",
"version": "5.0.2-4",
"description": "UI library for Solid applications",
"main": "dist/index.cjs.js",
"types": "dist/index.d.ts",
Expand Down
23 changes: 23 additions & 0 deletions src/lib/file-explorer/relevant-panes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { DataBrowserContext, PaneDefinition } from 'pane-registry'
import type { NamedNode } from 'rdflib'
import { filterAvailablePanes } from '@/login/login'
import ns from '@/lib/ns'

export type RelevantPaneOptions = {
excludedPaneNames?: readonly string[]
Expand Down Expand Up @@ -43,3 +44,25 @@ export async function getRelevantPanes (
? [relevantPanes[0]].concat(filteredPanes)
: filteredPanes
}

/**
* Chooses the default pane from the relevant panes for a resource.
*
* A resource's `ui:mintClass` is an explicit declaration of the pane that
* created it, so it takes precedence over panes that merely request focus.
*/
export function getPreferredPane (
Comment thread
SharonStrats marked this conversation as resolved.
subject: NamedNode,
context: DataBrowserContext,
relevantPanes: PaneDefinition[]
): PaneDefinition | undefined {
const store = context.session.store
const mintClass = store.any(subject, ns.ui('mintClass'), undefined, subject.doc()) ||
store.any(subject.doc(), ns.ui('mintClass'), undefined, subject.doc())
if (mintClass) {
const mintClassPane = relevantPanes.find(pane => pane.mintClass?.sameTerm(mintClass))
if (mintClassPane) return mintClassPane
}

return relevantPanes.find(pane => pane.shouldGetFocus?.(subject)) || relevantPanes[0]
}
52 changes: 51 additions & 1 deletion test/unit/file-explorer/relevant-panes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { DataBrowserContext, PaneDefinition } from 'pane-registry'
import { sym } from 'rdflib'
import { solidLogicSingleton } from 'solid-logic'
import { filterAvailablePanes } from '../../../src/login/login'
import { getRelevantPanes } from '../../../src/lib/file-explorer/relevant-panes'
import ns from '../../../src/lib/ns'
import { getPreferredPane, getRelevantPanes } from '../../../src/lib/file-explorer/relevant-panes'

vi.mock('../../../src/login/login', () => ({
filterAvailablePanes: vi.fn()
Expand Down Expand Up @@ -128,3 +129,52 @@ describe('getRelevantPanes', () => {
await expect(getRelevantPanes(subject, createContext([createPane('first')]))).rejects.toBe(error)
})
})

describe('getPreferredPane', () => {
function contextWithMintClass (mintClass?: string): DataBrowserContext {
const store = Object.create(solidLogicSingleton.store)
store.any = vi.fn((candidate, predicate) => {
if (mintClass && candidate.sameTerm(subject) && predicate.sameTerm(ns.ui('mintClass'))) {
return sym(mintClass)
}
return undefined
})
return {
dom: document,
getOutliner: () => undefined,
session: {
logic: solidLogicSingleton,
store,
paneRegistry: {
list: [],
paneForIcon: {},
paneForPredicate: {},
register: vi.fn(),
byName: () => null
}
}
}
}

it('prefers the pane matching a resource mint class over a focus request', () => {
const mintClass = sym('https://schema.example/PhotoAlbum')
const focus = createPane('focus', { shouldGetFocus: () => true })
const minted = createPane('album', { mintClass })

expect(getPreferredPane(subject, contextWithMintClass(mintClass.uri), [focus, minted])).toBe(minted)
})

it('uses a focus request when no relevant pane matches the mint class', () => {
const focus = createPane('focus', { shouldGetFocus: () => true })
const other = createPane('other', { mintClass: sym('https://schema.example/Other') })

expect(getPreferredPane(subject, contextWithMintClass('https://schema.example/PhotoAlbum'), [other, focus])).toBe(focus)
})

it('falls back to registry order when no pane requests focus', () => {
const first = createPane('first')
const second = createPane('second')

expect(getPreferredPane(subject, contextWithMintClass(), [first, second])).toBe(first)
})
})
1 change: 1 addition & 0 deletions test/unit/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Index', () => {
'dom',
'fileExplorerContext',
'generateId',
'getPreferredPane',
'getRelevantPanes',
'icons',
'infiniteMessageArea',
Expand Down
Loading