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 additional interfaces for Scoped, Labelable and Labeled ui elements. #1935

Merged
merged 19 commits into from
Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
44 changes: 24 additions & 20 deletions packages/core/src/models/uischema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,20 @@ export interface Scopable {
scope: string;
}

/**
* Interface for describing an UI schema element that may be labeled.
*/
export interface Lableable<T = string> {
sdirix marked this conversation as resolved.
Show resolved Hide resolved
label?: string|T;
}

/**
* Interface for describing an UI schema element that is labeled.
*/
export interface Labeled<T = string> extends Lableable<T> {
sdirix marked this conversation as resolved.
Show resolved Hide resolved
label: string|T;
}

/**
* A rule that may be attached to any UI schema element.
*/
Expand Down Expand Up @@ -170,12 +184,8 @@ export interface HorizontalLayout extends Layout {
* A group resembles a vertical layout, but additionally might have a label.
* This layout is useful when grouping different elements by a certain criteria.
*/
export interface GroupLayout extends Layout {
export interface GroupLayout extends Layout, Lableable {
type: 'Group';
/**
* The label of this group layout.
*/
label?: string;
}

/**
Expand Down Expand Up @@ -207,36 +217,24 @@ export interface LabelElement extends UISchemaElement {
* A control element. The scope property of the control determines
* to which part of the schema the control should be bound.
*/
export interface ControlElement extends UISchemaElement, Scopable {
export interface ControlElement extends UISchemaElement, Scopable, Lableable<string | boolean | LabelDescription> {
type: 'Control';
/**
* An optional label that will be associated with the control
*/
label?: string | boolean | LabelDescription;
}

/**
* The category layout.
*/
export interface Category extends Layout {
export interface Category extends Layout, Labeled {
type: 'Category';
/**
* The label associated with this category layout.
*/
label: string;
}

/**
* The categorization element, which may have children elements.
* A child element may either be itself a Categorization or a Category, hence
* the categorization element can be used to represent recursive structures like trees.
*/
export interface Categorization extends UISchemaElement {
export interface Categorization extends UISchemaElement, Labeled {
type: 'Categorization';
/**
* The label of this categorization.
*/
label: string;
/**
* The child elements of this categorization which are either of type
* {@link Category} or {@link Categorization}.
Expand All @@ -249,3 +247,9 @@ export const isGroup = (layout: Layout): layout is GroupLayout =>

export const isLayout = (uischema: UISchemaElement): uischema is Layout =>
(uischema as Layout).elements !== undefined;

sdirix marked this conversation as resolved.
Show resolved Hide resolved
export const isScopeable = (obj: object): obj is Scopable =>
obj !== undefined && obj.hasOwnProperty('scope') && (obj as Scopable).scope !== undefined;

export const isLabeled = (obj: object): obj is Labeled =>
obj !== undefined && obj.hasOwnProperty('label') && (obj as Lableable).label !== undefined;
11 changes: 8 additions & 3 deletions packages/core/src/util/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,15 @@ export { compose as composePaths };
* and de-referencing the single segments to obtain a new object.
*
*
* @param {string} schemaPath the schema path to be converted
* @param {string?} schemaPath the schema path to be converted
* @returns {string[]} an array containing only non-schema-specific segments
*/
export const toDataPathSegments = (schemaPath: string): string[] => {
export const toDataPathSegments = (schemaPath?: string): string[] => {
if (!schemaPath) {
// handle undefined, null and ''
return [];
}
sdirix marked this conversation as resolved.
Show resolved Hide resolved

const s = schemaPath
.replace(/(anyOf|allOf|oneOf)\/[\d]\//g, '')
.replace(/(then|else)\//g, '');
Expand Down Expand Up @@ -99,4 +104,4 @@ export const encode = (segment: string) => segment?.replace(/~/g, '~0').replace(
/**
* Decodes a given JSON Pointer segment to its "normal" representation
*/
export const decode = (pointerSegment: string) => pointerSegment?.replace(/~1/g, '/').replace(/~0/, '~');
export const decode = (pointerSegment: string) => pointerSegment?.replace(/~1/g, '/').replace(/~0/, '~');
2 changes: 1 addition & 1 deletion packages/core/src/util/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import has from 'lodash/has';
import {
AndCondition,
Condition,
JsonSchema,
LeafCondition,
OrCondition,
RuleEffect,
Expand All @@ -39,7 +40,6 @@ import { composeWithUi } from './path';
import Ajv from 'ajv';
import { getAjv } from '../reducers';
import { JsonFormsState } from '../store';
import { JsonSchema } from '../models/jsonSchema';

const isOrCondition = (condition: Condition): condition is OrCondition =>
condition.type === 'OR';
Expand Down