bpmn-io / form-js

View and visually edit JSON-based forms.
https://bpmn.io/toolkit/form-js/
Other
400 stars 102 forks source link

Playground: propagate import errors #322

Open pinussilvestrus opened 2 years ago

pinussilvestrus commented 2 years ago

Is your feature request related to a problem? Please describe

Currently, when setting a new schema to the form-js-playground, the import warning for the editor/viewer won't be populated.

import { Playground } from '@bpmn-io/form-js-playground';

const playground = new Playground({
  container: document.querySelector('#container'),
  data
});

// this does not catch anything
playground.setSchema(schema);

The reason is that we simply set the schema as the state in the Playground component and ignore any errors and warnings during import in editor/viewer.

As a consumer, I have no chance to check whether an import was successful or not. Check out the following logs when importing a form with errors.

image

Describe the solution you'd like

Make it possible to get import warnings and errors, probably similar to how the editor or viewer is doing it.

try {
  await formEditor.importSchema(schema);
} catch (err) {
  console.log('importing form failed', err);
}

Describe alternatives you've considered

Workaround: Use the editor instead to get proper import errors

try {
  const formEditor = playground.getEditor();
  await formEditor.importSchema(schema);
} catch (err) {
  console.log('importing form failed', err);
}

Additional context

Discovered while working on https://github.com/bpmn-io/internal-docs/issues/527. Related to https://github.com/bpmn-io/form-js/issues/289

pinussilvestrus commented 2 years ago

I added a test case in this branch to reproduce the problem.