@@ -145,23 +145,27 @@ export class ExampleMetadataProvider extends Reactodia.BaseMetadataProvider {
145145 await Reactodia . delay ( SIMULATED_DELAY , { signal} ) ;
146146 const properties = new Map < Reactodia . PropertyTypeIri , Reactodia . MetadataPropertyShape > ( ) ;
147147 if ( types . some ( type => this . editableTypes . has ( type ) ) ) {
148- properties . set ( rdfs . comment , {
148+ properties . set ( Reactodia . rdfs . label , {
149149 valueShape : { termType : 'Literal' } ,
150+ order : 1 ,
150151 } ) ;
151- properties . set ( Reactodia . rdfs . label , {
152+ properties . set ( rdfs . comment , {
152153 valueShape : { termType : 'Literal' } ,
154+ order : 2 ,
153155 } ) ;
154156 properties . set ( Reactodia . schema . thumbnailUrl , {
155157 valueShape : { termType : 'NamedNode' } ,
156158 maxCount : 1 ,
159+ order : 3 ,
157160 } ) ;
158161 properties . set ( rdfs . seeAlso , {
159162 valueShape : { termType : 'NamedNode' } ,
163+ order : 4 ,
160164 } ) ;
161165 }
162166 return { properties} ;
163167 } ,
164- getRelationShape : async ( linkType , { signal} ) => {
168+ getRelationShape : async ( linkType , source , target , { signal} ) => {
165169 await Reactodia . delay ( SIMULATED_DELAY , { signal} ) ;
166170 const properties = new Map < Reactodia . PropertyTypeIri , Reactodia . MetadataPropertyShape > ( ) ;
167171 if ( this . editableRelations . has ( linkType ) ) {
@@ -183,11 +187,16 @@ export class ExampleValidationProvider implements Reactodia.ValidationProvider {
183187 async validate (
184188 event : Reactodia . ValidationEvent
185189 ) : Promise < Reactodia . ValidationResult > {
190+ const { target, outboundLinks, graph, state, translation, language, signal} = event ;
186191 const items : Array < Reactodia . ValidatedElement | Reactodia . ValidatedLink > = [ ] ;
187192
188- if ( event . target . types . includes ( owl . Class ) ) {
189- event . state . links . forEach ( e => {
190- if ( e . type === 'relationAdd' && e . data . sourceId === event . target . id ) {
193+ if ( target . types . includes ( owl . Class ) ) {
194+ for ( const e of state . links . values ( ) ) {
195+ if ( e . type === 'relationAdd' && e . data . sourceId === target . id ) {
196+ const linkType = graph . getLinkType ( e . data . linkTypeId ) ;
197+ const linkLabel = translation . formatLabel (
198+ linkType ?. data ?. label , e . data . linkTypeId , language
199+ ) ;
191200 items . push ( {
192201 type : 'link' ,
193202 target : e . data ,
@@ -196,41 +205,42 @@ export class ExampleValidationProvider implements Reactodia.ValidationProvider {
196205 } ) ;
197206 items . push ( {
198207 type : 'element' ,
199- target : event . target . id ,
208+ target : target . id ,
200209 severity : 'warning' ,
201- message : `Cannot create < ${ e . data . linkTypeId } > link from a Class` ,
210+ message : `Cannot create " ${ linkLabel } " relation from a Class` ,
202211 } ) ;
203212 }
204- } ) ;
213+ }
205214 }
206215
207216 if (
208- event . state . elements . has ( event . target . id ) &&
209- event . target . types . includes ( owl . ObjectProperty )
217+ state . elements . has ( target . id ) &&
218+ target . types . includes ( owl . ObjectProperty )
210219 ) {
211- if ( ! event . outboundLinks . some ( link => link . linkTypeId === rdfs . subPropertyOf ) ) {
220+ if ( ! outboundLinks . some ( link => link . linkTypeId === rdfs . subPropertyOf ) ) {
212221 items . push ( {
213222 type : 'element' ,
214- target : event . target . id ,
223+ target : target . id ,
215224 severity : 'info' ,
216225 message : 'It might be a good idea to make the property a sub-property of another' ,
217226 } ) ;
218227 }
219228 }
220229
221- for ( const link of event . outboundLinks ) {
230+ for ( const link of outboundLinks ) {
222231 const { [ rdfs . comment ] : comments } = link . properties ;
223232 if ( comments && ! comments . every ( comment => comment . termType === 'Literal' && comment . language ) ) {
224233 items . push ( {
225234 type : 'link' ,
226235 target : link ,
227236 severity : 'error' ,
228- message : 'rdfs:comment value should have a language' ,
237+ message : 'value should have a language' ,
238+ propertyType : rdfs . comment ,
229239 } ) ;
230240 }
231241 }
232242
233- await Reactodia . delay ( SIMULATED_DELAY , { signal : event . signal } ) ;
243+ await Reactodia . delay ( SIMULATED_DELAY , { signal} ) ;
234244 return { items} ;
235245 }
236246}
0 commit comments