Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: forms checkbox to reflect correct model state #738

Merged
merged 1 commit into from
Nov 3, 2022
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -4431,7 +4431,7 @@ export default function InputGalleryCreateForm(props) {
rootbeer: undefined,
attend: undefined,
maybeSlide: false,
maybeCheck: undefined,
maybeCheck: false,
arrayTypeField: [],
timestamp: undefined,
ippy: undefined,
Expand Down Expand Up @@ -4703,7 +4703,7 @@ export default function InputGalleryCreateForm(props) {
name=\\"maybeCheck\\"
value=\\"maybeCheck\\"
isDisabled={false}
defaultChecked={false}
checked={maybeCheck}
onChange={(e) => {
let value = e.target.checked;
if (onChange) {
Expand Down Expand Up @@ -5149,7 +5149,7 @@ export default function InputGalleryUpdateForm(props) {
rootbeer: undefined,
attend: undefined,
maybeSlide: false,
maybeCheck: undefined,
maybeCheck: false,
arrayTypeField: [],
timestamp: undefined,
ippy: undefined,
Expand Down Expand Up @@ -5461,7 +5461,7 @@ export default function InputGalleryUpdateForm(props) {
name=\\"maybeCheck\\"
value=\\"maybeCheck\\"
isDisabled={false}
defaultChecked={false}
checked={maybeCheck}
defaultValue={maybeCheck}
onChange={(e) => {
let value = e.target.checked;
Expand Down
4 changes: 4 additions & 0 deletions packages/codegen-ui-react/lib/forms/component-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ export const renderValueAttribute = ({
factory.createIdentifier('isChecked'),
factory.createJsxExpression(undefined, valueIdentifier),
),
CheckboxField: factory.createJsxAttribute(
factory.createIdentifier('checked'),
factory.createJsxExpression(undefined, valueIdentifier),
),
};

if (controlledComponentToAttributesMap[componentType]) {
Expand Down
1 change: 1 addition & 0 deletions packages/codegen-ui-react/lib/forms/form-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ export const getDefaultValueExpression = (
SwitchField: factory.createFalse(),
StepperField: factory.createNumericLiteral(0),
SliderField: factory.createNumericLiteral(0),
CheckboxField: factory.createFalse(),
};

// it's a nonModel or relationship object
Expand Down
1 change: 0 additions & 1 deletion packages/codegen-ui-react/lib/workflow/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ const genericEventToReactEventImplementationOverrides: PrimitiveLevelPropConfigu

const PrimitiveDefaultValuePropMapping: PrimitiveLevelPropConfiguration<string> = new Proxy(
{
[Primitive.CheckboxField]: { checked: 'defaultChecked' },
[Primitive.SwitchField]: { isChecked: 'defaultChecked' },
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,13 +469,12 @@ describe('getFormDefinitionInputElement', () => {
const config = {
inputType: {
type: 'CheckboxField',
defaultChecked: true,
},
};

expect(getFormDefinitionInputElement(config)).toStrictEqual({
componentType: 'CheckboxField',
props: { label: 'Label', name: 'fieldName', value: 'fieldName', defaultChecked: true },
props: { label: 'Label', name: 'fieldName', value: 'fieldName' },
cwoolum marked this conversation as resolved.
Show resolved Hide resolved
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,6 @@ export function getFormDefinitionInputElement(
value:
config.inputType?.value || baseConfig?.inputType?.value || FORM_DEFINITION_DEFAULTS.field.inputType.value,
isDisabled: getFirstDefinedValue([config.inputType?.readOnly, baseConfig?.inputType?.readOnly]),
defaultChecked:
getFirstDefinedValue([config.inputType?.defaultChecked, baseConfig?.inputType?.defaultChecked]) || false,
},
};
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export type FormDefinitionToggleButtonElement = {

export type FormDefinitionCheckboxFieldElement = {
componentType: 'CheckboxField';
props: { label: string; value: string; name: string; isDisabled?: boolean; defaultChecked?: boolean };
props: { label: string; value: string; name: string; isDisabled?: boolean };
};

export type FormDefinitionRadioGroupFieldElement = {
Expand Down