Skip to content
Open
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@earthranger/react-native-jsonforms-formatter",
"version": "2.0.0-beta.24",
"version": "2.0.0-beta.25",
"description": "Converts JTD into JSON Schema ",
"main": "./dist/bundle.js",
"types": "./dist/index.d.ts",
Expand Down
4 changes: 2 additions & 2 deletions src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export interface V2Schema {

// Base property interface for nested properties (doesn't require deprecated/title)
export interface V2BaseProperty {
type: 'string' | 'number' | 'array' | 'object';
type: 'boolean' | 'string' | 'number' | 'array' | 'object';
description?: string;
default?: any;
minimum?: number;
Expand All @@ -60,7 +60,7 @@ export interface V2Property extends V2BaseProperty {
}

export interface V2UIField {
type: 'TEXT' | 'NUMERIC' | 'CHOICE_LIST' | 'DATE_TIME' | 'LOCATION' | 'COLLECTION' | 'ATTACHMENT';
type: 'BOOLEAN' | 'TEXT' | 'NUMERIC' | 'CHOICE_LIST' | 'DATE_TIME' | 'LOCATION' | 'COLLECTION' | 'ATTACHMENT';
parent: string;
inputType?: 'SHORT_TEXT' | 'LONG_TEXT' | 'DROPDOWN' | 'LIST';
placeholder?: string;
Expand Down
2 changes: 1 addition & 1 deletion src/v2/generateUISchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { validateConditions } from './conditions';
*/
const validateV2Schema = (schema: V2Schema): void => {
const invalidFields: string[] = [];
const supportedFieldTypes = ['TEXT', 'NUMERIC', 'DATE_TIME', 'CHOICE_LIST', 'LOCATION', 'COLLECTION', 'ATTACHMENT'];
const supportedFieldTypes = ['BOOLEAN', 'TEXT', 'NUMERIC', 'DATE_TIME', 'CHOICE_LIST', 'LOCATION', 'COLLECTION', 'ATTACHMENT'];

// Check each field for validity
Object.entries(schema.json.properties).forEach(([fieldName, property]) => {
Expand Down
4 changes: 4 additions & 0 deletions src/v2/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ export const createControl = (

// Add format based on field type
switch (uiField.type) {
case "BOOLEAN":
control.options!.format = "boolean";
break;

case "TEXT":
if (uiField.inputType === "LONG_TEXT") {
control.options!.multi = true;
Expand Down
74 changes: 74 additions & 0 deletions test/v2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,80 @@ describe('V2 generateUISchema', () => {
});


describe('BOOLEAN field type', () => {
const booleanSchema: V2Schema = {
json: {
$schema: 'https://json-schema.org/draft/2020-12/schema',
additionalProperties: false,
properties: {
requires_medicine: {
deprecated: false,
title: 'Animal Requires Medicine',
default: true,
description: 'Does the veterinarian require medicine for the animal?',
type: 'boolean',
},
},
required: [],
type: 'object',
},
ui: {
fields: {
requires_medicine: {
conditionalDependents: [],
parent: 'section-1',
type: 'BOOLEAN',
},
},
headers: {},
order: ['section-1'],
sections: {
'section-1': {
columns: 1,
conditions: [],
isActive: true,
label: 'Animal Care',
leftColumn: [{ name: 'requires_medicine', type: 'field' }],
rightColumn: [],
},
},
},
};

it('generates a Control with boolean format', () => {
const result = generateUISchema(booleanSchema);
const control = result.elements![0].elements![0];
expect(control).toMatchObject({
type: 'Control',
scope: '#/properties/requires_medicine',
label: 'Animal Requires Medicine',
options: { format: 'boolean' },
});
});

it('includes the description in options', () => {
const result = generateUISchema(booleanSchema);
const control = result.elements![0].elements![0];
expect(control.options!.description).toBe(
'Does the veterinarian require medicine for the animal?',
);
});

it('deprecated boolean field is not rendered', () => {
const schema: V2Schema = {
...booleanSchema,
json: {
...booleanSchema.json,
properties: {
requires_medicine: { ...booleanSchema.json.properties.requires_medicine, deprecated: true },
},
},
};
const result = generateUISchema(schema);
expect(result.elements).toHaveLength(0);
});
});

// Helper function to extract all controls from nested structure
function getAllControls(uiSchema: any): any[] {
const controls: any[] = [];
Expand Down