Giter Club home page Giter Club logo

jsonforms-react-seed's Introduction

JSON Forms React seed App

This seed demonstrates how to use JSON Forms with React in order to render a simple form for displaying a task entity.

It is based on create-react-app and only contains minor modifications.

  • Execute npm ci to install the prerequisites. If you want to have the latest released versions use npm install.
  • Execute npm run build to build the application.
  • Execute npm start to start the application.

Browse to http://localhost:3000 to see the application in action.

File Structure

Let's briefly have a look at the most important files:

  • src/schema.json contains the JSON schema (also referred to as 'data schema')
  • src/uischema.json contains the UI schema
  • src/main.tsx is the entry point of the application. We also customize the Material UI theme to give each control more space.
  • src/App.tsx is the main app component and makes use of the JsonForms component in order to render a form.

The data schema defines the structure of a Task: it contains attributes such as title, description, due date and so on.

The corresponding UI schema specifies controls for each property and puts them into a vertical layout that in turn contains two horizontal layouts.

Rendering JSON Forms

JSON Forms is rendered by importing and using the JsonForms component and directly handing over the schema, uischema, data, renderer and cell props. We listen to changes in the form via the onChange callback.

Custom renderers

Please see our corresponding tutorial on how to add custom renderers.

jsonforms-react-seed's People

Contributors

abraham avatar alexandrabuzila avatar edgarmueller avatar eneufeld avatar koegel avatar lucas-koehler avatar lukasboll avatar mayank1513 avatar sdirix avatar thezoker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jsonforms-react-seed's Issues

Libraries and some examples are obsolete

Many of the libraries in package.json are deprecated. Additionally, some code examples are also OBE. For example, rule conditions no longer use type and expectedValue properties and were replaced by schema.

Migrate to TS

As create-react-app has added support for TS beginning with 2.x.x we also should think about making use of TS within our seed app.

Usage of schema based conditions

Also, there is no examples and documents how to use schema based conditions, please can you provide how to use it with master branch code of this repo.

How to capture handleChange in JsonForms in App.jsx?

Let's say I have a input in my uischema and it is rendered using Actions.init(data, schema, uischema),

If i change value inside input box and want to get it's value and set state accordingly, how I can do this?

getting started instructions fail to start app

Running these: https://github.com/eclipsesource/jsonforms?tab=readme-ov-file#getting-started

Produces

# ryanavery at Ryans-MacBook-Pro.local in ~/jsonforms-react-seed on git:master ● [14:13:24]
→ npm run start

> [email protected] start
> vite preview --port 3000

/Users/ryanavery/jsonforms-react-seed/node_modules/rollup/dist/native.js:59
		throw new Error(
		      ^

Error: Cannot find module @rollup/rollup-darwin-arm64. npm has a bug related to optional dependencies (https://github.com/npm/cli/issues/4828). Please try `npm i` again after removing both package-lock.json and node_modules directory.
    at requireWithFriendlyError (/Users/ryanavery/jsonforms-react-seed/node_modules/rollup/dist/native.js:59:9)
    at Object.<anonymous> (/Users/ryanavery/jsonforms-react-seed/node_modules/rollup/dist/native.js:68:76)
    at Module._compile (node:internal/modules/cjs/loader:1467:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1551:10)
    at Module.load (node:internal/modules/cjs/loader:1282:32)
    at Module._load (node:internal/modules/cjs/loader:1098:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
    at cjsLoader (node:internal/modules/esm/translators:318:5)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:258:7) {
  [cause]: Error: Cannot find module '@rollup/rollup-darwin-arm64'
  Require stack:
  - /Users/ryanavery/jsonforms-react-seed/node_modules/rollup/dist/native.js
      at Module._resolveFilename (node:internal/modules/cjs/loader:1219:15)
      at Module._load (node:internal/modules/cjs/loader:1045:27)
      at TracingChannel.traceSync (node:diagnostics_channel:315:14)
      at wrapModuleLoad (node:internal/modules/cjs/loader:215:24)
      at Module.require (node:internal/modules/cjs/loader:1304:12)
      at require (node:internal/modules/helpers:123:16)
      at requireWithFriendlyError (/Users/ryanavery/jsonforms-react-seed/node_modules/rollup/dist/native.js:41:10)
      at Object.<anonymous> (/Users/ryanavery/jsonforms-react-seed/node_modules/rollup/dist/native.js:68:76)
      at Module._compile (node:internal/modules/cjs/loader:1467:14)
      at Module._extensions..js (node:internal/modules/cjs/loader:1551:10) {
    code: 'MODULE_NOT_FOUND',
    requireStack: [
      '/Users/ryanavery/jsonforms-react-seed/node_modules/rollup/dist/native.js'
    ]
  }
}

Node.js v22.4.1

array no default rendering

when json schema contains:
"properties": {
"labels": {
"type": "array",
"items": [{ "type": "string" }]
},
where, for example, matching data could be:
{
"labels" : ["257","340"],
},
Then, for this array, default renderer displays:
"No applicable renderer found."

render image?

hi, how can I use it to display image with custom height/width and border or change the location of the form or entire object or am I asking too much ?

Make field "Required" in Array

Hi,
First of all, thanks for building and publishing this great frame work.
I got a newbie question.
I have this json in shcema.json and ui.json.

How do I make a field inside array "Required" so App will to in-line validation if that field is not entered.
Thanks
Sabbir
shcema.json

{
	"type": "object",
	"properties": {
		"schedules": {
			"type": "array",
			"minItems": 1,
			"maxItems": 4,
			"items": {
				"type": "object",
				"properties": {
					"ODKey": {
						"type": "string",
						"enum": ["OD1",
						"OD2",
						"OD3",
						"OD4"]
					},
					"DepAirportCode": {
						"type": "string",
						"maxLength": 3,
						"minLength": 3
					},
					"ArvAirportCode": {
						"type": "string",
						"maxLength": 3,
						"minLength": 3
					},
					"FlightDate": {
						"type": "string",
						"format": "date"
					}
				}
			}			
		}
	}
}

ui.json

{
	"type": "VerticalLayout",
	"elements": [{
		"type": "Control",
		"label": "Origin, Destination Port and Flight Date (Maximum 4)",
		"scope": "#/properties/schedules"
	}]
}

Support yaml schemas

I wish

to support yaml syntax for uischema.yaml and schema.yaml

Note

I'll try to make a PR.

Website down

jsonforms.io is down at the moment. Cam some one look that up.

Complex JSON

I'm trying to use your forms and they're great.
But I Have a Question: Could I use more complex json forman like:

{
  "data": {
    "getTaskForm": {
      "task": "UserTask",
      "name": "clientUser",
      "formKey": "testId",
      "fields": [
        {
          "id": "firstName",
          "label": "Fiirst Name",
          "type": "string",
          "default": "",
          "enum": null,
          "constraints": null,
          "properties": [
            {
              "property": "materialType",
              "value": "TextField"
            }
          ]
        }
      ]
    }
  }
}

Thanks a lot for answer.

Clone not working

After cloning the repository, I got a blank page. It appear that since src/index.tsx is missing, the page does not load.
Also, it renders the index.html from the root folder instead of the one in public/index.html.

What to do now?

Custom renderer issue

Issue:- When we are creating custom renderers, jsonforms internally binds custom renderer with uischema.json (scope) and data.json (field name)

Expectation:- Instead of binding both data.json and uischema.json can we only bind our renderer to uischema.json

Remove downstream dependencies

The current seed contains the following downstream dependencies:

  • @babel/runtime
  • @material-ui/core

They should be removed once they are included by immediate dependencies (e.g. @jsonforms/material-renderers)

Issue build error

When running this command , an error occurred
..\jsonforms\jsonforms-editor>npm run build

build
lerna run build

lerna notice cli v4.0.0
lerna info Executing command in 2 packages: "npm run build"
lerna ERR! npm run build exited 1 in '@jsonforms/editor'
lerna ERR! npm run build stdout:

@jsonforms/[email protected] build ..\jsonforms\jsonforms-editor\jsonforms-editor
rimraf dist && rollup --config rollup.config.ts

lerna ERR! npm run build stderr:
'rollup' is not recognized as an internal or external command,
operable program or batch file.

npm ERR! Windows_NT 10.0.22621
npm ERR! argv "..\nodejs\node.exe" "..\node_modules\npm\bin\npm-cli.js" "run" "build"
npm ERR! node v18.14.2
npm ERR! npm v2.15.12
npm ERR! code ELIFECYCLE
npm ERR! @jsonforms/[email protected] build: rimraf dist && rollup --config rollup.config.ts
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @jsonforms/[email protected] build script 'rimraf dist && rollup --config rollup.config.ts'.
npm ERR! This is most likely a problem with the @jsonforms/editor package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! rimraf dist && rollup --config rollup.config.ts
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs @jsonforms/editor
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls @jsonforms/editor
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! ..\jsonforms\jsonforms-editor\jsonforms-editor\npm-debug.log
lerna ERR! npm run build exited 1 in '@jsonforms/editor'
npm-debug.log

Number validation not working

Sorry, it's me again.

I am trying to add a form with the following schema:

const schema = {
  type: 'object',
  properties: {
    ...otherFields,
    docNo: {
      type: 'integer', // or 'number'
      title: 'Document Number',
    },
  },
}

When I enter invalid values (as in: letters) for docNo the following happens

  • first invalid value: onChange is triggered with errors == [] and docNo == undefined
  • subsequent invalid values: onChange is not triggered again

If I enter something valid in other fields, onChange is triggered again with errors == [] and docNo == undefined

As soon as I delete the invalid values and enter something valid, e.g. '123', the onChange passes the correct value for docNo.

Other validations work correctly.

Here's a minimal example from my repo:

import { materialCells, materialRenderers } from '@jsonforms/material-renderers'

import AppFrame from '../../layouts/AppFrame'
import ContentAreaLayout from '../../layouts/ContentAreaLayout'
import { JsonForms } from '@jsonforms/react'
import { useState } from 'react'

const schema = {
  type: 'object',
  properties: {
    issuedBy: {
      type: 'string',
      title: 'Issuer',
    },
    issueDate: {
      type: 'string',
      format: 'date',
      title: 'Issue Date',
    },
    expiryDate: {
      type: 'string',
      format: 'date',
      title: 'Expiry Date',
    },
    docNo: {
      type: 'integer', // same with 'number'
      title: 'Document Number',
    },
  },
}

const defaultData = {
  issuedBy: 'Ministry of Foreign Affairs',
  issueDate: '2015-01-01',
  expiryDate: '2015-12-31',
  docNo: 123,
}

export default function Page() {
  const [currentData, setCurrentData] = useState(defaultData)
  return (
    <AppFrame pageTitle="JsonFormTestPage">
      <ContentAreaLayout>
        <div>
          <JsonForms
            renderers={materialRenderers}
            cells={materialCells}
            data={currentData}
            schema={schema}
            onChange={({ data, errors }) => {
              console.log({ data, errors })
              setCurrentData(data)
            }}
          />
        </div>
      </ContentAreaLayout>
    </AppFrame>
  )
}

Screenshot of the console when entering the first invalid value:
image

I am using:

"@jsonforms/core": "^3.1.0",
"@jsonforms/material-renderers": "^3.1.0",
"@jsonforms/react": "^3.1.0",
"@mui/icons-material": "^5.11.16",

Am I missing something? My expectation is that the errors object in onChange contains an error as soon as I start typing letters into a numbers field and the data object contains the invalid values for docNo.

TODOs in description

There are several TODOs in the description (missing links).
Further it would be nice to know how to access the seed application in a browser after launching it

Cannot launch the app

Hi, I installed this package to fail to launch the app.
It says the following error.

./node_modules/@material-ui/lab/Slider/Slider.js
Module not found: Can't resolve '@babel/runtime/helpers/builtin/classCallCheck' in '/path/to/jsonforms-react-seed/node_modules/@material-ui/lab/Slider'

MacOS X 10.12.6
Node.js v8.9.0
npm 5.5.1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.