From 9547b79b6788f4503c3758d0c5c906b70e4d7fc5 Mon Sep 17 00:00:00 2001 From: Florian Gareis Date: Fri, 21 Aug 2020 17:33:37 +0200 Subject: [PATCH] Rename 'readOnly' to 'readonly' Since the angular renderers already support an option called readonly, we rename the newly added core and React 'readOnly' attribute to 'readonly' to be consistent throughout the packages. --- packages/core/src/store.ts | 2 +- packages/core/src/util/cell.ts | 4 ++-- packages/core/src/util/renderer.ts | 8 ++++---- packages/core/test/util/cell.test.ts | 12 ++++++------ packages/core/test/util/renderer.test.ts | 24 ++++++++++++------------ packages/react/src/JsonForms.tsx | 6 +++--- packages/react/src/JsonFormsContext.tsx | 2 +- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/packages/core/src/store.ts b/packages/core/src/store.ts index ab1c8101e..4ba7070a6 100644 --- a/packages/core/src/store.ts +++ b/packages/core/src/store.ts @@ -73,7 +73,7 @@ export interface JsonFormsSubStates { /** * If true, sets all controls to read-only. */ - readOnly?: boolean; + readonly?: boolean; // allow additional state [additionalState: string]: any; } diff --git a/packages/core/src/util/cell.ts b/packages/core/src/util/cell.ts index 160380831..5e8b71cee 100644 --- a/packages/core/src/util/cell.ts +++ b/packages/core/src/util/cell.ts @@ -108,9 +108,9 @@ export const mapStateToCellProps = ( ownProps.visible !== undefined ? ownProps.visible : isVisible(uischema, rootData, undefined, getAjv(state)); - const readOnly = state.jsonforms.readOnly; + const readonly = state.jsonforms.readonly; const enabled = - !readOnly && (ownProps.enabled !== undefined + !readonly && (ownProps.enabled !== undefined ? ownProps.enabled : isEnabled(uischema, rootData, undefined, getAjv(state))); const errors = formatErrorMessage( diff --git a/packages/core/src/util/renderer.ts b/packages/core/src/util/renderer.ts index 8e1a902f2..8e0de3ab4 100644 --- a/packages/core/src/util/renderer.ts +++ b/packages/core/src/util/renderer.ts @@ -398,9 +398,9 @@ export const mapStateToControlProps = ( ownProps.visible === undefined || hasShowRule(uischema) ? isVisible(uischema, rootData, ownProps.path, getAjv(state)) : ownProps.visible; - const readOnly = state.jsonforms.readOnly; + const readonly = state.jsonforms.readonly; const enabled: boolean = - !readOnly && (ownProps.enabled === undefined || hasEnableRule(uischema) + !readonly && (ownProps.enabled === undefined || hasEnableRule(uischema) ? isEnabled(uischema, rootData, ownProps.path, getAjv(state) ) : ownProps.enabled); const controlElement = uischema as ControlElement; @@ -708,9 +708,9 @@ export const mapStateToLayoutProps = ( ownProps.visible === undefined || hasShowRule(uischema) ? isVisible(ownProps.uischema, rootData, ownProps.path, getAjv(state)) : ownProps.visible; - const readOnly = state.jsonforms.readOnly; + const readonly = state.jsonforms.readonly; const enabled: boolean = - !readOnly && (ownProps.enabled === undefined || hasEnableRule(uischema) + !readonly && (ownProps.enabled === undefined || hasEnableRule(uischema) ? isEnabled(ownProps.uischema, rootData, ownProps.path, getAjv(state)) : ownProps.enabled); diff --git a/packages/core/test/util/cell.test.ts b/packages/core/test/util/cell.test.ts index 95844eec7..c2d06c9c8 100644 --- a/packages/core/test/util/cell.test.ts +++ b/packages/core/test/util/cell.test.ts @@ -204,30 +204,30 @@ test('mapStateToCellProps - enabled via state ', t => { t.true(props.enabled); }); -test('mapStateToCellProps - disabled via global readOnly', t => { +test('mapStateToCellProps - disabled via global readonly', t => { const ownProps = { uischema: coreUISchema }; const state: JsonFormsState = createState(coreUISchema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToCellProps(state, ownProps); t.false(props.enabled); }); -test('mapStateToCellProps - disabled via global readOnly beats enabled via ownProps', t => { +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; + state.jsonforms.readonly = true; const props = mapStateToCellProps(state, ownProps); t.false(props.enabled); }); -test('mapStateToCellProps - disabled via global readOnly beats enabled via rule', t => { +test('mapStateToCellProps - disabled via global readonly beats enabled via rule', t => { const uischema = { ...coreUISchema, rule: enableRule @@ -236,7 +236,7 @@ test('mapStateToCellProps - disabled via global readOnly beats enabled via rule' uischema }; const state: JsonFormsState = createState(uischema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToCellProps(state, ownProps); t.false(props.enabled); diff --git a/packages/core/test/util/renderer.test.ts b/packages/core/test/util/renderer.test.ts index 0930208a3..9ba38994f 100644 --- a/packages/core/test/util/renderer.test.ts +++ b/packages/core/test/util/renderer.test.ts @@ -192,30 +192,30 @@ test('mapStateToControlProps - visible via state with path from ownProps ', t => t.true(props.visible); }); -test('mapStateToControlProps - disabled via global readOnly', t => { +test('mapStateToControlProps - disabled via global readonly', t => { const ownProps = { uischema: coreUISchema }; const state: JsonFormsState = createState(coreUISchema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToControlProps(state, ownProps); t.false(props.enabled); }); -test('mapStateToControlProps - disabled via global readOnly beats enabled via ownProps', t => { +test('mapStateToControlProps - disabled via global readonly beats enabled via ownProps', t => { const ownProps = { uischema: coreUISchema, enabled: true }; const state: JsonFormsState = createState(coreUISchema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToControlProps(state, ownProps); t.false(props.enabled); }); -test('mapStateToControlProps - disabled via global readOnly beats enabled via rule', t => { +test('mapStateToControlProps - disabled via global readonly beats enabled via rule', t => { const uischema = { ...coreUISchema, rule: enableRule @@ -224,7 +224,7 @@ test('mapStateToControlProps - disabled via global readOnly beats enabled via ru uischema }; const state: JsonFormsState = createState(uischema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToControlProps(state, ownProps); t.false(props.enabled); @@ -711,7 +711,7 @@ test('mapStateToLayoutProps should return renderers prop via ownProps', t => { t.is(props.renderers.length, 1); }); -test('mapStateToLayoutProps - disabled via global readOnly', t => { +test('mapStateToLayoutProps - disabled via global readonly', t => { const uischema = { type: 'VerticalLayout', elements: [coreUISchema], @@ -720,13 +720,13 @@ test('mapStateToLayoutProps - disabled via global readOnly', t => { uischema }; const state: JsonFormsState = createState(uischema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToLayoutProps(state, ownProps); t.false(props.enabled); }); -test('mapStateToLayoutProps - disabled via global readOnly beats enabled via ownProps', t => { +test('mapStateToLayoutProps - disabled via global readonly beats enabled via ownProps', t => { const uischema = { type: 'VerticalLayout', elements: [coreUISchema], @@ -736,13 +736,13 @@ test('mapStateToLayoutProps - disabled via global readOnly beats enabled via own enabled: true }; const state: JsonFormsState = createState(uischema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToLayoutProps(state, ownProps); t.false(props.enabled); }); -test('mapStateToLayoutProps - disabled via global readOnly beats enabled via rule', t => { +test('mapStateToLayoutProps - disabled via global readonly beats enabled via rule', t => { const uischema = { type: 'VerticalLayout', elements: [coreUISchema], @@ -752,7 +752,7 @@ test('mapStateToLayoutProps - disabled via global readOnly beats enabled via rul uischema }; const state: JsonFormsState = createState(uischema); - state.jsonforms.readOnly = true; + state.jsonforms.readonly = true; const props = mapStateToLayoutProps(state, ownProps); t.false(props.enabled); diff --git a/packages/react/src/JsonForms.tsx b/packages/react/src/JsonForms.tsx index 6e3bc96de..d2186367b 100644 --- a/packages/react/src/JsonForms.tsx +++ b/packages/react/src/JsonForms.tsx @@ -220,7 +220,7 @@ export interface JsonFormsInitStateProps { ajv?: AJV.Ajv; refParserOptions?: RefParser.Options; config?: any; - readOnly?: boolean; + readonly?: boolean; validationMode?: ValidationMode; } @@ -237,7 +237,7 @@ export const JsonForms = ( refParserOptions, onChange, config, - readOnly, + readonly, validationMode } = props; const schemaToUse = schema !== undefined ? schema : Generate.jsonSchema(data); @@ -257,7 +257,7 @@ export const JsonForms = ( config, renderers, cells, - readOnly, + readonly, }} > diff --git a/packages/react/src/JsonFormsContext.tsx b/packages/react/src/JsonFormsContext.tsx index b6637caaa..9a854abd1 100644 --- a/packages/react/src/JsonFormsContext.tsx +++ b/packages/react/src/JsonFormsContext.tsx @@ -143,7 +143,7 @@ export const JsonFormsStateProvider = ({ children, initState }: any) => { renderers: initState.renderers, cells: initState.cells, config: config, - readOnly: initState.readOnly, + readonly: initState.readonly, // only core dispatch available dispatch: coreDispatch, }}