Skip to content

Commit

Permalink
disallow adding of Involved things if data not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Tilsch committed Feb 10, 2024
1 parent 89019d8 commit 01e56cd
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions apps/exhibition-live/components/renderer/MaterialArrayLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ import {
JsonSchema7,
Resolve,
} from "@jsonforms/core";
import map from "lodash/map";
import merge from "lodash/merge";
import range from "lodash/range";
import React, { useCallback, useMemo, useState } from "react";

import { ArrayLayoutToolbar, getDefaultKey } from "./ArrayToolbar";
Expand All @@ -57,6 +55,7 @@ import AddIcon from "@mui/icons-material/Add";
import { useGlobalCRUDOptions } from "../state/useGlobalCRUDOptions";
import { useCRUDWithQueryClient } from "../state/useCRUDWithQueryClient";
import { useSnackbar } from "notistack";
import { ErrorObject } from "ajv";

type OwnProps = {
removeItems(path: string, toDelete: number[]): () => void;
Expand Down Expand Up @@ -90,6 +89,16 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps & {}) => {
irisToData(slent(uuidv4()).value, typeIRI),
);

const handleInlineFormDataChange = useCallback(
(data: any) => {
console.log("data", data);
setFormData({
data,
});
},
[setFormData],
);

const handleCreateNew = useCallback(() => {
setFormData(irisToData(slent(uuidv4()).value, typeIRI));
setModalIsOpen(true);
Expand Down Expand Up @@ -147,6 +156,16 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps & {}) => {
}, [setModalIsOpen, addItem, formData, setFormData, typeIRI]);

const isReifiedStatement = Boolean(appliedUiSchemaOptions.isReifiedStatement);
const [inlineErrors, setInlineErrors] = useState<ErrorObject[]>([]);
const handleErrors = useCallback(
(err: ErrorObject[]) => {
console.log("errors", err);
setInlineErrors(err);
},
[setInlineErrors],
);

const formsPath = useMemo(() => makeFormsPath(config?.formsPath, path), [config?.formsPath, path]);

return (
<div>
Expand Down Expand Up @@ -195,16 +214,20 @@ const MaterialArrayLayoutComponent = (props: ArrayLayoutProps & {}) => {
schema={subSchema}
entityIRI={formData["@id"]}
typeIRI={typeIRI}
onError={handleErrors}
formData={formData}
onFormDataChange={(data) => setFormData(data)}
onFormDataChange={handleInlineFormDataChange}
semanticJsonFormsProps={{
disableSimilarityFinder: true,
}}
formsPath={makeFormsPath(config?.formsPath, path)}
formsPath={formsPath}
/>
</Grid>
<Grid item>
<IconButton onClick={handleSaveAndAdd}>
<IconButton
disabled={inlineErrors?.length > 0}
onClick={handleSaveAndAdd}
>
<AddIcon style={{ fontSize: 40 }} />
</IconButton>
</Grid>
Expand Down

0 comments on commit 01e56cd

Please sign in to comment.