Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add migration guide for version 3.0 #1764

Merged
merged 5 commits into from
Jun 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 101 additions & 16 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,71 @@
# Migrating to JSON Forms 2.5 for Angular users
The JsonFormsAngularService is not provided in the root anymore.
# Migration guide

## Migrating to JSON Forms 3.0 for React users

With version 3.0 of JSON Forms, we removed the `json-schema-ref-parser` dependency within the core package.
This change only affects users of the React variant, Vue and Angular users are not affected.

`json-schema-ref-parser` was used to resolve external JSON Schema references.
As a side effect it also resolved 'internal' references and therefore simplified the JSON Schema for JSON Forms' processing.
However that resolving was quite slow, the JSON Schema was mutated in place and `json-schema-ref-parser` brought in Node-only dependencies which needed to be polyfilled.
Also all users of JSON Forms React had to pay the resolving effort, whether they needed it or not.

Most React users should be unaffected by this change and don't need to spend any migration efforts.
However when you relied on the resolving of external JSON Schema references via the `refParserOptions` or use complicated references setups which can't yet be handled by JSON Forms' internal processing, you can resolve the JSON Schema before handing it over to JSON Forms.

Note that we're aware of some regressions caused by removing `json-schema-ref-parser` which occur when not handing over a resolved JSON Schema to JSON Forms.
We're working on removing these edge cases during the JSON Forms 3.0 alpha period.
You can always restore the old behavior when following the approach described below.

To restore the old behavior, you can use `json-schema-ref-parser` or other libraries like `json-refs` to resolve references on your own before passing the schema to JSON Forms.

```ts
import React, { useState } from 'react';
import { JsonForms } from '@jsonforms/react';
import { materialCells, materialRenderers } from '@jsonforms/material-renderers';
import $RefParser from '@apidevtools/json-schema-ref-parser';
import JsonRefs from 'json-refs';

import mySchemaWithReferences from 'myschema.json';

const refParserOptions = {
dereference: {
circular: false
}
}

function App() {
const [data, setData] = useState(initialData);
const [resolvedSchema, setSchema] = useState();

useEffect(() => {
$RefParser.dereference(mySchemaWithReferences).then(res => setSchema(res.$schema));
// or
JsonRefs.resolveRefs(mySchemaWithReferences).then(res => setSchema(res.resolved));
},[]);

if(resolvedSchema === undefined) {
return <div> Loading... </div>
}

return (
<JsonForms
schema={resolvedSchema}
uischema={uischema}
data={data}
renderers={materialRenderers}
cells={materialCells}
onChange={({ data, _errors }) => setData(data)}
/>
);
}
```

For more information have a look at our [ref-resolving](https://jsonforms.io/docs/ref-resolving) docs page.

## Migrating to JSON Forms 2.5 for Angular users

The JsonFormsAngularService is not provided in the root anymore.
To keep the old behavior, you need to provide it manually in the module.

The preferred way is using the new JsonForms Component though.
Expand Down Expand Up @@ -42,7 +108,7 @@ export class AppComponent {
}
```

# Migrating to JSON Forms 2.5 for React users
## Migrating to JSON Forms 2.5 for React users

In version 2.5 we made the `redux` dependency within the `react` package optional.
Users of the JSON Forms React standalone version (i.e. without Redux) don't need to change anything.
Expand All @@ -51,6 +117,7 @@ In contrary you no longer need to install 'redux' and 'react-redux' to use JSON
Users of the JSON Forms Redux variant need to perform some changes.

Basically there are two different approaches:

1. Migrate your app to the standalone variant
2. Keep using the Redux variant of JSON Forms

Expand All @@ -60,14 +127,16 @@ In any case, users of the vanilla renderers need to migrate style definitions.
Providing style classes via the redux context is no longer supported even when using the redux fallback.
For more information see the [vanilla renderer style guide](./packages/vanilla/Styles.md).

## Case 1: Migrate to the standalone variant (recommended)
### Case 1: Migrate to the standalone variant (recommended)

The standalone JSON Forms variant is the new default and the main focus for new features and bug fixes.
We definitely recommend migrating to this version as soon as possible.
All current Redux functionally can also be achieved with the standalone version.

### Example 1: Init action
#### Example 1: Init action

Previously the store was initialized like this:

```ts
const store = createStore(
combineReducers({ jsonforms: jsonformsReducer() }),
Expand All @@ -89,6 +158,7 @@ return (
```

Instead of creating a store and passing the required information to that store, we rather pass it directly to the `<JsonForms .../>` component:

```ts
return (
<JsonForms
Expand All @@ -101,15 +171,18 @@ return (
);
```

### Example 2: Register a custom renderer
#### Example 2: Register a custom renderer

Another commonly used action is the 'register renderer' action.

With Redux this could look like this:

```ts
store.dispatch(Actions.registerRenderer(customControlTester, CustomControl));
```

Within the standalone version, the renderer can just be provided to the `<JsonForms .../>` element like this:

```ts
const renderers = [
...materialRenderers,
Expand All @@ -125,7 +198,9 @@ const MyApp = () => (
);

```
### Example 3: Listen to data and validation changes

#### Example 3: Listen to data and validation changes

The `JsonForms` component offers to register a listener which is notified whenever `data` and `errors` changes:

```ts
Expand All @@ -141,7 +216,7 @@ const MyApp = () => {
};
```

## Case 2: Use the Redux fallback
### Case 2: Use the Redux fallback

If you want to keep using the Redux variant of JSON Forms for now (which is not recommended), you have to change a few import paths.

Expand All @@ -151,22 +226,26 @@ The new imports are available at `@jsonforms/react/lib/redux`, i.e.
import { jsonformsReducer, JsonFormsReduxProvider } from '@jsonforms/react/lib/redux';
```

# Migrating from JSON Forms 1.x (AngularJS 1.x)
## Migrating from JSON Forms 1.x (AngularJS 1.x)

The complexity of the migration of an existing JSON Forms 1.x application, which is based on AngularJS, to JSON Forms 2.x depends on the feature set you use.

## Architectural changes in JSON Forms 2.x
### Architectural changes in JSON Forms 2.x

There are two big changes between JSON Forms 1 and JSON Forms 2 you need to understand when migrating your existing application.

1. JSON Forms 2.x does not rely on any specific UI framework [or library]. The `2.0.0` initial release featured renderers based on [React](https://reactjs.org). An [Angular](https://angular.io) based renderer set was released with `2.1.0`.

2. Since JSON Forms 2.x maintains its internal state via [redux](https://redux.js.org/), you will need to add it as a dependency to your application.

## Steps for upgrading your application to JSON Forms 2.x
### Steps for upgrading your application to JSON Forms 2.x

#### Step 1: Update your UI schemata

### Step 1: Update your UI schemata
There is only one minor change in the UI schemata. The UI Schema for controls was simplified and the bulky `ref` object inside `scope` was removed.

Instead of:

```ts
const uischema = {
type: 'Control',
Expand All @@ -175,20 +254,26 @@ const uischema = {
}
}
```

simply write:

```ts
const uischema = {
type: 'Control',
scope: '#/properties/name'
}
```

Otherwise the UI schema remains unchanged and works like in JSON Forms 1.x.

### Step 2: Use JSON Forms 2.x in your application
#### Step 2: Use JSON Forms 2.x in your application

As JSON Forms 2 does not rely on any specific UI framework or library you can choose which renderer set you want to use. The React Material renderer set is the most polished one at the moment, followed by Angular Material and the Vanilla renderer sets.

#### Use with React
Please refer to the React [Tutorial](http://jsonforms.io/docs/tutorial).
##### Use with React

Please refer to the React [tutorial](http://jsonforms.io/docs/tutorial).

#### Step 3: Migrate Custom Renderers

### Step 3: Migrate Custom Renderers
Any custom renderer needs to be re-factored to conform to the new custom renderer style in JSON Forms 2.x. You can find instructions how to implement Custom controls based on React [here](http://jsonforms.io/docs/custom-renderers). While you need to change a lot except for the template, the good news it that writing custom renderers became much simpler in JSON Forms 2 since the framework will trigger rendering and re-rendering in case of changes to the data or other state. In many cases this means you will be able to streamline your code for custom renderers significantly.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Please see the official JSON Forms website, [jsonforms.io](https://jsonforms.io)
For more info about the seed app, please see the corresponding README file of the [seed repo](https://github.com/eclipsesource/jsonforms-react-seed).
For a more detailed tutorial about the usage of JSON Forms, please see [this tutorial](http://jsonforms.io/docs/tutorial).

## Upgrading to JSON Forms 3.0 Alpha

With version 3.0 of JSON Forms we removed `json-schema-ref-parser` from the core package.
This change only affects users of the React variant (Vue and Angular are not affected) and even for React only a few users will need to adjust their code.
To avoid issues and for more information, please have a look at our [migration guide](https://github.com/eclipsesource/jsonforms/blob/master/MIGRATION.md).

## Feedback, Help and Support

If you encounter any problems feel free to [open an issue](https://github.com/eclipsesource/jsonforms/issues/new/choose) on the repo.
Expand Down