bhaskargurram-ai opened a new pull request, #718:
URL: https://github.com/apache/shenyu-dashboard/pull/718
Plugin config, plugin-handle extObj and API-document ext/document are stored
as strings and were passed straight to `JSON.parse` inside render. A record
whose string is malformed, or is valid JSON that is not an object, threw during
render and blanked the Home page, the Plugin and NamespacePlugin lists, the
plugin edit forms and the API-document form.
`src/utils/jsonObject.js` adds `parseJsonObject`, which never throws and
returns `{ value }` for a JSON object, `{ value: undefined }` for null/empty
and `{ error }` for everything else, plus `formatJsonObject` for read-only
views. The Home, Plugin and NamespacePlugin popovers pretty-print a JSON object
as before and otherwise render the original string as text, which React escapes.
The Plugin and NamespacePlugin edit forms keep the stored string. When it is
not a JSON object the schema fields are replaced by a textarea holding the
original text with a validation error shown on open, and the form cannot be
saved until that text is a JSON object; the corrected text is then saved as the
config. Nothing is substituted with `{}`, so a save can no longer overwrite the
stored value with an empty object. A field whose plugin-handle `extObj` is not
a JSON object renders without its required/default/rule metadata instead of
throwing. The API-document form shows `ext` and `document` as text with an
error status when they are not JSON objects; `isJsonStr` already blocks saving
a bad `ext` and is unchanged.
Tests cover null/empty values, malformed strings and valid JSON of an
unexpected type as separate cases in `src/utils/jsonObject.test.js`,
`src/routes/System/Plugin/AddModal.test.js`,
`src/routes/System/NamespacePlugin/AddModal.test.js` and
`src/routes/Document/components/AddAndUpdateApiDoc.test.js`. Against master, 8
of the new tests fail with the uncaught `SyntaxError`; with this change `npm
run test:unit` passes 308 tests in 58 suites, `npm run lint` and `prettier
--check` are clean and `npm run build` succeeds.
Fixes #612
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]