@vuu-ui/vuu-data-editing 3.5.9 → 3.5.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/package.json +6 -6
- package/src/EditSession.js +38 -21
- package/types/EditSession.d.ts +3 -0
- package/types/index.d.ts +1 -1
package/README.md
CHANGED
|
@@ -162,7 +162,10 @@ A cell is considered edited only when `originalValue !== editedValue && isValid
|
|
|
162
162
|
- Exits early if `selectedRowsCount === 0`.
|
|
163
163
|
- Calls `dataSource.deleteSelectedRows(deleteMode)`.
|
|
164
164
|
- On success:
|
|
165
|
-
-
|
|
165
|
+
- If the server returns `response.data.deletedKeys`, keys are partitioned against `#addedRowKeys`:
|
|
166
|
+
- Deleting a newly added row cancels out the addition (`addCount` decrements, key removed from `#addedRowKeys`, any cell edits on that row are discarded, and `deleteCount` remains unaffected).
|
|
167
|
+
- Deleting an existing source row increments `deleteCount`.
|
|
168
|
+
- Fallback: if `deletedKeys` is not returned, increments `deleteCount` by `selectedRowsCount`.
|
|
166
169
|
- **Clears selection**: Dispatches `dataSource.select({ type: "DESELECT_ALL" })` so deleted rows are immediately deselected, preventing accidental double-deletion and disabling the Delete button.
|
|
167
170
|
|
|
168
171
|
### Undo Flow (`undoRowChange`)
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "3.5.
|
|
2
|
+
"version": "3.5.11",
|
|
3
3
|
"description": "Shared data editing APIs and React components for VUU UI",
|
|
4
4
|
"main": "./src/index.js",
|
|
5
5
|
"author": "heswell",
|
|
@@ -12,13 +12,13 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@salt-ds/core": "1.54.1",
|
|
15
|
-
"@vuu-ui/vuu-ui-controls": "3.5.
|
|
16
|
-
"@vuu-ui/vuu-utils": "3.5.
|
|
15
|
+
"@vuu-ui/vuu-ui-controls": "3.5.11",
|
|
16
|
+
"@vuu-ui/vuu-utils": "3.5.11"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
|
-
"@vuu-ui/vuu-data-types": "3.5.
|
|
20
|
-
"@vuu-ui/vuu-protocol-types": "3.5.
|
|
21
|
-
"@vuu-ui/vuu-table-types": "3.5.
|
|
19
|
+
"@vuu-ui/vuu-data-types": "3.5.11",
|
|
20
|
+
"@vuu-ui/vuu-protocol-types": "3.5.11",
|
|
21
|
+
"@vuu-ui/vuu-table-types": "3.5.11"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"react": "^19.2.3"
|
package/src/EditSession.js
CHANGED
|
@@ -241,10 +241,24 @@ class EditSession extends EventEmitter {
|
|
|
241
241
|
data: void 0,
|
|
242
242
|
type: "SUCCESS_RESULT"
|
|
243
243
|
};
|
|
244
|
+
const deleteRevision = this.#commitRevision;
|
|
244
245
|
const response = await deleteSelectedRows.call(this.dataSource, this.#deleteMode);
|
|
245
246
|
if (void 0 === response) throw Error("[EditSession] datasource returned no response when deleting rows");
|
|
246
247
|
if (isRpcError(response)) return response;
|
|
247
|
-
|
|
248
|
+
const deletedKeys = response.data?.deletedKeys;
|
|
249
|
+
if (deletedKeys && deletedKeys.length > 0) {
|
|
250
|
+
const oldState = this.editState;
|
|
251
|
+
let addedRowsDeleted = 0;
|
|
252
|
+
for (const key of deletedKeys)if (this.#addedRowKeys.has(key)) {
|
|
253
|
+
this.#addedRowKeys.delete(key);
|
|
254
|
+
this.#discardRowEdits(key, deleteRevision);
|
|
255
|
+
addedRowsDeleted++;
|
|
256
|
+
}
|
|
257
|
+
const sourceRowsDeleted = deletedKeys.length - addedRowsDeleted;
|
|
258
|
+
if (sourceRowsDeleted > 0) this.#deleteCount += sourceRowsDeleted;
|
|
259
|
+
if (addedRowsDeleted > 0) this.#addCount = Math.max(0, this.#addCount - addedRowsDeleted);
|
|
260
|
+
this.#emitEditStateChange(oldState);
|
|
261
|
+
} else if (selectedRowsCount > 0) this.#setDeleteCount(this.#deleteCount + selectedRowsCount);
|
|
248
262
|
await this.dataSource?.select?.({
|
|
249
263
|
type: "DESELECT_ALL"
|
|
250
264
|
});
|
|
@@ -272,6 +286,28 @@ class EditSession extends EventEmitter {
|
|
|
272
286
|
const cellEdit = this.#rowEdits.get(key)?.cellEdits.get(columnName);
|
|
273
287
|
return cellEdit?.isValid === true && cellEdit.originalValue !== cellEdit.editedValue;
|
|
274
288
|
}
|
|
289
|
+
#discardRowEdits(key, maxRevision, columnsToDiscard) {
|
|
290
|
+
const rowEdits = this.#rowEdits.get(key);
|
|
291
|
+
if (!rowEdits) return;
|
|
292
|
+
const columns = columnsToDiscard ?? new Set(rowEdits.cellEdits.keys());
|
|
293
|
+
const changedColumns = [];
|
|
294
|
+
let removedValidCount = 0;
|
|
295
|
+
let removedInvalidCount = 0;
|
|
296
|
+
for (const columnName of columns){
|
|
297
|
+
const latestRevision = this.#cellCommitRevisions.get(key)?.get(columnName) ?? 0;
|
|
298
|
+
if (latestRevision > maxRevision) continue;
|
|
299
|
+
const existing = rowEdits.cellEdits.get(columnName);
|
|
300
|
+
if (existing) if (existing.isValid) removedValidCount++;
|
|
301
|
+
else removedInvalidCount++;
|
|
302
|
+
if (this.isCellEdited(key, columnName)) changedColumns.push(columnName);
|
|
303
|
+
rowEdits.cellEdits.delete(columnName);
|
|
304
|
+
this.#setCellCommitRevision(key, columnName);
|
|
305
|
+
}
|
|
306
|
+
if (0 === rowEdits.cellEdits.size) this.#rowEdits.delete(key);
|
|
307
|
+
this.#editCount -= removedValidCount;
|
|
308
|
+
this.#invalidCount -= removedInvalidCount;
|
|
309
|
+
for (const columnName of changedColumns)this.emit("cellEditChanged", key, columnName);
|
|
310
|
+
}
|
|
275
311
|
async undoRowChange(key, action) {
|
|
276
312
|
if (!this.inEditMode) return;
|
|
277
313
|
const undoRevision = this.#commitRevision;
|
|
@@ -281,26 +317,7 @@ class EditSession extends EventEmitter {
|
|
|
281
317
|
if (void 0 === response) return;
|
|
282
318
|
if (isRpcError(response)) return response;
|
|
283
319
|
const oldState = this.editState;
|
|
284
|
-
|
|
285
|
-
if (rowEdits) {
|
|
286
|
-
const changedColumns = [];
|
|
287
|
-
let removedValidCount = 0;
|
|
288
|
-
let removedInvalidCount = 0;
|
|
289
|
-
for (const columnName of columnsAtRequest){
|
|
290
|
-
const latestRevision = this.#cellCommitRevisions.get(key)?.get(columnName) ?? 0;
|
|
291
|
-
if (latestRevision > undoRevision) continue;
|
|
292
|
-
const existing = rowEdits.cellEdits.get(columnName);
|
|
293
|
-
if (existing) if (existing.isValid) removedValidCount++;
|
|
294
|
-
else removedInvalidCount++;
|
|
295
|
-
if (this.isCellEdited(key, columnName)) changedColumns.push(columnName);
|
|
296
|
-
rowEdits.cellEdits.delete(columnName);
|
|
297
|
-
this.#setCellCommitRevision(key, columnName);
|
|
298
|
-
}
|
|
299
|
-
if (0 === rowEdits.cellEdits.size) this.#rowEdits.delete(key);
|
|
300
|
-
this.#editCount -= removedValidCount;
|
|
301
|
-
this.#invalidCount -= removedInvalidCount;
|
|
302
|
-
for (const columnName of changedColumns)this.emit("cellEditChanged", key, columnName);
|
|
303
|
-
}
|
|
320
|
+
this.#discardRowEdits(key, undoRevision, columnsAtRequest);
|
|
304
321
|
if ("deleteRow" === action) this.#deleteCount = Math.max(0, this.#deleteCount - 1);
|
|
305
322
|
const wasInsertedRow = "addRow" === action || this.#addedRowKeys.has(key);
|
|
306
323
|
if (wasInsertedRow) {
|
package/types/EditSession.d.ts
CHANGED
|
@@ -24,6 +24,9 @@ export type EditSessionConstructorProps = {
|
|
|
24
24
|
export type AddRowResultData = {
|
|
25
25
|
key?: string | number;
|
|
26
26
|
};
|
|
27
|
+
export type DeleteSelectedRowsResultData = {
|
|
28
|
+
deletedKeys?: string[];
|
|
29
|
+
};
|
|
27
30
|
export type NewRowState = {
|
|
28
31
|
columns: readonly string[];
|
|
29
32
|
requiredColumns?: readonly string[];
|
package/types/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { EditButtons, type EditButtonProps } from "./EditButtons";
|
|
|
8
8
|
export { EditField, type DropdownEditFieldProps, type EditFieldProps, type EditFieldType, type TextFieldType, } from "./edit-field/EditField";
|
|
9
9
|
export { useEditField, type EditFieldHookProps, } from "./edit-field/useEditField";
|
|
10
10
|
export { EditModeProvider, useEditMode, type EditModeContextProps, } from "./EditModeProvider";
|
|
11
|
-
export { EditError, EditSession, SupersededEditError, type AddRowResultData, type EditActionType, type EditCommitOptions, type EditLifecycle, type EditSessionConstructorProps, type EditSessionValue, type NewRowState, type EditState, type RowDefaultDataItemValues, } from "./EditSession";
|
|
11
|
+
export { EditError, EditSession, SupersededEditError, type AddRowResultData, type DeleteSelectedRowsResultData, type EditActionType, type EditCommitOptions, type EditLifecycle, type EditSessionConstructorProps, type EditSessionValue, type NewRowState, type EditState, type RowDefaultDataItemValues, } from "./EditSession";
|
|
12
12
|
export { StaleUpdateError } from "@vuu-ui/vuu-utils";
|
|
13
13
|
export { lookupOptionsFromRows, useLookupValues, type LookupOption, type LookupValuedHookProps, type OptionMap, } from "./lookup-values/useLookupValues";
|
|
14
14
|
export { useEditable, type EditableHookProps } from "./useEditable";
|