Skip to content

Commit

Permalink
feat: give ui schema types better names (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
DrewHoo authored Mar 19, 2024
1 parent 37551ee commit a10d32b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/layouts/HorizontalLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LayoutProps, GroupLayout } from "@jsonforms/core"
import isEmpty from "lodash.isempty"
import { AntDLayout, AntDLayoutProps } from "./LayoutRenderer"
import { HorizontalLayout as HorizontalLayoutUISchema } from "../ui-schema"
import { HorizontalLayoutUISchema } from "../ui-schema"
import { Form, Row } from "antd"
import { withJsonFormsLayoutProps } from "@jsonforms/react"

Expand Down
2 changes: 1 addition & 1 deletion src/layouts/VerticalLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LayoutProps, GroupLayout } from "@jsonforms/core"
import { AntDLayout, AntDLayoutProps } from "./LayoutRenderer"
import { Form, FormInstance, FormProps } from "antd"
import { VerticalLayout as VerticalLayoutUISchema } from "../ui-schema"
import { VerticalLayoutUISchema } from "../ui-schema"
import { withJsonFormsLayoutProps } from "@jsonforms/react"

export function VerticalLayout({
Expand Down
47 changes: 29 additions & 18 deletions src/ui-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import type { RuleObject as AntDRule } from "antd/es/form"

export type UISchema =
| UISchemaElement
| Layout
| VerticalLayout
| HorizontalLayout
| LabelElement
| GroupLayout
| ControlElement
| Categorization
| Category
| LayoutUISchema
| VerticalLayoutUISchema
| HorizontalLayoutUISchema
| LabelLayoutUISchema
| GroupLayoutUISchema
| ControlUISchema
| CategorizationUISchema
| CategoryUISchema

/**
* Interface for describing an UI schema element that is referencing
Expand Down Expand Up @@ -77,7 +77,7 @@ interface UISchemaElement<TOptions = { [key: string]: unknown }> {
* Represents a layout element which can order its children
* in a specific way.
*/
interface Layout extends UISchemaElement {
interface LayoutUISchema extends UISchemaElement {
/**
* The child elements of this layout.
*/
Expand All @@ -86,20 +86,23 @@ interface Layout extends UISchemaElement {
/**
* A layout which orders its child elements vertically (i.e. from top to bottom).
*/
export interface VerticalLayout extends Layout {
export interface VerticalLayoutUISchema extends LayoutUISchema {
type: "VerticalLayout"
}
/**
* A layout which orders its children horizontally (i.e. from left to right).
*/
export interface HorizontalLayout extends Layout {
export interface HorizontalLayoutUISchema extends LayoutUISchema {
type: "HorizontalLayout"
}
/**
* A group resembles a vertical layout, but additionally might have a label.
* This layout is useful when grouping different elements by a certain criteria.
*/
interface GroupLayout extends Layout, Labelable, Internationalizable {
interface GroupLayoutUISchema
extends LayoutUISchema,
Labelable,
Internationalizable {
type: "Group"
}
/**
Expand All @@ -118,7 +121,9 @@ interface LabelDescription {
/**
* A label element.
*/
export interface LabelElement extends UISchemaElement, Internationalizable {
export interface LabelLayoutUISchema
extends UISchemaElement,
Internationalizable {
type: "Label"
/**
* The text of label.
Expand Down Expand Up @@ -173,7 +178,7 @@ type ControlOptions =
* A control element. The scope property of the control determines
* to which part of the schema the control should be bound.
*/
export interface ControlElement
export interface ControlUISchema
extends UISchemaElement<ControlOptions>,
Scoped,
Labelable<string | boolean | LabelDescription>,
Expand All @@ -183,21 +188,27 @@ export interface ControlElement
/**
* The category layout.
*/
interface Category extends Layout, Labeled, Internationalizable {
interface CategoryUISchema
extends LayoutUISchema,
Labeled,
Internationalizable {
type: "Category"
}
/**
* 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.
*/
interface Categorization extends UISchemaElement, Labeled, Internationalizable {
interface CategorizationUISchema
extends UISchemaElement,
Labeled,
Internationalizable {
type: "Categorization"
/**
* The child elements of this categorization which are either of type
* {@link Category} or {@link Categorization}.
* {@link CategoryUISchema} or {@link CategorizationUISchema}.
*/
elements: (Category | Categorization)[]
elements: (CategoryUISchema | CategorizationUISchema)[]
}

/**
Expand Down

0 comments on commit a10d32b

Please sign in to comment.