Skip to content

Commit

Permalink
fix: honor when changing selected shape
Browse files Browse the repository at this point in the history
  • Loading branch information
tpluscode committed Nov 30, 2021
1 parent cbc7504 commit 145dbfb
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/nine-geckos-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hydrofoil/roadshow": patch
---

Switching shape should inspect `dash:viewer` and select its renderer
18 changes: 16 additions & 2 deletions packages/roadshow/lib/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { html, TemplateResult } from 'lit'
import { findNodes } from 'clownface-shacl-path'
import { BlankNode, Literal, NamedNode, Term } from '@rdfjs/types'
import { roadshow } from '@hydrofoil/vocabularies/builders'
import { rdfs, sh } from '@tpluscode/rdf-ns-builders/strict'
import { dash, rdfs, sh } from '@tpluscode/rdf-ns-builders/strict'
import { dataset } from '@rdf-esm/dataset'
import { NodeShape } from '@rdfine/shacl'
import { ResourceIdentifier } from '@tpluscode/rdfine'
Expand Down Expand Up @@ -112,7 +112,21 @@ function setShape(this: FocusNodeViewContext, shape: NodeShape | ResourceIdentif
const found = this.state.applicableShapes.find(ns => ns.equals(shape))
if (found) {
this.state.shape = found
const { applicableViewers, viewer } = findViewers(this.state, this.node, this.controller)
delete this.state.viewer
let { applicableViewers, viewer } = findViewers(this.state, this.node, this.controller)
const dashViewer: NamedNode = found.pointer.out(dash.viewer).term as any
if (dashViewer) {
const hasRenderer = this.controller.renderers.has(dashViewer)
if (hasRenderer) {
viewer = dashViewer
applicableViewers.unshift({
pointer: this.controller.viewers.get(dashViewer),
score: null,
})
delete this.state.renderer
}
}

this.state.applicableViewers = applicableViewers
this.state.viewer = viewer
this.state.properties = found.property.reduce(createPropertyState, [])
Expand Down
2 changes: 1 addition & 1 deletion packages/roadshow/lib/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface FocusNodeState<R = unknown> extends ShapedNodeState<R>, Rendere
pointer?: GraphPointer<BlankNode | NamedNode>
properties: PropertyState[]
applicableViewers: ViewerScore[]
viewer: Term
viewer?: Term
}

export type AnyState = ObjectState | FocusNodeState | PropertyState
Expand Down

0 comments on commit 145dbfb

Please sign in to comment.