AI Agents & MCPs & AI Workflow Automation • (~400 MCP servers for AI agents) • AI Automation / AI Agent with MCPs • AI Workflows & AI Agents • MCPs for AI Agents
TypeScript ai-agentai-agent-toolsai-agentsai-agents-frameworkmcpmcp-servermcp-toolsmcpsn8n-alternativeno-code-automationworkflowworkflow-automationworkflows
fix(tables): editing a cell no longer erases other columns (#15764)
Hazem Adel6f9ab91013b2
diff --git a/brain/knowledge/data-storage-observability/tables.md b/brain/knowledge/data-storage-observability/tables.mdindex 082103c442e..48c24ff1bc5 100644--- a/brain/knowledge/data-storage-observability/tables.md+++ b/brain/knowledge/data-storage-observability/tables.md@@ -27,6 +27,7 @@ A built-in relational database inside Activepieces: users store structured data- `record.create()` bulk insert caps at 50 per batch, transactional.- When adding any new table/field/record route, the `permission` arg to `securityAccess.project(...)` is required — passing `undefined` silently allows any project member.- The per-create `field.validateCount()` check alone races on bulk paths: all concurrent creates read the same pre-save count and pass. Bulk/import paths (`table.create` with fields, project-state/project-replace apply) MUST call it once up front with the batch size **before** their `Promise.all`.+- The web table store keys each cell by the column's position (`fieldIndex`), not by field id, so every field mutator in `ap-tables-client-state.tsx` has to renumber surviving cells (`deleteField` didn't, see ENG-537). A cell edit sends only the edited cell, and `record.update` upserts just those cells, so stale indexes can't blank other columns on the server.- Concurrent field reorders are last-write-wins, same as rename — no distributed lock. Reordering *existing* fields through project-release apply is not supported: `FieldState` carries no position, so array order only applies to newly created fields.- The web client stores positional `cell.fieldIndex` references, so it must remap every record's cells when fields move.diff --git a/packages/web/src/features/tables/components/cell-context.tsx b/packages/web/src/features/tables/components/cell-context.tsxindex 8e6b98219f5..53d52fbbe41 100644--- a/packages/web/src/features/tables/components/cell-context.tsx+++ b/packages/web/src/features/tables/components/cell-context.tsx@@ -44,11 +44,7 @@ export const CellProvider = ({setIsEditing,disabled,}: CellProviderProps) => {- const [updateRecord, fields, records] = useTableState((state) => [- state.updateRecord,- state.fields,- state.records,- ]);+ const updateRecord = useTableState((state) => state.updateRecord);const focustContainer = () => {// need to refocus container so keyboard navigation between cells works// if it was done immediately, the cell would be blurred and call handleRowChange@@ -58,20 +54,8 @@ export const CellProvider = ({};const handleCellChange = (newCellValue: string) => {- const record = records[rowIdx];- const newRecrodValues = fields.map((_, fIndex) => {- // values order isn't guaranteed to be the same as fields order- const fieldValue = record.values.find(- (value) => value.fieldIndex === fIndex,- )?.value;- return {- fieldIndex: fIndex,- value: fieldValue ?? '',- };- });- newRecrodValues[columnIdx].value = newCellValue;updateRecord(rowIdx, {- values: newRecrodValues,+ values: [{ fieldIndex: columnIdx, value: newCellValue }],});setIsEditing(false);focustContainer();diff --git a/packages/web/src/features/tables/stores/store/ap-tables-client-state.tsx b/packages/web/src/features/tables/stores/store/ap-tables-client-state.tsxindex 8e3eb663fd6..df2ea95c8c5 100644--- a/packages/web/src/features/tables/stores/store/ap-tables-client-state.tsx+++ b/packages/web/src/features/tables/stores/store/ap-tables-client-state.tsx@@ -169,10 +169,23 @@ export const createApTableStore = (recordData: Pick<ClientRecordData, 'values'>,) => {serverState.updateRecord(recordIndex, recordData);+ const updatedFieldIndexes = new Set(+ recordData.values.map((cell) => cell.fieldIndex),+ );return set((state) => {return {records: state.records.map((record, index) =>- index === recordIndex ? { ...record, ...recordData } : record,+ index === recordIndex+ ? {+ ...record,+ values: [+ ...record.values.filter(+ (cell) => !updatedFieldIndexes.has(cell.fieldIndex),+ ),+ ...recordData.values,+ ].sort((a, b) => a.fieldIndex - b.fieldIndex),+ }+ : record,),};});diff --git a/packages/web/test/features/tables/ap-tables-client-state.test.ts b/packages/web/test/features/tables/ap-tables-client-state.test.tsindex dd73cbea1a0..8859faaafea 100644--- a/packages/web/test/features/tables/ap-tables-client-state.test.ts+++ b/packages/web/test/features/tables/ap-tables-client-state.test.ts@@ -1,10 +1,17 @@-import { Table, TableAutomationStatus } from '@activepieces/shared';+import {+ Field,+ FieldType,+ Table,+ TableAutomationStatus,+} from '@activepieces/shared';import { describe, expect, it, vi } from 'vitest';import { createApTableStore } from '@/features/tables/stores/store/ap-tables-client-state';+const serverUpdateRecord = vi.hoisted(() => vi.fn());+vi.mock('@/features/tables/stores/store/ap-tables-server-state', () => ({- createServerState: () => ({}),+ createServerState: () => ({ updateRecord: serverUpdateRecord }),}));const table: Table = {@@ -33,4 +40,50 @@ describe('createApTableStore', () => {expect(listener).toHaveBeenCalledTimes(1);expect(store.getState().selectedCell).toEqual({ rowIdx: 1, columnIdx: 2 });});++ it('saves only the edited cell and keeps the rest of the row', () => {+ const fields = ['a', 'b', 'c'].map(+ (id, position): Field => ({+ id,+ created: table.created,+ updated: table.updated,+ name: id,+ externalId: id,+ type: FieldType.TEXT,+ tableId: table.id,+ projectId: table.projectId,+ position,+ }),+ );+ const cell = (fieldName: string, value: string) => ({+ created: table.created,+ updated: table.updated,+ value,+ fieldName,+ });+ const store = createApTableStore(table, fields, [+ {+ id: 'record-1',+ created: table.created,+ updated: table.updated,+ tableId: table.id,+ projectId: table.projectId,+ cells: {+ c: cell('c', 'c-value'),+ a: cell('a', 'a-value'),+ b: cell('b', 'b-value'),+ },+ },+ ]);++ const edit = { values: [{ fieldIndex: 0, value: 'a-edited' }] };+ store.getState().updateRecord(0, edit);++ expect(serverUpdateRecord).toHaveBeenCalledWith(0, edit);+ expect(store.getState().records[0].values).toEqual([+ { fieldIndex: 0, value: 'a-edited' },+ { fieldIndex: 1, value: 'b-value' },+ { fieldIndex: 2, value: 'c-value' },+ ]);+ });});diff --git a/packages/web/test/features/tables/cell-context.test.tsx b/packages/web/test/features/tables/cell-context.test.tsxnew file mode 100644index 00000000000..590bc475b11--- /dev/null+++ b/packages/web/test/features/tables/cell-context.test.tsx@@ -0,0 +1,47 @@+/** @vitest-environment jsdom */+import { FieldType } from '@activepieces/shared';+import { render } from '@testing-library/react';+import { useEffect } from 'react';+import { describe, expect, it, vi } from 'vitest';++import {+ CellProvider,+ useCellContext,+} from '@/features/tables/components/cell-context';++const updateRecord = vi.hoisted(() => vi.fn());++vi.mock('@/features/tables/components/ap-table-state-provider', () => ({+ useTableState: <T,>(selector: (state: { updateRecord: unknown }) => T) =>+ selector({ updateRecord }),+}));++function CommitEdit({ value }: { value: string }) {+ const { handleCellChange } = useCellContext();+ useEffect(() => handleCellChange(value), [handleCellChange, value]);+ return null;+}++describe('CellProvider', () => {+ it('saves only the edited cell', () => {+ render(+ <CellProvider+ rowIdx={3}+ columnIdx={1}+ fieldType={FieldType.TEXT}+ value="old"+ isEditing={true}+ setIsEditing={() => undefined}+ handleCellChange={() => undefined}+ disabled={false}+ containerRef={{ current: null }}+ >+ <CommitEdit value="new" />+ </CellProvider>,+ );++ expect(updateRecord).toHaveBeenCalledWith(3, {+ values: [{ fieldIndex: 1, value: 'new' }],+ });+ });+});