From 320ed019e0e49af4f271ca8bea4d1c3898d47272 Mon Sep 17 00:00:00 2001 From: Polle Pas Date: Mon, 16 Oct 2023 16:41:50 +0200 Subject: [PATCH] #648 Add ontology test --- .../components/ResourceContextMenu/index.tsx | 13 +- .../forms/NewForm/NewFormDialog.tsx | 6 +- .../src/components/forms/ResourceField.tsx | 15 +- .../components/forms/SearchBox/SearchBox.tsx | 6 +- .../OntologyPage/Class/ClassCardWrite.tsx | 2 +- .../OntologyPage/CreateInstanceButton.tsx | 9 +- .../Property/PropertyLineWrite.tsx | 12 +- browser/data-browser/tests/ontology.spec.ts | 214 ++++++++++++++++++ browser/data-browser/tests/tables.spec.ts | 2 +- browser/data-browser/tests/test-utils.ts | 12 +- browser/lib/src/search.ts | 24 +- browser/react/src/useServerSearch.tsx | 24 +- 12 files changed, 309 insertions(+), 30 deletions(-) create mode 100644 browser/data-browser/tests/ontology.spec.ts diff --git a/browser/data-browser/src/components/ResourceContextMenu/index.tsx b/browser/data-browser/src/components/ResourceContextMenu/index.tsx index 127cd38f8..c4edd1502 100644 --- a/browser/data-browser/src/components/ResourceContextMenu/index.tsx +++ b/browser/data-browser/src/components/ResourceContextMenu/index.tsx @@ -1,6 +1,6 @@ import React, { useCallback } from 'react'; import { useLocation, useNavigate } from 'react-router-dom'; -import { Client, properties, useResource, useStore } from '@tomic/react'; +import { Client, core, useResource, useStore } from '@tomic/react'; import { editURL, dataURL, @@ -57,6 +57,7 @@ export interface ResourceContextMenuProps { bindActive?: (active: boolean) => void; /** Callback that is called after the resource was deleted */ onAfterDelete?: () => void; + title?: string; } /** Dropdown menu that opens a bunch of actions for some resource */ @@ -66,6 +67,7 @@ function ResourceContextMenu({ trigger, simple, isMainMenu, + title, bindActive, onAfterDelete, }: ResourceContextMenuProps) { @@ -80,7 +82,7 @@ function ResourceContextMenu({ // Try to not have a useResource hook in here, as that will lead to many costly fetches when the user enters a new subject const handleDestroy = useCallback(async () => { - const parent = resource.get(properties.parent); + const parent = resource.get(core.properties.parent); try { await resource.destroy(store); @@ -187,7 +189,12 @@ function ResourceContextMenu({ ) : items; - const triggerComp = trigger ?? buildDefaultTrigger(); + const triggerComp = + trigger ?? + buildDefaultTrigger( + , + title ?? `Open ${resource.title} menu`, + ); return ( <> diff --git a/browser/data-browser/src/components/forms/NewForm/NewFormDialog.tsx b/browser/data-browser/src/components/forms/NewForm/NewFormDialog.tsx index 6b620f3dd..1f05548f0 100644 --- a/browser/data-browser/src/components/forms/NewForm/NewFormDialog.tsx +++ b/browser/data-browser/src/components/forms/NewForm/NewFormDialog.tsx @@ -14,7 +14,7 @@ import { useNewForm } from './useNewForm'; import { getNamePartFromProps } from '../../../helpers/getNamePartFromProps'; export interface NewFormDialogProps extends NewFormProps { - closeDialog: () => void; + closeDialog: (success?: boolean) => void; initialProps?: Record; onSave: (subject: string) => void; parent: string; @@ -43,7 +43,7 @@ export const NewFormDialog = ({ const onResourceSave = useCallback(() => { onSave(resource.getSubject()); - closeDialog(); + closeDialog(true); }, [onSave, closeDialog, resource]); // Onmount we generate a new subject based on the classtype and the user input. @@ -95,7 +95,7 @@ export const NewFormDialog = ({ {error && {error.message}} -