Skip to content
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/Form/grid/Element/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const Element = ({ node: el, form }: any) => {
setInlineErrors,
changeValue,
updateFieldValues,
submitCustom,
elementOnView,
onViewElements,
formSettings,
Expand Down Expand Up @@ -94,6 +95,8 @@ const Element = ({ node: el, form }: any) => {
<Elements.TableElement
{...basicProps}
onClick={(payload: any) => tableOnClick(el, payload)}
updateFieldValues={updateFieldValues}
submitCustom={submitCustom}
buttonLoaders={buttonLoaders}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/Form/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2895,6 +2895,7 @@ function Form({
changeStep: (nextStepKey: string) =>
changeFormStep(nextStepKey, activeStep.key, false),
updateFieldValues,
submitCustom: (values: Record<string, any>) => client?.submitCustom(values),
elementOnView,
onViewElements: viewElements,
formSettings,
Expand Down
24 changes: 23 additions & 1 deletion src/elements/basic/TableElement/Actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
actionButtonStyle,
actionMenuStyle,
actionMenuItemStyle,
actionMenuSeparatorStyle,
actionMenuDeleteItemStyle,
actionContainerStyle,
menuIconStyle,
actionIconButtonStyle
Expand All @@ -31,6 +33,8 @@ type ActionButtonsProps = {
forceInlineButtons?: boolean;
tableId?: string;
buttonLoaders?: Record<string, any>;
canDeleteRows?: boolean;
onDeleteRow?: (rowIndex: number) => void;
};

export function ActionButtons({
Expand All @@ -41,7 +45,9 @@ export function ActionButtons({
onClick,
forceInlineButtons = false,
tableId = '',
buttonLoaders = {}
buttonLoaders = {},
canDeleteRows = false,
onDeleteRow
}: ActionButtonsProps) {
if (actions.length === 0) return null;

Expand Down Expand Up @@ -179,6 +185,22 @@ export function ActionButtons({
</button>
);
})}
{canDeleteRows && onDeleteRow && (
<>
<div css={actionMenuSeparatorStyle} />
<button
type='button'
onClick={(e) => {
e.stopPropagation();
setIsMenuOpen(false);
onDeleteRow(rowIndex);
}}
css={actionMenuDeleteItemStyle}
>
Delete
</button>
</>
)}
</div>,
featheryDoc().body
)}
Expand Down
102 changes: 102 additions & 0 deletions src/elements/basic/TableElement/DeleteConfirm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import { useRef, useEffect } from 'react';
import { createPortal } from 'react-dom';
import { featheryDoc } from '../../../utils/browser';
import {
confirmPopoverStyle,
confirmTextStyle,
confirmButtonRowStyle,
confirmDeleteButtonStyle,
confirmCancelButtonStyle
} from './styles';

type DeleteConfirmProps = {
anchorEl: HTMLElement | null;
onConfirm: () => void;
onCancel: () => void;
message?: string;
confirmLabel?: string;
};

export function DeleteConfirm({
anchorEl,
onConfirm,
onCancel,
message = 'Delete this row?',
confirmLabel = 'Delete'
}: DeleteConfirmProps) {
const popoverRef = useRef<HTMLDivElement>(null);

if (!anchorEl) return null;

const anchorRect = anchorEl.getBoundingClientRect();
const top = anchorRect.bottom + 4;
const left = anchorRect.right;

useEffect(() => {
const handleClickOutside = (event: MouseEvent) => {
if (
popoverRef.current &&
!popoverRef.current.contains(event.target as Node) &&
anchorEl &&
!anchorEl.contains(event.target as Node)
) {
onCancel();
}
};

const handleScroll = () => onCancel();
const handleKeyDown = (event: KeyboardEvent) => {
if (event.key === 'Escape') onCancel();
};

const doc = featheryDoc();
doc.addEventListener('mousedown', handleClickOutside);
doc.addEventListener('scroll', handleScroll, true);
doc.addEventListener('keydown', handleKeyDown);

return () => {
doc.removeEventListener('mousedown', handleClickOutside);
doc.removeEventListener('scroll', handleScroll, true);
doc.removeEventListener('keydown', handleKeyDown);
};
}, [onCancel, anchorEl]);

return createPortal(
<div
ref={popoverRef}
role='alertdialog'
aria-label={message}
css={{
...confirmPopoverStyle,
top: `${top}px`,
left: `${left}px`,
transform: 'translateX(-100%)'
}}
>
<p css={confirmTextStyle}>{message}</p>
<div css={confirmButtonRowStyle}>
<button
type='button'
css={confirmCancelButtonStyle}
onClick={(e) => {
e.stopPropagation();
onCancel();
}}
>
Cancel
</button>
<button
type='button'
css={confirmDeleteButtonStyle}
onClick={(e) => {
e.stopPropagation();
onConfirm();
}}
>
{confirmLabel}
</button>
</div>
</div>,
featheryDoc().body
);
}
Loading
Loading