@@ -4,6 +4,7 @@ import { useAppDispatch, useAppSelector } from "../../../app/hooks";
4
4
import DataTable , { Column } from "../../../components/DataTable" ;
5
5
import Entity from "../../../model/Entity" ;
6
6
import { getEntities } from "../ontologiesSlice" ;
7
+ import Individual from "../../../model/Individual" ;
7
8
8
9
export default function EntityList ( {
9
10
ontologyId,
@@ -34,6 +35,69 @@ export default function EntityList({
34
35
} , [ entityType ] ) ;
35
36
36
37
const navigate = useNavigate ( ) ;
38
+
39
+ // base columns are shown for all entity types.
40
+ const baseColumns : readonly Column [ ] = [
41
+ {
42
+ name : "Name" ,
43
+ sortable : true ,
44
+ selector : ( entity : Entity ) => entity . getName ( ) ,
45
+ } ,
46
+ {
47
+ name : "ID" ,
48
+ sortable : true ,
49
+ selector : ( entity : Entity ) => entity . getShortForm ( ) ,
50
+ } ,
51
+ ] ;
52
+
53
+ // If the entity type is "individuals", add a "associated class" column.
54
+ const individualTypeColumn : Column = {
55
+ name : "Associated Class" ,
56
+ sortable : true ,
57
+ selector : ( entity : Entity ) => {
58
+ if ( entity instanceof Individual ) {
59
+ const types = entity . getIndividualTypes ( ) ;
60
+ const linkedEntities = entity . getLinkedEntities ( ) ;
61
+ if ( types && types . length > 0 ) {
62
+ return types
63
+ . map ( ( val : any ) => {
64
+ if ( ! ( typeof val === "object" && ! Array . isArray ( val ) ) ) {
65
+ return (
66
+ linkedEntities . getLabelForIri ( val ) ||
67
+ val . split ( "/" ) . pop ( ) ||
68
+ val
69
+ ) ;
70
+ }
71
+ if ( typeof val === "object" && ! Array . isArray ( val ) ) {
72
+ // If the object has the "someValuesFrom" property, use the custom format.
73
+ if ( val [ "http://www.w3.org/2002/07/owl#someValuesFrom" ] ) {
74
+ const someValuesFromIri = val [ "http://www.w3.org/2002/07/owl#someValuesFrom" ] ;
75
+ const onPropertyIri = val [ "http://www.w3.org/2002/07/owl#onProperty" ] ;
76
+ const someValuesLabel =
77
+ linkedEntities . getLabelForIri ( someValuesFromIri ) ||
78
+ ( typeof someValuesFromIri === "string" && someValuesFromIri . split ( "/" ) . pop ( ) ) ||
79
+ someValuesFromIri ;
80
+ const propertyLabel =
81
+ linkedEntities . getLabelForIri ( onPropertyIri ) ||
82
+ ( typeof onPropertyIri === "string" && onPropertyIri . split ( "/" ) . pop ( ) ) ||
83
+ onPropertyIri ;
84
+ return `${ propertyLabel } some ${ someValuesLabel } ` ;
85
+ }
86
+ }
87
+ } )
88
+ . join ( ", " ) ;
89
+ }
90
+ }
91
+ return "" ;
92
+ } ,
93
+ } ;
94
+
95
+ // Merge columns based on the entity type.
96
+ const columns =
97
+ entityType === "individuals"
98
+ ? [ ...baseColumns , individualTypeColumn ]
99
+ : baseColumns ;
100
+
37
101
return (
38
102
< div className = "mt-2" >
39
103
< DataTable
@@ -70,16 +134,3 @@ export default function EntityList({
70
134
</ div >
71
135
) ;
72
136
}
73
-
74
- const columns : readonly Column [ ] = [
75
- {
76
- name : "Name" ,
77
- sortable : true ,
78
- selector : ( entity : Entity ) => entity . getName ( ) ,
79
- } ,
80
- {
81
- name : "ID" ,
82
- sortable : true ,
83
- selector : ( entity : Entity ) => entity . getShortForm ( ) ,
84
- } ,
85
- ] ;
0 commit comments