ListNode合并自身和相应子结点的action

This commit is contained in:
Xu Chang 2023-04-12 21:21:40 +08:00
parent 57e5635145
commit 710d75357f
4 changed files with 47 additions and 20 deletions

View File

@ -803,11 +803,29 @@ var ListNode = /** @class */ (function (_super) {
operation: (0, lodash_1.cloneDeep)(this.updates[id].operation),
});
}
for (var id in this.children) {
var childOperation = this.children[id].composeOperations();
var _loop_1 = function (id) {
var childOperation = this_1.children[id].composeOperations();
if (childOperation) {
operations.push.apply(operations, tslib_1.__spreadArray([], tslib_1.__read(childOperation), false));
// 现在因为后台有not null检查不能先create再update所以还是得合并成一个
(0, assert_1.assert)(childOperation.length === 1);
var operation = childOperation[0].operation;
var action = operation.action, data = operation.data, filter = operation.filter;
(0, assert_1.assert)(!['create', 'remove'].includes(action), '在list结点上对子结点进行增删请使用父结点的addItem/removeItem不要使用子结点的create/remove');
(0, assert_1.assert)(filter.id === id);
var sameNodeOperation = operations.find(function (ele) { var _a; return ele.operation.action === 'create' && ele.operation.data.id === id || ((_a = ele.operation.filter) === null || _a === void 0 ? void 0 : _a.id) === id; });
if (sameNodeOperation) {
if (sameNodeOperation.operation.action !== 'remove') {
Object.assign(sameNodeOperation.operation.data, data);
}
}
else {
operations.push.apply(operations, tslib_1.__spreadArray([], tslib_1.__read(childOperation), false));
}
}
};
var this_1 = this;
for (var id in this.children) {
_loop_1(id);
}
return operations;
};
@ -1219,7 +1237,6 @@ var SingleNode = /** @class */ (function (_super) {
SingleNode.prototype.composeOperations = function () {
var _a, _b;
if (this.dirty) {
var operations = [];
var operation = this.operation ? (0, lodash_1.cloneDeep)(this.operation.operation) : {
id: (0, uuid_1.generateNewId)(),
action: 'update',
@ -1258,11 +1275,10 @@ var SingleNode = /** @class */ (function (_super) {
}
}
}
operations.push({
entity: this.entity,
operation: operation,
});
return operations;
return [{
entity: this.entity,
operation: operation,
}];
}
};
SingleNode.prototype.getProjection = function (context, withDecendants) {

2
lib/types/Page.d.ts vendored
View File

@ -231,7 +231,7 @@ export declare type OakComponentData<ED extends EntityDict & BaseEntityDict, T e
oakLegalActions?: ED[T]['Action'][];
oakDisablePulldownRefresh: boolean;
};
export declare type OakListComoponetData<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
declare type OakListComoponetData<ED extends EntityDict & BaseEntityDict, T extends keyof ED> = {
oakFilters?: NonNullable<ED[T]['Selection']['filter']>[];
oakSorters?: NonNullable<ED[T]['Selection']['sorter']>[];
oakPagination?: Pagination;

View File

@ -885,7 +885,23 @@ class ListNode<
for (const id in this.children) {
const childOperation = this.children[id].composeOperations();
if (childOperation) {
operations.push(...childOperation);
// 现在因为后台有not null检查不能先create再update所以还是得合并成一个
assert(childOperation.length === 1);
const { operation } = childOperation[0];
const { action, data, filter } = operation;
assert(!['create', 'remove'].includes(action), '在list结点上对子结点进行增删请使用父结点的addItem/removeItem不要使用子结点的create/remove');
assert(filter!.id === id);
const sameNodeOperation = operations.find(
ele => ele.operation.action === 'create' && (ele.operation.data as ED[T]['CreateSingle']['data']).id === id || ele.operation.filter?.id === id
);
if (sameNodeOperation) {
if (sameNodeOperation.operation.action !== 'remove') {
Object.assign(sameNodeOperation.operation.data, data);
}
}
else {
operations.push(...childOperation);
}
}
}
@ -1295,10 +1311,6 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
operation: ED[keyof ED]['Operation'];
}> | undefined {
if (this.dirty) {
const operations = [] as Array<{
entity: keyof ED;
operation: ED[keyof ED]['Operation'];
}>;
const operation: ED[T]['Operation'] = this.operation ? cloneDeep(this.operation.operation) : {
id: generateNewId(),
action: 'update',
@ -1340,11 +1352,10 @@ class SingleNode<ED extends EntityDict & BaseEntityDict,
}
}
}
operations.push({
return [{
entity: this.entity,
operation: operation!,
});
return operations;
operation,
}];
}
}

View File

@ -452,7 +452,7 @@ export type OakComponentData<
oakDisablePulldownRefresh: boolean;
};
export type OakListComoponetData<
type OakListComoponetData<
ED extends EntityDict & BaseEntityDict,
T extends keyof ED
> = {