Merge pull request #1237 from iamanishroy/new-field-subtable-array

Array Subtable bug fixes
This commit is contained in:
Shams
2023-05-04 19:35:35 +02:00
committed by GitHub
2 changed files with 31 additions and 21 deletions

View File

@@ -141,6 +141,34 @@ export default function MenuContents({ onClose }: IMenuContentsProps) {
});
}
};
const handleClearValue = () => {
const clearValue = () => {
updateField({
path: selectedCell.path,
fieldName: selectedColumn.fieldName,
arrayTableData: {
index: selectedCell.arrayIndex,
},
value: null,
deleteField: true,
});
onClose();
};
if (altPress || row._rowy_ref.arrayTableData !== undefined) {
clearValue();
} else {
confirm({
title: "Clear cell value?",
body: "The cells value cannot be recovered after",
confirm: "Delete",
confirmColor: "error",
handleConfirm: clearValue,
});
}
};
const rowActions: IContextMenuItem[] = [
{
label: "Copy ID",
@@ -214,13 +242,7 @@ export default function MenuContents({ onClose }: IMenuContentsProps) {
// Cell actions
// TODO: Add copy and paste here
const cellValue = row?.[selectedCell.columnKey];
const handleClearValue = () =>
updateField({
path: selectedCell.path,
fieldName: selectedColumn.fieldName,
value: null,
deleteField: true,
});
const columnFilters = getFieldProp(
"filter",
selectedColumn?.type === FieldType.derivative
@@ -247,18 +269,7 @@ export default function MenuContents({ onClose }: IMenuContentsProps) {
!row ||
cellValue === undefined ||
getFieldProp("group", selectedColumn?.type) === "Auditing",
onClick: altPress
? handleClearValue
: () => {
confirm({
title: "Clear cell value?",
body: "The cells value cannot be recovered after",
confirm: "Delete",
confirmColor: "error",
handleConfirm: handleClearValue,
});
onClose();
},
onClick: handleClearValue,
},
{
label: "Filter value",

View File

@@ -201,7 +201,7 @@ export function useFirestoreDocAsCollectionWithAtom<T = TableRow>(
useEffect(() => {
if (deleteDocAtom) {
setDeleteRowAtom(() => (_: string, options?: ArrayTableRowData) => {
if (!options || !options.index) return;
if (!options || options.index === undefined) return;
const updateFunction = deleteRow(options.index);
return setRows(updateFunction);
});
@@ -348,7 +348,6 @@ function useAlterArrayTable<T>({
return (rows) => {
if (addTo === "bottom") {
console.log("bottom", newRow(rows.length, false));
rows.push(newRow(rows.length, false));
} else {
rows = [newRow(0, false), ...rows];