Skip to content

Commit

Permalink
Rendering checkboxes summary as string, when string is provided (#310)
Browse files Browse the repository at this point in the history
Co-authored-by: Ole Martin Handeland <git@olemartin.org>
  • Loading branch information
olemartinorg and Ole Martin Handeland authored Jul 4, 2022
1 parent 9f10ce5 commit 0ca70bb
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import SummaryBoilerplate from 'src/components/summary/SummaryBoilerplate';
import {
isFileUploadComponent,
isFileUploadWithTagComponent,
isGroupComponent,
isCheckboxesComponent,
} from 'src/utils/formLayout';

export interface ISummaryComponentSwitch {
Expand Down Expand Up @@ -46,67 +48,67 @@ export default function SummaryComponentSwitch({
return null;
}

if (Object.keys(formComponent.dataModelBindings || {}).length === 0) {
if (isFileUploadComponent(formComponent)) {
return (
<>
<SummaryBoilerplate
{...change}
label={label}
hasValidationMessages={hasValidationMessages}
/>
<AttachmentSummaryComponent componentRef={componentRef} />
</>
);
}
if (isFileUploadWithTagComponent(formComponent)) {
return (
<>
<SummaryBoilerplate
{...change}
label={label}
hasValidationMessages={hasValidationMessages}
/>
<AttachmentWithTagSummaryComponent
componentRef={componentRef}
component={formComponent as ISelectionComponentProps}
/>
</>
);
}
}
const hasDataBindings =
Object.keys(formComponent.dataModelBindings || {}).length === 0;

switch (formComponent.type) {
case 'Group':
case 'group': {
return (
<SummaryGroupComponent
{...change}
{...groupProps}
componentRef={componentRef}
/>
);
}
case 'Checkboxes': {
return (
<MultipleChoiceSummary
if (hasDataBindings && isFileUploadComponent(formComponent)) {
return (
<>
<SummaryBoilerplate
{...change}
label={label}
hasValidationMessages={hasValidationMessages}
formData={formData}
readOnlyComponent={(formComponent as ILayoutComponent).readOnly}
/>
);
}
default:
return (
<SingleInputSummary
<AttachmentSummaryComponent componentRef={componentRef} />
</>
);
}

if (hasDataBindings && isFileUploadWithTagComponent(formComponent)) {
return (
<>
<SummaryBoilerplate
{...change}
label={label}
hasValidationMessages={hasValidationMessages}
formData={formData}
readOnlyComponent={(formComponent as ILayoutComponent).readOnly}
/>
);
<AttachmentWithTagSummaryComponent
componentRef={componentRef}
component={formComponent as ISelectionComponentProps}
/>
</>
);
}

if (isGroupComponent(formComponent)) {
return (
<SummaryGroupComponent
{...change}
{...groupProps}
componentRef={componentRef}
/>
);
}

if (isCheckboxesComponent(formComponent) && typeof formData !== 'string') {
return (
<MultipleChoiceSummary
{...change}
label={label}
hasValidationMessages={hasValidationMessages}
formData={formData}
readOnlyComponent={(formComponent as ILayoutComponent).readOnly}
/>
);
}

return (
<SingleInputSummary
{...change}
label={label}
hasValidationMessages={hasValidationMessages}
formData={formData}
readOnlyComponent={(formComponent as ILayoutComponent).readOnly}
/>
);
}
9 changes: 9 additions & 0 deletions src/altinn-app-frontend/src/utils/formLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
ILayoutGroup,
} from '../features/form/layout';
import type { IDatePickerProps } from 'src/components/base/DatepickerComponent';
import type { ICheckboxContainerProps } from 'src/components/base/CheckboxesContainerComponent';

interface SplitKey {
baseComponentId: string;
Expand Down Expand Up @@ -472,3 +473,11 @@ export function isDatePickerComponent(
): component is IDatePickerProps & ILayoutComponent {
return component.type.toLowerCase() === 'datepicker';
}

export function isCheckboxesComponent(
component: any,
): component is ICheckboxContainerProps & ILayoutComponent {
return (
component && component.type && component.type.toLowerCase() === 'checkboxes'
);
}

0 comments on commit 0ca70bb

Please sign in to comment.