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(compass-crud): in the bulk update preview, convert array indexes from strings to numbers COMPASS-8218 #6161

Merged
merged 2 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -391,7 +391,7 @@ function itemsWithChanges({
assert(delta._t === 'a', 'delta._t is not a');
const toRemove = Object.keys(delta)
.filter((key) => key.startsWith('_') && key !== '_t')
.map((key) => key.slice(1) as unknown as number);
.map((key) => parseInt(key.slice(1), 10));

// Removed indexes refer to the original (left) which is why we remove in a
// separate pass before updating/adding
Expand All @@ -404,13 +404,6 @@ function itemsWithChanges({
} else {
assert(false, `item with index "${index}" does not exist`);
}

// adjust the indexes of all items after this one
for (const item of items) {
if (item.index > index) {
item.index = item.index - 1;
}
}
}

for (const [_index, change] of Object.entries(delta)) {
Expand All @@ -421,7 +414,7 @@ function itemsWithChanges({
// Non-removed indexes refer to the final (right) array which is why we
// update/add in a separate pass after removing

const index = _index as unknown as number;
const index = parseInt(_index, 10);
assert(Array.isArray(change), 'unexpected non-array');
assert(change.length !== 3, 'array moves are not supported');
assert(change.length !== 2, 'array changes are not supported'); // always add and remove
Expand Down
31 changes: 31 additions & 0 deletions packages/compass-crud/test/before-after-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,37 @@ export const fixtureGroups: FixtureGroup[] = [
before: { foo: [0, { bar: 'baz' }] },
after: { foo: [0, { bar: 'bazz' }] },
},
{
name: 'many items',
before: {
foo: [
{ i: 0 },
{ i: 1 },
{ i: 2 },
{ i: 3 },
{ i: 4 },
{ i: 5 },
{ i: 6 },
{ i: 7 },
{ i: 8 },
{ i: 9 },
],
},
after: {
foo: [
{ i: 0, newField: 1 },
{ i: 1, newField: 1 },
{ i: 2, newField: 1 },
{ i: 3, newField: 1 },
{ i: 4, newField: 1 },
{ i: 5, newField: 1 },
{ i: 6, newField: 1 },
{ i: 7, newField: 1 },
{ i: 8, newField: 1 },
{ i: 9, newField: 1 },
],
},
},
],
},
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading