Skip to content

Commit

Permalink
allow broader selections in the node picker to still select associations
Browse files Browse the repository at this point in the history
  • Loading branch information
Woozl committed Jul 23, 2024
1 parent 89da942 commit 4a25f97
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ const getQualifierOptions = ({ range, subpropertyOf }) => {
export default function QualifiersSelector({ id, associations }) {
const queryBuilder = useContext(QueryBuilderContext);

const associationOptions = associations.map(({ association, qualifiers }) => ({
name: association.name,
uuid: association.uuid,
qualifiers: qualifiers.map((q) => ({
name: q.qualifier.name,
options: getQualifierOptions(q),
})),
}));
const associationOptions = associations
.filter((a) => a.qualifiers.length > 0)
.map(({ association, qualifiers }) => ({
name: association.name,
uuid: association.uuid,
qualifiers: qualifiers.map((q) => ({
name: q.qualifier.name,
options: getQualifierOptions(q),
})),
}));

const [value, setValue] = React.useState(associationOptions[0] || null);
const [qualifiers, setQualifiers] = React.useState({});
Expand All @@ -75,6 +77,7 @@ export default function QualifiersSelector({ id, associations }) {
onChange={(_, newValue) => {
setValue(newValue);
}}
disableClearable
size="small"
options={associationOptions}
getOptionLabel={(option) => option.name}
Expand Down
26 changes: 23 additions & 3 deletions src/pages/queryBuilder/textEditor/textEditorRow/TextEditorRow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,26 @@ function getValidAssociations(s, p, o, model) {
return traverse([n], range);
};

// Returns true if `n` is an ancestor of `domain`
const isInDomain = (
n,
domain
) => {
const traverse = (nodes, search) => {
for (const n of nodes) {
if (n === search) return true;
if (n.parent) {
if (traverse([n.parent], search)) return true;
}
if (n.mixinParents) {
if (traverse(n.mixinParents, search)) return true;
}
}
return false;
};
return traverse([domain], n);
};

/**
* Get the inherited subject/predicate/object ranges for an association
*/
Expand Down Expand Up @@ -78,9 +98,9 @@ function getValidAssociations(s, p, o, model) {
if (association.slotUsage && !association.abstract) {
const inherited = getInheritedSPORanges(association);

const validSubject = isInRange(subject, inherited.subject);
const validObject = isInRange(object, inherited.object);
const validPredicate = isInRange(predicate, inherited.predicate);
const validSubject = isInRange(subject, inherited.subject) || isInDomain(subject, inherited.subject);
const validObject = isInRange(object, inherited.object) || isInDomain(object, inherited.object);
const validPredicate = isInRange(predicate, inherited.predicate) || isInDomain(predicate, inherited.predicate);

const qualifiers = Object.entries(association.slotUsage)
.map(([qualifierName, properties]) => {
Expand Down
12 changes: 7 additions & 5 deletions src/pages/queryBuilder/useQueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,13 @@ function reducer(state, action) {
}
case 'editQualifiers': {
const { id, qualifiers } = action.payload;
const qualifier_set = Object.entries(qualifiers).map(([name, value]) => ({
qualifier_type_id: `biolink:${_.snakeCase(name)}`,
qualifier_value: name === 'qualified predicate' ? `biolink:${_.snakeCase(value)}` : _.snakeCase(value),
}));
state.message.message.query_graph.edges[id].qualifier_constraints = [{ qualifier_set }];
if (qualifiers.length !== 0) {
const qualifier_set = Object.entries(qualifiers).map(([name, value]) => ({
qualifier_type_id: `biolink:${_.snakeCase(name)}`,
qualifier_value: name === 'qualified predicate' ? `biolink:${_.snakeCase(value)}` : _.snakeCase(value),
}));
state.message.message.query_graph.edges[id].qualifier_constraints = [{ qualifier_set }];
}
break;
}
case 'deleteEdge': {
Expand Down

0 comments on commit 4a25f97

Please sign in to comment.