Skip to content

Commit 6deac39

Browse files
authored
Merge pull request #862 from EBISPOT/add-classes-to-individual-table
Add classes to individual table
2 parents e8b8175 + 4d87e79 commit 6deac39

File tree

3 files changed

+66
-15
lines changed

3 files changed

+66
-15
lines changed

frontend/src/pages/ontologies/entities/EntityList.tsx

Lines changed: 64 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useAppDispatch, useAppSelector } from "../../../app/hooks";
44
import DataTable, { Column } from "../../../components/DataTable";
55
import Entity from "../../../model/Entity";
66
import { getEntities } from "../ontologiesSlice";
7+
import Individual from "../../../model/Individual";
78

89
export default function EntityList({
910
ontologyId,
@@ -34,6 +35,69 @@ export default function EntityList({
3435
}, [entityType]);
3536

3637
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+
37101
return (
38102
<div className="mt-2">
39103
<DataTable
@@ -70,16 +134,3 @@ export default function EntityList({
70134
</div>
71135
);
72136
}
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-
];

frontend/src/pages/ontologies/entities/entityPageSections/EntityAnnotationsSection.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default function EntityAnnotationsSection({
9191
/>
9292
);
9393
} else {
94-
if (typeof value.value !== "string" && typeof value.value !== "boolean") {
94+
if (typeof value.value !== "string" && typeof value.value !== "boolean" && typeof value.value !== "number") {
9595
return (
9696
<ClassExpression
9797
ontologyId={entity.getOntologyId()}

frontend/src/pages/ontologies/ontologiesSlice.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ export const getEntities = createAsyncThunk(
277277
{ rejectWithValue }
278278
) => {
279279
const path = `api/v2/ontologies/${ontologyId}/${entityType}?page=${page}&size=${rowsPerPage}${
280-
search ? "&search=" + search : ""
280+
search ? "&search=" + encodeURIComponent(`*${search}*`) : ""
281281
}`;
282282
try {
283283
const data = (await getPaginated<any>(path)).map((e) =>

0 commit comments

Comments
 (0)