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

Add summary2 for "Custom" component #2840

Merged
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
3 changes: 3 additions & 0 deletions src/layout/Custom/CustomWebComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import type { CompInternal, ITextResourceBindings } from 'src/layout/layout';

export type ICustomComponentProps = PropsFromGenericComponent<'Custom'> & {
[key: string]: string | number | boolean | object | null | undefined;
summaryMode?: boolean;
};

export type IPassedOnProps = Omit<PropsFromGenericComponent<'Custom'>, 'node' | 'componentValidations'> &
Expand All @@ -24,6 +25,7 @@ export type IPassedOnProps = Omit<PropsFromGenericComponent<'Custom'>, 'node' |
export function CustomWebComponent({
node,
componentValidations,
summaryMode = false,
...passThroughPropsFromGenericComponent
}: ICustomComponentProps) {
const langTools = useLanguage();
Expand All @@ -34,6 +36,7 @@ export function CustomWebComponent({
...passThroughPropsFromNode,
text: langAsString(textResourceBindings?.title),
getTextResourceAsString: (textResource: string) => langAsString(textResource),
summaryMode,
};
const HtmlTag = tagName;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
14 changes: 14 additions & 0 deletions src/layout/Custom/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import type { JSX } from 'react';
import { CustomDef } from 'src/layout/Custom/config.def.generated';
import { CustomWebComponent } from 'src/layout/Custom/CustomWebComponent';
import { SummaryItemSimple } from 'src/layout/Summary/SummaryItemSimple';
import { useNodeFormData } from 'src/utils/layout/useNodeItem';
import type { DisplayDataProps } from 'src/features/displayData';
import type { PropsFromGenericComponent } from 'src/layout';
import type { SummaryRendererProps } from 'src/layout/LayoutComponent';
import type { Summary2Props } from 'src/layout/Summary2/SummaryComponent2/types';
import type { LayoutNode } from 'src/utils/layout/LayoutNode';

export class Custom extends CustomDef {
Expand All @@ -26,6 +28,18 @@ export class Custom extends CustomDef {
return <SummaryItemSimple formDataAsString={displayData} />;
}

renderSummary2(props: Summary2Props<'Custom'>): JSX.Element | null {
const formData = useNodeFormData(props.target);
return (
<CustomWebComponent
summaryMode={true}
formData={formData}
node={props.target}
containerDivRef={React.createRef()}
/>
);
}

validateDataModelBindings(): string[] {
return [];
}
Expand Down
5 changes: 4 additions & 1 deletion src/layout/Grid/GridSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { GenericComponent } from 'src/layout/GenericComponent';
import classes from 'src/layout/Grid/GridSummary.module.css';
import { isGridRowHidden } from 'src/layout/Grid/tools';
import { EditButton } from 'src/layout/Summary2/CommonSummaryComponents/EditButton';
import { ComponentSummary } from 'src/layout/Summary2/SummaryComponent2/ComponentSummary';
import { getColumnStyles } from 'src/utils/formComponentUtils';
import { Hidden, useNode } from 'src/utils/layout/NodesContext';
import { useNodeItem } from 'src/utils/layout/useNodeItem';
Expand Down Expand Up @@ -431,7 +432,9 @@ function getComponentCellData(
displayDataProps: DisplayDataProps,
textResourceBindings?: ITextResourceBindings,
) {
if (node && 'getDisplayData' in node.def) {
if (node?.type === 'Custom') {
return <ComponentSummary componentNode={node} />;
} else if (node && 'getDisplayData' in node.def && node.type) {
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
return node.def.getDisplayData(node as LayoutNode<any>, displayDataProps) || '-';
} else if (textResourceBindings && 'title' in textResourceBindings) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { RepeatingGroupTableTitle, useTableTitle } from 'src/layout/RepeatingGro
import { useTableNodes } from 'src/layout/RepeatingGroup/useTableNodes';
import { EditButton } from 'src/layout/Summary2/CommonSummaryComponents/EditButton';
import { SingleValueSummary } from 'src/layout/Summary2/CommonSummaryComponents/SingleValueSummary';
import { ComponentSummary } from 'src/layout/Summary2/SummaryComponent2/ComponentSummary';
import { useColumnStylesRepeatingGroups } from 'src/utils/formComponentUtils';
import { useNodeItem } from 'src/utils/layout/useNodeItem';
import type { ITableColumnFormatting } from 'src/layout/common.generated';
Expand Down Expand Up @@ -141,14 +142,22 @@ function DataRow({ row, node, index, pdfModeActive, columnSettings }: DataRowPro

return (
<Table.Row>
{cellNodes.map((node) => (
<DataCell
key={node.id}
node={node}
displayData={('getDisplayData' in node.def && node.def.getDisplayData(node as never, displayDataProps)) ?? ''}
columnSettings={columnSettings}
/>
))}
{cellNodes.map((node) =>
node.type === 'Custom' ? (
<Table.Cell key={node.id}>
<ComponentSummary componentNode={node} />
</Table.Cell>
) : (
<DataCell
key={node.id}
node={node}
displayData={
('getDisplayData' in node.def && node.def.getDisplayData(node as never, displayDataProps)) ?? ''
}
columnSettings={columnSettings}
/>
),
)}
{!pdfModeActive && (
<Table.Cell
align='right'
Expand Down
Loading