Skip to content

Union UISchemaElement type #2436

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

Merged
merged 5 commits into from
Apr 8, 2025
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
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v18.19.0
22
10 changes: 10 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Migration guide

## Migrating to JSON Forms 3.6

### UI schema type changes

The `UISchemaElement` type was renamed to `BaseUISchemaElement` and a new `UISchemaElement` type was introduced, which is a union of all available UI schema types.

The `Condition` type was renamed to `BaseCondition` and a new `Condition` type was introduced, which is a union of all available condition types.

Both unions include their respective base type for backwards compatibility, but if you run into errors, replace `UISchemaElement` with `BaseUISchemaElement`/`Condition` with `BaseCondition` in your code to restore the old behaviour.

## Migrating to JSON Forms 3.5

### Angular support now targets Angular 18 and Angular 19
Expand Down
52 changes: 39 additions & 13 deletions packages/core/src/models/uischema.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
The MIT License

Copyright (c) 2017-2019 EclipseSource Munich
https://github.com/eclipsesource/jsonforms

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Expand Down Expand Up @@ -114,7 +114,7 @@ export enum RuleEffect {
/**
* Represents a condition to be evaluated.
*/
export interface Condition {
export interface BaseCondition {
/**
* The type of condition.
*/
Expand All @@ -124,7 +124,7 @@ export interface Condition {
/**
* A leaf condition.
*/
export interface LeafCondition extends Condition, Scoped {
export interface LeafCondition extends BaseCondition, Scoped {
type: 'LEAF';

/**
Expand All @@ -133,7 +133,7 @@ export interface LeafCondition extends Condition, Scoped {
expectedValue: any;
}

export interface SchemaBasedCondition extends Condition, Scoped {
export interface SchemaBasedCondition extends BaseCondition, Scoped {
schema: JsonSchema;

/**
Expand All @@ -153,7 +153,7 @@ export interface SchemaBasedCondition extends Condition, Scoped {
/**
* A composable condition.
*/
export interface ComposableCondition extends Condition {
export interface ComposableCondition extends BaseCondition {
conditions: Condition[];
}

Expand All @@ -171,10 +171,20 @@ export interface AndCondition extends ComposableCondition {
type: 'AND';
}

/**
* A union of all available conditions.
*/
export type Condition =
| BaseCondition
| LeafCondition
| OrCondition
| AndCondition
| SchemaBasedCondition;

/**
* Common base interface for any UI schema element.
*/
export interface UISchemaElement {
export interface BaseUISchemaElement {
/**
* The type of this UI schema element.
*/
Expand All @@ -195,7 +205,7 @@ export interface UISchemaElement {
* Represents a layout element which can order its children
* in a specific way.
*/
export interface Layout extends UISchemaElement {
export interface Layout extends BaseUISchemaElement {
/**
* The child elements of this layout.
*/
Expand Down Expand Up @@ -241,7 +251,7 @@ export interface LabelDescription {
/**
* A label element.
*/
export interface LabelElement extends UISchemaElement, Internationalizable {
export interface LabelElement extends BaseUISchemaElement, Internationalizable {
type: 'Label';
/**
* The text of label.
Expand All @@ -254,7 +264,7 @@ export interface LabelElement extends UISchemaElement, Internationalizable {
* to which part of the schema the control should be bound.
*/
export interface ControlElement
extends UISchemaElement,
extends BaseUISchemaElement,
Scoped,
Labelable<string | boolean | LabelDescription>,
Internationalizable {
Expand All @@ -274,7 +284,7 @@ export interface Category extends Layout, Labeled, Internationalizable {
* the categorization element can be used to represent recursive structures like trees.
*/
export interface Categorization
extends UISchemaElement,
extends BaseUISchemaElement,
Labeled,
Internationalizable {
type: 'Categorization';
Expand All @@ -284,3 +294,19 @@ export interface Categorization
*/
elements: (Category | Categorization)[];
}

/**
* A union of all available UI schema elements.
* This includes all layout elements, control elements, label elements,
* group elements, category elements and categorization elements.
*/
export type UISchemaElement =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this is nice to see! I created this same thing in jsonforms-antd-renderers, but with a type argument for the literal type of the corresponding jsonschema. Having the schema as a type argument allows us to intersect UISchemaElement with SchemaAwareScope, which traverses the jsonschema (via the type system, not at runtime), to give us autocomplete and type-checking when defining UISchemas, ie for valid scope values, or options configurations.

| BaseUISchemaElement
| ControlElement
| Layout
| LabelElement
| GroupLayout
| Category
| Categorization
| VerticalLayout
| HorizontalLayout;