Skip to content

Commit

Permalink
Feat/2623 isCompact support for summary2 (#2626)
Browse files Browse the repository at this point in the history
* Added isCompact support
  • Loading branch information
adamhaeger authored Oct 23, 2024
1 parent 663f64a commit 8dcffc0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
5 changes: 4 additions & 1 deletion src/layout/Likert/Summary2/LikertSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export function LikertSummary({ componentNode, emptyFieldText, isCompact }: Like
rowNode={row?.itemNode}
emptyFieldText={emptyFieldText}
readOnly={readOnly}
isCompact={isCompact}
/>
))}
{errors?.map(({ message }) => (
Expand All @@ -82,9 +83,10 @@ type LikertRowSummaryProps = {
rowNode?: LayoutNode<'LikertItem'>;
emptyFieldText?: string;
readOnly?: boolean;
isCompact?: boolean;
};

function LikertRowSummary({ rowNode, emptyFieldText, readOnly }: LikertRowSummaryProps) {
function LikertRowSummary({ rowNode, emptyFieldText, readOnly, isCompact }: LikertRowSummaryProps) {
const title = useNodeItem(rowNode, (i) => i.textResourceBindings?.title);
const displayData = rowNode?.def.useDisplayData(rowNode);
const validations = useUnifiedValidationsForNode(rowNode);
Expand All @@ -102,6 +104,7 @@ function LikertRowSummary({ rowNode, emptyFieldText, readOnly }: LikertRowSummar
node={rowNode}
/>
}
isCompact={isCompact}
componentNode={rowNode}
displayData={displayData}
errors={errors}
Expand Down
4 changes: 2 additions & 2 deletions src/layout/Summary2/SummaryComponent2/ComponentSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ interface ComponentSummaryProps {
interface ResolveComponentProps {
targetId: string;
}
export function ComponentSummary({ componentNode, isCompact }: ComponentSummaryProps) {
export function ComponentSummary({ componentNode }: ComponentSummaryProps) {
const summaryNodeItem = useSummary2Store((state) => state.summaryItem);
const componentNodeItem = useNodeItem(componentNode);

Expand All @@ -37,7 +37,7 @@ export function ComponentSummary({ componentNode, isCompact }: ComponentSummaryP
? componentNode.def.renderSummary2({
target: componentNode as LayoutNode<never>,
override,
isCompact,
isCompact: summaryNodeItem.isCompact,
})
: null;

Expand Down
22 changes: 20 additions & 2 deletions src/layout/Summary2/SummaryComponent2/SummaryComponent2.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('SummaryComponent', () => {
},
},
});
//

test('should render Group', async () => {
await render({
summary2Config: {
Expand All @@ -48,6 +48,23 @@ describe('SummaryComponent', () => {
expect(screen.getByTestId('summary-group-component')).toBeInTheDocument();
});

test('Should render in compact mode when set', async () => {
await render({
summary2Config: {
type: 'Summary2',
id: 'Summary2',
isCompact: true,
hideEmptyFields: false,
},
});
const elements = screen.getAllByTestId('summary-single-value-component');
expect(elements.length).toBeGreaterThan(0);
elements.forEach((element) => {
const labelElement = element.querySelector('.compact');
expect(labelElement).toBeInTheDocument();
});
});

test('should render component if hideEmptyFields is set to false', async () => {
await render({
summary2Config: {
Expand All @@ -60,7 +77,7 @@ describe('SummaryComponent', () => {
},
},
});
// expect(screen.getByTestId('summary-single-value-component'));

expect(screen.getByTestId('summary-single-value-component')).toBeInTheDocument();
});

Expand Down Expand Up @@ -460,6 +477,7 @@ describe('SummaryComponent', () => {
type: 'Summary2',
id: 'mySummary2',
hideEmptyFields: summary2Config.hideEmptyFields,
isCompact: summary2Config.isCompact,
target: {
id: summary2Config.target?.id || '',
type: summary2Config.target?.type,
Expand Down
1 change: 1 addition & 0 deletions src/layout/Summary2/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export const Config = new CG.component({
),
)
.addProperty(new CG.prop('showPageInAccordion', new CG.bool().optional()))
.addProperty(new CG.prop('isCompact', new CG.bool().optional()))
.addProperty(
new CG.prop(
'hideEmptyFields',
Expand Down

0 comments on commit 8dcffc0

Please sign in to comment.