Skip to content

Commit 75dff37

Browse files
TheZokersdirix
andauthored
Restructure and update to JSON Forms 2.5
* Remove redux from react-seed * Replace initialData with jsonformsData * Add yalc to gitignore * Add clear data button * Replace data attribute with uischema attribute * Refactor Rating to functional component * Remove not needed styles * Clear data instead of reset data * Update README * Showcases labels and titles * Adjust theme to give controls more space * Remove horizontal scrollbar * Update to JSON Forms 2.5.0 Co-authored-by: Stefan Dirix <[email protected]>
1 parent 7d9a751 commit 75dff37

18 files changed

+7053
-5258
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,6 @@ typings/
5959

6060
.idea
6161

62-
build
62+
build
63+
.yalc
64+
yalc.lock

README.md

+16-59
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,31 @@
1-
This project was bootstrapped with [Create React App](https://github.com/facebookincubator/create-react-app).
21
# JSON Forms React seed App
3-
This seed demonstrates how to use [JSON Forms](https://jsonforms.io) with React in order to render a simple form for displaying a task entity. It showcases both the redux variant and the React standalone component (without redux).
4-
5-
It is based on create-react-app and only contains minor modifications.
62

7-
* Execute `npm ci` to install the prerequisites. If you want to have the latest released versions use `npm install`.
8-
* Execute `npm start` to start the application.
9-
10-
Browse to http://localhost:3000 to see the application in action.
3+
This seed demonstrates how to use [JSON Forms](https://jsonforms.io) with React in order to render a simple form for displaying a task entity.
114

12-
## File Structure
13-
Let's briefly have a look at the most important files:
14-
* `src/schema.json` contains the JSON schema (also referred to as 'data schema')
15-
* `src/uischema.json` contains the UI schema
16-
* `src/index.js` is the entry point of the application and sets up the redux store that contains the data, the JSON and the UI schema necessary for JSON Forms.
17-
* `src/App.js` is the main React component and makes use of the core JSON Forms component or the React standalone component in order to render a form.
18-
19-
The [data schema](https://github.com/eclipsesource/jsonforms-react-seed/blob/master/src/schema.json) defines the structure of a Task: it contains attributes such as title, description, due date and so on.
20-
21-
The [corresponding UI schema](https://github.com/eclipsesource/jsonforms-react-seed/blob/master/src/uischema.json) specifies controls for each property and puts them into a vertical layout that in turn contains two horizontal layouts.
22-
23-
Both the data schema and the UI schema are imported within `index.js` and are used to set up a redux store. We make use of a helper function exported by JSON Forms which expects the initial state. If you already have an existing redux store, you'll need to import the jsonforms reducer and add it to your store. Please refer to [the tutorial](https://jsonforms.io/docs/tutorial) for how to do this.
5+
It is based on `create-react-app` and only contains minor modifications.
246

25-
## Setting up the store
7+
- Execute `npm ci` to install the prerequisites. If you want to have the latest released versions use `npm install`.
8+
- Execute `npm start` to start the application.
269

27-
```js
28-
const store = createStore(
29-
jsonformsReducer(),
30-
{
31-
jsonforms: {
32-
common: {
33-
data,
34-
schema,
35-
uischema
36-
},
37-
renderers: JsonForms.renderers,
38-
cells: JsonForms.cells
39-
},
40-
},
41-
applyMiddleware(thunk)
42-
);
10+
Browse to http://localhost:3000 to see the application in action.
4311

44-
// initialize store
45-
store.dispatch({
46-
type: Actions.INIT,
47-
data,
48-
schema,
49-
uischema,
50-
});
12+
## File Structure
5113

52-
// trigger initial validation
53-
store.dispatch(Actions.validate());
54-
```
14+
Let's briefly have a look at the most important files:
5515

56-
We then use the `Provider` component provided by `react-redux` to provide the store to the JSON Forms redux component and all its children.
16+
- `src/schema.json` contains the JSON schema (also referred to as 'data schema')
17+
- `src/uischema.json` contains the UI schema
18+
- `src/index.tsx` is the entry point of the application. We also customize the Material UI theme to give each control more space.
19+
- `src/App.tsx` is the main app component and makes use of the `JsonForms` component in order to render a form.
5720

58-
```js
59-
<Provider store={store}>
60-
<JsonFormsReduxContext>
61-
<JsonFormsDispatch />
62-
</JsonFormsReduxContext>
63-
</Provider>
64-
```
21+
The [data schema](src/schema.json) defines the structure of a Task: it contains attributes such as title, description, due date and so on.
6522

66-
## Rendering our form
67-
The `App` component is responsible for rendering our actual forms.
23+
The [corresponding UI schema](src/uischema.json) specifies controls for each property and puts them into a vertical layout that in turn contains two horizontal layouts.
6824

69-
The redux form is rendered by importing and using `DispatchRenderer` from `@jsonforms/core`. `DispatchRenderer` expects `schema` and `uischema` props which define the form to be rendered but if those are omitted, they will be pulled from the store which was provided via `Provider` previously.
25+
## Rendering JSON Forms
7026

71-
The standalone form 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 .
27+
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.
7228

7329
## Custom renderers
30+
7431
Please see [our corresponding tutorial](https://jsonforms.io/docs/tutorial) on how to add custom renderers.

cypress/plugins/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/// <reference types="cypress" />
2+
// ***********************************************************
3+
// This example plugins/index.js can be used to load plugins
4+
//
5+
// You can change the location of this file or turn off loading
6+
// the plugins file with the 'pluginsFile' configuration option.
7+
//
8+
// You can read more here:
9+
// https://on.cypress.io/plugins-guide
10+
// ***********************************************************
11+
12+
// This function is called when a project is opened or re-opened (e.g. due to
13+
// the project's config changing)
14+
15+
/**
16+
* @type {Cypress.PluginConfig}
17+
*/
18+
module.exports = (on, config) => {
19+
// `on` is used to hook into various events Cypress emits
20+
// `config` is the resolved Cypress config
21+
}

cypress/support/commands.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// ***********************************************
2+
// This example commands.js shows you how to
3+
// create various custom commands and overwrite
4+
// existing commands.
5+
//
6+
// For more comprehensive examples of custom
7+
// commands please read more here:
8+
// https://on.cypress.io/custom-commands
9+
// ***********************************************
10+
//
11+
//
12+
// -- This is a parent command --
13+
// Cypress.Commands.add("login", (email, password) => { ... })
14+
//
15+
//
16+
// -- This is a child command --
17+
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
18+
//
19+
//
20+
// -- This is a dual command --
21+
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
22+
//
23+
//
24+
// -- This will overwrite an existing command --
25+
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })

cypress/support/index.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// ***********************************************************
2+
// This example support/index.js is processed and
3+
// loaded automatically before your test files.
4+
//
5+
// This is a great place to put global configuration and
6+
// behavior that modifies Cypress.
7+
//
8+
// You can change the location of this file or turn off
9+
// automatically serving support files with the
10+
// 'supportFile' configuration option.
11+
//
12+
// You can read more here:
13+
// https://on.cypress.io/configuration
14+
// ***********************************************************
15+
16+
// Import commands.js using ES2015 syntax:
17+
import './commands'
18+
19+
// Alternatively you can use CommonJS syntax:
20+
// require('./commands')

0 commit comments

Comments
 (0)