Skip to content
Merged
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 @@ -15,6 +15,7 @@ interface FieldGroupTemplateProps extends PConnProps {
displayMode?: string;
fieldHeader?: string;
allowTableEdit: boolean;
allowActions?: any;
}

export default function FieldGroupTemplate(props: FieldGroupTemplateProps) {
Expand All @@ -31,6 +32,7 @@ export default function FieldGroupTemplate(props: FieldGroupTemplateProps) {
heading = '',
displayMode,
fieldHeader,
allowActions,
allowTableEdit: allowAddEdit
} = props;
const pConn = getPConnect();
Expand All @@ -40,6 +42,11 @@ export default function FieldGroupTemplate(props: FieldGroupTemplateProps) {
const isReadonlyMode = renderMode === 'ReadOnly' || displayMode === 'DISPLAY_ONLY';
const HEADING = heading ?? 'Row';

const hasAllowActions = Object.keys(allowActions ?? {}).length > 0;
const { allowAdd: actionAdd, allowDelete: actionDelete } = allowActions ?? {};
const allowAdd = hasAllowActions ? (actionAdd ?? true) : (allowAddEdit ?? true);
const allowDelete = hasAllowActions ? (actionDelete ?? true) : (allowAddEdit ?? true);

useLayoutEffect(() => {
if (!isReadonlyMode) {
// @ts-ignore - Expected 3 arguments, but got 1
Expand Down Expand Up @@ -73,7 +80,7 @@ export default function FieldGroupTemplate(props: FieldGroupTemplateProps) {
pConn.getListActions().deleteEntry(index);
}
};
if (referenceList.length === 0 && allowAddEdit !== false) {
if (referenceList.length === 0 && allowAdd) {
addFieldGroupItem();
}

Expand All @@ -88,8 +95,8 @@ export default function FieldGroupTemplate(props: FieldGroupTemplateProps) {
return (
<FieldGroupList
items={MemoisedChildren}
onAdd={allowAddEdit !== false ? addFieldGroupItem : undefined}
onDelete={allowAddEdit !== false ? deleteFieldGroupItem : undefined}
onAdd={allowAdd ? addFieldGroupItem : undefined}
onDelete={allowDelete ? deleteFieldGroupItem : undefined}
/>
);
}
Expand Down
Loading