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(list, block-group): drag menu 'Move to' actions broken when list elements have explicit ids #11515

Merged
merged 3 commits into from
Feb 12, 2025
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 @@ -246,6 +246,38 @@ describe("calcite-block-group", () => {

await page.waitForChanges();

const letterBlockSelector = `calcite-block-group[group="letters"] calcite-block`;
const letterBlocks = await findAll(page, letterBlockSelector);

expect(letterBlocks.length).toBe(6);

const moveToItemIds = await page.evaluate((letterBlockSelector) => {
return Array.from(document.querySelectorAll(letterBlockSelector))
.map((item: Block["el"]) => item.moveToItems.map((moveToItem) => moveToItem.id))
.flat();
}, letterBlockSelector);

expect(moveToItemIds.length).toBe(6);

const uniqueMoveToItemIds = new Set(moveToItemIds);

expect(uniqueMoveToItemIds.size).toBe(2);

const moveToItemElementIds = await page.evaluate((letterBlockSelector) => {
return Array.from(document.querySelectorAll(letterBlockSelector))
.map((item: Block["el"]) => item.moveToItems.map((moveToItem) => moveToItem.element.id))
.flat();
}, letterBlockSelector);

expect(moveToItemElementIds.length).toBe(6);
expect(moveToItemElementIds[0]).toBe("second-letters");
expect(moveToItemElementIds[1]).toBe("second-letters");

expect(moveToItemElementIds[2]).toBe("first-letters");
expect(moveToItemElementIds[3]).toBe("first-letters");
expect(moveToItemElementIds[4]).toBe("first-letters");
expect(moveToItemElementIds[5]).toBe("first-letters");

// Workaround for page.spyOnEvent() failing due to drag event payload being serialized and there being circular JSON structures from the payload elements. See: https://github.com/Esri/calcite-design-system/issues/7643
await page.evaluate(() => {
const testWindow = window as TestWindow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ export class BlockGroup extends LitElement implements InteractiveComponent, Sort
this.moveToItems = blockGroups.map((element) => ({
element,
label: element.label ?? element.id,
id: el.id || guid(),
id: guid(),
}));
}

Expand Down
32 changes: 32 additions & 0 deletions packages/calcite-components/src/components/list/list.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,38 @@ describe("calcite-list", () => {

await page.waitForChanges();

const letterItemSelector = `calcite-list[group="letters"] calcite-list-item`;
const letterItems = await findAll(page, letterItemSelector);

expect(letterItems.length).toBe(6);

const moveToItemIds = await page.evaluate((letterItemSelector) => {
return Array.from(document.querySelectorAll(letterItemSelector))
.map((item: ListItem["el"]) => item.moveToItems.map((moveToItem) => moveToItem.id))
.flat();
}, letterItemSelector);

expect(moveToItemIds.length).toBe(6);

const uniqueMoveToItemIds = new Set(moveToItemIds);

expect(uniqueMoveToItemIds.size).toBe(2);

const moveToItemElementIds = await page.evaluate((letterItemSelector) => {
return Array.from(document.querySelectorAll(letterItemSelector))
.map((item: ListItem["el"]) => item.moveToItems.map((moveToItem) => moveToItem.element.id))
.flat();
}, letterItemSelector);

expect(moveToItemElementIds.length).toBe(6);
expect(moveToItemElementIds[0]).toBe("second-letters");
expect(moveToItemElementIds[1]).toBe("second-letters");

expect(moveToItemElementIds[2]).toBe("first-letters");
expect(moveToItemElementIds[3]).toBe("first-letters");
expect(moveToItemElementIds[4]).toBe("first-letters");
expect(moveToItemElementIds[5]).toBe("first-letters");

// Workaround for page.spyOnEvent() failing due to drag event payload being serialized and there being circular JSON structures from the payload elements. See: https://github.com/Esri/calcite-design-system/issues/7643
await page.evaluate(() => {
const testWindow = window as TestWindow;
Expand Down
2 changes: 1 addition & 1 deletion packages/calcite-components/src/components/list/list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -854,7 +854,7 @@ export class List
this.moveToItems = lists.map((element) => ({
element,
label: element.label ?? element.id,
id: el.id || guid(),
id: guid(),
}));

const groupItems = Array.from(this.el.querySelectorAll(listItemGroupSelector));
Expand Down
Loading