diff --git a/apps/actors/systems/kvSync/client.ts b/apps/actors/systems/kvSync/client.ts index 67d357c5..3a03c2dc 100644 --- a/apps/actors/systems/kvSync/client.ts +++ b/apps/actors/systems/kvSync/client.ts @@ -70,6 +70,7 @@ export type TransactionState = export type TransactionRecord = { invocation: MutationInvocation; + clientTrace: Trace; state: TransactionState; }; @@ -168,6 +169,7 @@ function runMutationOnClient( console.warn("CLIENT: txn aborted client side:", resVal, trace); const state2 = addTransaction(state1, txnID, { invocation, + clientTrace: trace, state: { type: "Aborted", // TODO: pretty print values @@ -182,6 +184,7 @@ function runMutationOnClient( const state2 = addTransaction(state1, txnID, { invocation, + clientTrace: trace, state: { type: "Pending", sentTime: state.time }, }); @@ -227,6 +230,7 @@ function getNewTransactions(metadata: TransactionMetadata): { return mapObj( metadata, (txnid, metadata): TransactionRecord => ({ + clientTrace: [], state: { type: "Committed", serverTimestamp: metadata.serverTimestamp, diff --git a/apps/actors/systems/kvSync/examples/common/table.tsx b/apps/actors/systems/kvSync/examples/common/table.tsx index a4c1561f..a091c2e0 100644 --- a/apps/actors/systems/kvSync/examples/common/table.tsx +++ b/apps/actors/systems/kvSync/examples/common/table.tsx @@ -9,7 +9,7 @@ type ColumnSpec = { export function Table(props: { data: T[]; columns: ColumnSpec[]; - getKey: (row: T) => string; + getKey: (row: T, idx: number) => string; }) { return ( @@ -41,8 +41,8 @@ export function Table(props: { ) : null} - {props.data.map((row) => ( - + {props.data.map((row, rowIdx) => ( + {props.columns.map((colSpec, colIdx) => (
(null); + return ( - - columns={[ - { name: "ID", render: ([id, txn]) => id }, - { - name: "Invocation", - render: ([id, txn]) => ( - {prettyPrintInvocation(txn.invocation)} - ), - }, - { - name: "Status", - render: ([id, txn]) => , - }, - ]} - data={Object.entries(props.client.state.transactions) - .sort(comparator) - .reverse()} - getKey={([id, txn]) => id} - /> + <> + + columns={[ + { + name: "ID", + render: ([id, txn]) => ( + // TODO: row click + setSelectedTxnID(id)}>{id} + ), + }, + { + name: "Invocation", + render: ([id, txn]) => ( + {prettyPrintInvocation(txn.invocation)} + ), + }, + { + name: "Status", + render: ([id, txn]) => ( + + ), + }, + ]} + data={Object.entries(props.client.state.transactions) + .sort(comparator) + .reverse()} + getKey={([id, txn]) => id} + /> + {selectedTxnID !== null ? ( + <> +
Trace
+ + data={props.client.state.transactions[selectedTxnID].clientTrace} + getKey={(_, idx) => idx.toString()} + columns={[ + { name: "Op", render: (op) => op.type }, + { name: "Key", render: (op) => op.key }, + { + name: "Value", + render: (op) => + op.type === "Write" ? ( + {JSON.stringify(op.value)} + ) : null, + }, + { + name: "TxnID", + render: (op) => + op.type === "Read" ? {op.transactionID} : null, + }, + ]} + /> + + ) : null} + ); } diff --git a/apps/actors/systems/kvSync/types.ts b/apps/actors/systems/kvSync/types.ts index e5e91351..a7308ab9 100644 --- a/apps/actors/systems/kvSync/types.ts +++ b/apps/actors/systems/kvSync/types.ts @@ -32,7 +32,7 @@ export type LiveQueryRequest = { export type Trace = TraceOp[]; -type TraceOp = ReadOp | WriteOp; +export type TraceOp = ReadOp | WriteOp; export type ReadOp = { type: "Read"; key: string; transactionID: string };