Skip to content

Commit

Permalink
[FIX] FiguresContainer: Restrict resizing if reaches header boundary
Browse files Browse the repository at this point in the history
Resizing the graph previously allowed it to go beyond the header, causing the
entire graph to be pushed to the right or bottom upon release. This commit
addresses this issue by introducing a restriction that prevents resizing from
extending into the header.

Changes made:
- Added conditional checks to restrict resizing if the x or y coordinate reaches
the header boundaries.

closes #2687

Task: 3414127
Signed-off-by: Adrien Minne (adrm) <adrm@odoo.com>
  • Loading branch information
dhrp-odoo committed Jul 26, 2023
1 parent 4dbd417 commit b1bac2f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/components/figures/figure_container/figure_container.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
if (dirY < 0) {
this.dnd.y = dndInitialY - deltaY;
}

if (this.dnd.x < 0) {
this.dnd.width += this.dnd.x;
this.dnd.x = 0;
}
if (this.dnd.y < 0) {
this.dnd.height += this.dnd.y;
this.dnd.y = 0;
}
};

const onMouseUp = (ev: MouseEvent) => {
Expand Down
17 changes: 17 additions & 0 deletions tests/components/figure.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,23 @@ describe("figures", () => {
expect(model.getters.getFigure(sheetId, figureId)).toMatchObject(expectedSize);
});

test.each([
["top", { mouseOffsetX: 0, mouseOffsetY: -100 }],
["left", { mouseOffsetX: -100, mouseOffsetY: 0 }],
["topLeft", { mouseOffsetX: -100, mouseOffsetY: -100 }],
])(
"Resizing a figure through its top and left anchor does not change size beyond header boundaries",
async (anchor: string, mouseMove: { mouseOffsetX: number; mouseOffsetY: number }) => {
const figureId = "someuuid";
const figure = { width: 100, height: 100 };
createFigure(model, { id: figureId, y: 0, x: 0, ...figure });
await nextTick();
await simulateClick(".o-figure");
await dragAnchor(anchor, mouseMove.mouseOffsetX, mouseMove.mouseOffsetY, true);
expect(model.getters.getFigure(sheetId, figureId)).toMatchObject(figure);
}
);

test.each([
[
"topLeft",
Expand Down

0 comments on commit b1bac2f

Please sign in to comment.