Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into add-uischemas
Browse files Browse the repository at this point in the history
  • Loading branch information
sdirix committed Jun 22, 2020
2 parents 8958d25 + 60f2af7 commit 7f994a6
Show file tree
Hide file tree
Showing 35 changed files with 8,634 additions and 9,184 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"packages": [
"packages/*"
],
"version": "2.4.0-beta.0"
"version": "2.4.0"
}
16,983 changes: 7,884 additions & 9,099 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"tslint-loader": "^3.5.4",
"tslint-react": "^4.1.0",
"typedoc": "^0.15.3",
"typescript": "3.6.4",
"typescript": "3.8.3",
"webpack": "^4.41.2",
"webpack-merge": "^4.2.2"
}
Expand Down
14 changes: 7 additions & 7 deletions packages/angular-material/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsonforms/angular-material",
"version": "2.4.0-beta.0",
"version": "2.4.0",
"description": "Material Renderer Set for Angular module of JSON Forms",
"repository": "https://github.com/eclipsesource/jsonforms",
"bugs": "https://github.com/eclipsesource/jsonforms/issues",
Expand Down Expand Up @@ -63,8 +63,8 @@
"@angular/material": "^9.0.0",
"@angular/platform-browser": "^9.0.0",
"@angular/router": "^9.0.0",
"@jsonforms/angular": "^2.3.0",
"@jsonforms/core": "^2.3.0",
"@jsonforms/angular": "^2.4.0",
"@jsonforms/core": "^2.4.0",
"core-js": "^2.5.3",
"rxjs": "^6.4.0",
"zone.js": "^0.10.2"
Expand All @@ -84,10 +84,10 @@
"@angular/platform-browser": "^9.0.0",
"@angular/platform-browser-dynamic": "^9.0.0",
"@angular/router": "^9.0.0",
"@jsonforms/angular": "^2.4.0-beta.0",
"@jsonforms/angular-test": "^2.4.0-beta.0",
"@jsonforms/core": "^2.4.0-beta.0",
"@jsonforms/examples": "^2.4.0-beta.0",
"@jsonforms/angular": "^2.4.0",
"@jsonforms/angular-test": "^2.4.0",
"@jsonforms/core": "^2.4.0",
"@jsonforms/examples": "^2.4.0",
"@types/node": "^10.10.0",
"@types/redux-logger": "3.0.6",
"angular2-template-loader": "^0.6.2",
Expand Down
6 changes: 3 additions & 3 deletions packages/angular-test/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "@jsonforms/angular-test",
"version": "2.4.0-beta.0",
"version": "2.4.0",
"private": true,
"main": "./lib/index.js",
"dependencies": {
"@jsonforms/angular": "^2.4.0-beta.0",
"@jsonforms/core": "^2.4.0-beta.0",
"@jsonforms/angular": "^2.4.0",
"@jsonforms/core": "^2.4.0",
"redux": "^4.0.4"
},
"devDependencies": {
Expand Down
6 changes: 3 additions & 3 deletions packages/angular/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsonforms/angular",
"version": "2.4.0-beta.0",
"version": "2.4.0",
"description": "Angular module of JSON Forms",
"repository": "https://github.com/eclipsesource/jsonforms",
"bugs": "https://github.com/eclipsesource/jsonforms/issues",
Expand Down Expand Up @@ -63,15 +63,15 @@
"peerDependencies": {
"@angular/core": "^9.0.0",
"@angular/forms": "^9.0.0",
"@jsonforms/core": "^2.3.0",
"@jsonforms/core": "^2.4.0",
"rxjs": "^6.4.0"
},
"devDependencies": {
"@angular/compiler": "^9.0.0",
"@angular/compiler-cli": "^9.0.0",
"@angular/core": "^9.0.0",
"@angular/forms": "^9.0.0",
"@jsonforms/core": "^2.4.0-beta.0",
"@jsonforms/core": "^2.4.0",
"copy-webpack-plugin": "^5.0.5",
"rxjs": "^6.4.0",
"webpack-dev-server": "^3.9.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jsonforms/core",
"version": "2.4.0-beta.0",
"version": "2.4.0",
"description": "Core module of JSON Forms",
"repository": "https://github.com/eclipsesource/jsonforms",
"bugs": "https://github.com/eclipsesource/jsonforms/issues",
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@ export interface JsonFormsSubStates {
*/
i18n?: JsonFormsLocaleState;
/**
*
* Ui schema registry, allows to specify detail ui schemas for renderers which support them.
*/
uischemas?: JsonFormsUISchemaRegistryEntry[];
/**
* If true, sets all controls to read-only.
*/
readOnly?: boolean;
// allow additional state
[additionalState: string]: any;
}
Expand Down
13 changes: 13 additions & 0 deletions packages/core/src/testers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,19 @@ export const isEnumControl = and(
)
);

/**
* Tests whether the given UI schema is of type Control and if the schema
* has an enum based on oneOf.
* @type {Tester}
*/
export const isOneOfEnumControl = and(
uiTypeIs('Control'),
schemaMatches(schema =>
schema.hasOwnProperty('oneOf') &&
(schema.oneOf as JsonSchema[]).every(s => s.const !== undefined)
)
);

/**
* Tests whether the given UI schema is of type Control and if the schema
* is of type integer
Expand Down
18 changes: 13 additions & 5 deletions packages/core/src/util/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ import {
Resolve,
StatePropsOfScopedRenderer
} from '.';
import { DispatchPropsOfControl, mapDispatchToControlProps } from './renderer';
import {
DispatchPropsOfControl,
EnumOption,
enumToEnumOptionMapper,
mapDispatchToControlProps,
} from './renderer';
import { JsonFormsState } from '../store';
import { AnyAction, Dispatch } from 'redux';
import { JsonFormsCellRendererRegistryEntry } from '../reducers/cells';
Expand Down Expand Up @@ -103,10 +108,11 @@ export const mapStateToCellProps = (
ownProps.visible !== undefined
? ownProps.visible
: isVisible(uischema, rootData);
const readOnly = state.jsonforms.readOnly;
const enabled =
ownProps.enabled !== undefined
!readOnly && (ownProps.enabled !== undefined
? ownProps.enabled
: isEnabled(uischema, rootData);
: isEnabled(uischema, rootData));
const errors = formatErrorMessage(
union(getErrorAt(path, schema)(state).map(error => error.message))
);
Expand Down Expand Up @@ -156,8 +162,10 @@ export const defaultMapStateToEnumCellProps = (
ownProps: OwnPropsOfEnumCell
): StatePropsOfEnumCell => {
const props: StatePropsOfCell = mapStateToCellProps(state, ownProps);
const options =
ownProps.options !== undefined ? ownProps.options : props.schema.enum;
const options: EnumOption[] =
ownProps.options ||
props.schema.enum?.map(enumToEnumOptionMapper) ||
props.schema.const && [enumToEnumOptionMapper(props.schema.const)];
return {
...props,
options
Expand Down
53 changes: 44 additions & 9 deletions packages/core/src/util/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ export interface WithClassname {
className?: string;
}

export interface EnumOption {
label: string;
value: any;
}

export const enumToEnumOptionMapper = (e: any): EnumOption => {
const stringifiedEnum = typeof e === 'string' ? e : JSON.stringify(e);
return { label: stringifiedEnum, value: e };
};

export interface OwnPropsOfRenderer {
/**
* The UI schema to be rendered.
Expand Down Expand Up @@ -211,7 +221,7 @@ export interface OwnPropsOfControl extends OwnPropsOfRenderer {
}

export interface OwnPropsOfEnum {
options?: any[];
options?: EnumOption[];
}

export interface OwnPropsOfLayout extends OwnPropsOfRenderer {
Expand Down Expand Up @@ -389,10 +399,11 @@ export const mapStateToControlProps = (
ownProps.visible === undefined || hasShowRule(uischema)
? isVisible(uischema, rootData, ownProps.path)
: ownProps.visible;
const readOnly = state.jsonforms.readOnly;
const enabled: boolean =
ownProps.enabled === undefined || hasEnableRule(uischema)
!readOnly && (ownProps.enabled === undefined || hasEnableRule(uischema)
? isEnabled(uischema, rootData, ownProps.path)
: ownProps.enabled;
: ownProps.enabled);
const controlElement = uischema as ControlElement;
const id = ownProps.id;
const rootSchema = getSchema(state);
Expand Down Expand Up @@ -456,10 +467,33 @@ export const mapStateToEnumControlProps = (
ownProps: OwnPropsOfControl & OwnPropsOfEnum
): StatePropsOfControl & OwnPropsOfEnum => {
const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
const options =
ownProps.options !== undefined
? ownProps.options
: props.schema.enum || [props.schema.const];
const options: EnumOption[] =
ownProps.options ||
props.schema.enum?.map(enumToEnumOptionMapper) ||
props.schema.const && [enumToEnumOptionMapper(props.schema.const)];
return {
...props,
options
};
};

/**
* Default mapStateToCellProps for enum control based on oneOf. Options is used for populating dropdown list
* @param state
* @param ownProps
* @returns {StatePropsOfControl & OwnPropsOfEnum}
*/
export const mapStateToOneOfEnumControlProps = (
state: JsonFormsState,
ownProps: OwnPropsOfControl & OwnPropsOfEnum
): StatePropsOfControl & OwnPropsOfEnum => {
const props: StatePropsOfControl = mapStateToControlProps(state, ownProps);
const options: EnumOption[] =
ownProps.options ||
(props.schema.oneOf as JsonSchema[])?.map(e => ({
value: e.const,
label: e.title || (typeof e.const === 'string' ? e.const : JSON.stringify(e.const))
}));
return {
...props,
options
Expand Down Expand Up @@ -675,10 +709,11 @@ export const mapStateToLayoutProps = (
ownProps.visible === undefined || hasShowRule(uischema)
? isVisible(ownProps.uischema, rootData, ownProps.path)
: ownProps.visible;
const readOnly = state.jsonforms.readOnly;
const enabled: boolean =
ownProps.enabled === undefined || hasEnableRule(uischema)
!readOnly && (ownProps.enabled === undefined || hasEnableRule(uischema)
? isEnabled(ownProps.uischema, rootData, ownProps.path)
: ownProps.enabled;
: ownProps.enabled);

const data = Resolve.data(rootData, ownProps.path);

Expand Down
50 changes: 49 additions & 1 deletion packages/core/test/util/cell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
RuleEffect,
UISchemaElement
} from '../../src';
import { enumToEnumOptionMapper } from '../../src/util/renderer';

const middlewares: Redux.Middleware[] = [];
const mockStore = configureStore<JsonFormsState>(middlewares);
Expand All @@ -62,6 +63,15 @@ const disableRule = {
}
};

const enableRule = {
effect: RuleEffect.ENABLE,
condition: {
type: 'LEAF',
scope: '#/properties/firstName',
expectedValue: 'Homer'
}
};

const coreUISchema: ControlElement = {
type: 'Control',
scope: '#/properties/firstName'
Expand Down Expand Up @@ -194,6 +204,44 @@ test('mapStateToCellProps - enabled via state ', t => {
t.true(props.enabled);
});

test('mapStateToCellProps - disabled via global readOnly', t => {
const ownProps = {
uischema: coreUISchema
};
const state: JsonFormsState = createState(coreUISchema);
state.jsonforms.readOnly = true;

const props = mapStateToCellProps(state, ownProps);
t.false(props.enabled);
});

test('mapStateToCellProps - disabled via global readOnly beats enabled via ownProps', t => {
const ownProps = {
uischema: coreUISchema,
enabled: true
};
const state: JsonFormsState = createState(coreUISchema);
state.jsonforms.readOnly = true;

const props = mapStateToCellProps(state, ownProps);
t.false(props.enabled);
});

test('mapStateToCellProps - disabled via global readOnly beats enabled via rule', t => {
const uischema = {
...coreUISchema,
rule: enableRule
};
const ownProps = {
uischema
};
const state: JsonFormsState = createState(uischema);
state.jsonforms.readOnly = true;

const props = mapStateToCellProps(state, ownProps);
t.false(props.enabled);
});

test('mapStateToCellProps - path', t => {
const ownProps = {
uischema: coreUISchema,
Expand Down Expand Up @@ -236,7 +284,7 @@ test('mapStateToEnumCellProps - set default options for dropdown list', t => {
};

const props = defaultMapStateToEnumCellProps(createState(uischema), ownProps);
t.deepEqual(props.options, ['DE', 'IT', 'JP', 'US', 'RU', 'Other']);
t.deepEqual(props.options, ['DE', 'IT', 'JP', 'US', 'RU', 'Other'].map(enumToEnumOptionMapper));
t.is(props.data, undefined);
});

Expand Down
Loading

0 comments on commit 7f994a6

Please sign in to comment.