From aff90e0ca8783059c7fa6466d22b6b2e7eece64a Mon Sep 17 00:00:00 2001 From: Julian Gonggrijp Date: Fri, 7 May 2021 16:37:03 +0200 Subject: [PATCH] Generalize applicablePredicates (#455) --- frontend/src/utilities/relation-utilities.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/utilities/relation-utilities.ts b/frontend/src/utilities/relation-utilities.ts index bc37609f8..2a224d0b0 100644 --- a/frontend/src/utilities/relation-utilities.ts +++ b/frontend/src/utilities/relation-utilities.ts @@ -1,4 +1,4 @@ -import { forEach, some, keys, ListIterator } from 'lodash'; +import { forEach, some, keys, ListIterator, isString } from 'lodash'; import Collection from '../core/collection'; import ldChannel from '../common-rdf/radio'; @@ -33,11 +33,13 @@ export function matchRelatee(direction: string, types: Node[]) { } /** - * Returns a Graph with all direct and inverse predicates applicable to model. + * Returns a Graph with all direct and inverse predicates applicable to `model`. + * If `model` is a bare string, it is assumed to name the range type. * This function runs entirely sync. */ -export function applicablePredicates(model: Node): Graph { - const allTypes = getRdfSuperClasses(model.get('@type') as string[]); +export function applicablePredicates(model: Node | string): Graph { + const seed = isString(model) ? [model] : model.get('@type') as string[]; + const allTypes = getRdfSuperClasses(seed); const predicates = new Graph(); const ontology = ldChannel.request('ontology:graph') as Graph; // predicates that can have model in subject position