Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: missing update history in DataManger #1919

Merged
merged 3 commits into from
May 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import {
ModifiedDataMap,
ModificationTypeCode,
ModifiedRowsOptions,
ModifiedDataManager,
ModifiedDataMap,
ModifiedRows,
RequestTypeCode,
ModifiedRowsOptions,
MutationParams,
RequestTypeCode,
} from '@t/dataSource';
import { OptRow } from '@t/options';
import { Row, RowKey } from '@t/store/data';
import {
someProp,
findIndex,
isUndefined,
omit,
isObject,
forEachObject,
isEmpty,
isObject,
isUndefined,
last,
omit,
someProp,
} from '../../helper/common';
import { getOriginObject, Observable } from '../../helper/observable';
import { getOmittedInternalProp, changeRawDataToOriginDataForTree } from '../../query/data';
import { changeRawDataToOriginDataForTree, getOmittedInternalProp } from '../../query/data';

type ParamNameMap = { [type in ModificationTypeCode]: string };

Expand Down Expand Up @@ -85,10 +85,14 @@ export function createManager(): ModifiedDataManager {
return acc;
}

const lastContinuousRowIndices = !acc ? acc : last(acc);
const lastRowIndex = !lastContinuousRowIndices ? -1 : last(lastContinuousRowIndices);
const lastContinuousRowIndices = last(acc) ?? [];
const lastRowIndex = last(lastContinuousRowIndices)?.rowIndex;

if (isUndefined(lastContinuousRowIndices) || rowIndex - lastRowIndex !== 1) {
if (
isUndefined(lastContinuousRowIndices) ||
isUndefined(lastRowIndex) ||
rowIndex - lastRowIndex !== 1
) {
acc.push([indexedRow]);
} else {
lastContinuousRowIndices.push(indexedRow);
Expand All @@ -97,19 +101,23 @@ export function createManager(): ModifiedDataManager {
return acc;
}, []);

let accumulatedLength = 0;

sortedContinuousIndexedRows.forEach((indexedRows) => {
const startIndex = indexedRows[0].rowIndex;
const lastIndex = last(indexedRows).rowIndex;
const currentLength = last(indexedRows).rowIndex - startIndex + 1;

if (isUndefined(rows)) {
dataMap[type].splice(startIndex, lastIndex - startIndex + 1);
dataMap[type].splice(startIndex - accumulatedLength, currentLength);
} else {
dataMap[type].splice(
startIndex,
lastIndex - startIndex + 1,
currentLength,
...indexedRows.reduce((acc: Row[], { row }) => (!row ? acc : [...acc, row]), [])
);
}

accumulatedLength += currentLength;
});
};
const spliceAll = (rowKey: RowKey, row?: Row) => {
Expand Down