From b28d921ffc4673a4b83af7cec0db8ec043a95d73 Mon Sep 17 00:00:00 2001 From: burnettk Date: Wed, 16 Nov 2022 18:16:55 -0500 Subject: [PATCH] add inline errors --- spiffworkflow-frontend/package-lock.json | 27 +++++++++++++++++++ spiffworkflow-frontend/package.json | 6 ++--- .../src/routes/TaskShow.tsx | 6 ++++- .../BaseInputTemplate/BaseInputTemplate.tsx | 9 +++++++ 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/spiffworkflow-frontend/package-lock.json b/spiffworkflow-frontend/package-lock.json index af9761979..4898b19cf 100644 --- a/spiffworkflow-frontend/package-lock.json +++ b/spiffworkflow-frontend/package-lock.json @@ -23,6 +23,7 @@ "@rjsf/core": "*", "@rjsf/mui": "^5.0.0-beta.13", "@rjsf/utils": "^5.0.0-beta.13", + "@rjsf/validator-ajv6": "^5.0.0-beta.13", "@rjsf/validator-ajv8": "^5.0.0-beta.13", "@tanstack/react-table": "^8.2.2", "@testing-library/jest-dom": "^5.16.4", @@ -4933,6 +4934,22 @@ "resolved": "https://registry.npmjs.org/react-is/-/react-is-18.2.0.tgz", "integrity": "sha512-xWGDIW6x921xtzPkhiULtthJHoJvBbF3q26fzloPCK0hsvxtPVelvftw3zjbHWSkR2km9Z+4uxbDDK/6Zw9B8w==" }, + "node_modules/@rjsf/validator-ajv6": { + "version": "5.0.0-beta.13", + "resolved": "https://registry.npmjs.org/@rjsf/validator-ajv6/-/validator-ajv6-5.0.0-beta.13.tgz", + "integrity": "sha512-X9N3/HJYV23MjUN/VJHIdBhUdBuMTUsh4HAZm50eUvUAhWK95wIqjjhAs24rzeLajrjFeH7kFr89zAqDgIFhVQ==", + "dependencies": { + "ajv": "^6.7.0", + "lodash": "^4.17.15", + "lodash-es": "^4.17.15" + }, + "engines": { + "node": ">=14" + }, + "peerDependencies": { + "@rjsf/utils": "^5.0.0-beta.1" + } + }, "node_modules/@rjsf/validator-ajv8": { "version": "5.0.0-beta.13", "resolved": "https://registry.npmjs.org/@rjsf/validator-ajv8/-/validator-ajv8-5.0.0-beta.13.tgz", @@ -34856,6 +34873,16 @@ } } }, + "@rjsf/validator-ajv6": { + "version": "5.0.0-beta.13", + "resolved": "https://registry.npmjs.org/@rjsf/validator-ajv6/-/validator-ajv6-5.0.0-beta.13.tgz", + "integrity": "sha512-X9N3/HJYV23MjUN/VJHIdBhUdBuMTUsh4HAZm50eUvUAhWK95wIqjjhAs24rzeLajrjFeH7kFr89zAqDgIFhVQ==", + "requires": { + "ajv": "^6.7.0", + "lodash": "^4.17.15", + "lodash-es": "^4.17.15" + } + }, "@rjsf/validator-ajv8": { "version": "5.0.0-beta.13", "resolved": "https://registry.npmjs.org/@rjsf/validator-ajv8/-/validator-ajv8-5.0.0-beta.13.tgz", diff --git a/spiffworkflow-frontend/package.json b/spiffworkflow-frontend/package.json index 4829368a2..b896bdcec 100644 --- a/spiffworkflow-frontend/package.json +++ b/spiffworkflow-frontend/package.json @@ -18,7 +18,7 @@ "@rjsf/core": "*", "@rjsf/mui": "^5.0.0-beta.13", "@rjsf/utils": "^5.0.0-beta.13", - "@rjsf/validator-ajv8": "^5.0.0-beta.13", + "@rjsf/validator-ajv6": "^5.0.0-beta.13", "@tanstack/react-table": "^8.2.2", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", @@ -79,8 +79,8 @@ "t": "npm test -- --watchAll=false", "eject": "craco eject", "format": "prettier --write src/**/*.[tj]s{,x}", - "lint": "./node_modules/.bin/eslint src *.[tj]s{,x}", - "lint:fix": "./node_modules/.bin/eslint --fix src *.[tj]s{,x}" + "lint": "./node_modules/.bin/eslint src", + "lint:fix": "./node_modules/.bin/eslint --fix src" }, "eslintConfig": { "extends": [ diff --git a/spiffworkflow-frontend/src/routes/TaskShow.tsx b/spiffworkflow-frontend/src/routes/TaskShow.tsx index 818670952..ec25d49d7 100644 --- a/spiffworkflow-frontend/src/routes/TaskShow.tsx +++ b/spiffworkflow-frontend/src/routes/TaskShow.tsx @@ -1,12 +1,16 @@ import { useContext, useEffect, useState } from 'react'; import { Link, useNavigate, useParams } from 'react-router-dom'; -import validator from '@rjsf/validator-ajv8'; + +// FIXME: npm install @rjsf/validator-ajv8 and use it as soon as +// rawErrors is fixed. +import validator from '@rjsf/validator-ajv6'; // @ts-ignore import { Button, Stack } from '@carbon/react'; import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; +// eslint-disable-next-line import/no-named-as-default import Form from '../themes/carbon'; import HttpService from '../services/HttpService'; import ErrorContext from '../contexts/ErrorContext'; diff --git a/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx b/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx index eea1abe0e..90cc3f0f8 100644 --- a/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx +++ b/spiffworkflow-frontend/src/themes/carbon/BaseInputTemplate/BaseInputTemplate.tsx @@ -83,12 +83,21 @@ export default function BaseInputTemplate< labelToUse = schema.title; } + let invalid = false; + let errorMessageForField = null; + if (rawErrors && rawErrors.length > 0) { + invalid = true; + errorMessageForField = `${labelToUse} ${rawErrors[0]}`; + } + return ( <>