Skip to content

Commit

Permalink
Rename 'readOnly' to 'readonly'
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
TheZoker authored Aug 21, 2020
1 parent 0595f77 commit 9547b79
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/util/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/util/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
12 changes: 6 additions & 6 deletions packages/core/test/util/cell.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down
24 changes: 12 additions & 12 deletions packages/core/test/util/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand Down Expand Up @@ -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],
Expand All @@ -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],
Expand All @@ -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],
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions packages/react/src/JsonForms.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export interface JsonFormsInitStateProps {
ajv?: AJV.Ajv;
refParserOptions?: RefParser.Options;
config?: any;
readOnly?: boolean;
readonly?: boolean;
validationMode?: ValidationMode;
}

Expand All @@ -237,7 +237,7 @@ export const JsonForms = (
refParserOptions,
onChange,
config,
readOnly,
readonly,
validationMode
} = props;
const schemaToUse = schema !== undefined ? schema : Generate.jsonSchema(data);
Expand All @@ -257,7 +257,7 @@ export const JsonForms = (
config,
renderers,
cells,
readOnly,
readonly,
}}
>
<JsonFormsDispatch onChange={onChange} />
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/JsonFormsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}}
Expand Down

0 comments on commit 9547b79

Please sign in to comment.