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: [Descriptions] Ensure that the number of rows matches the column #2201

Open
wants to merge 3 commits into
base: release
Choose a base branch
from

Conversation

rashagu
Copy link
Contributor

@rashagu rashagu commented Apr 25, 2024

English Template / 英文模板

  • 我已阅读并遵循了贡献文档中的PR指南.

PR类型 (请至少选择一个)

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Test Case
  • TypeScript definition update
  • Document improve
  • CI/CD improve
  • Branch sync
  • Other, please describe:

PR 描述

Fixes #

  1. [Descriptions] 当布局是horizontal时, 确保一行的数量符合column的值

更新日志

🇨🇳 Chinese

  • Fix: [Descriptions] 当布局是horizontal时, 确保一行的数量符合column的值

🇺🇸 English

  • Fix: [Descriptions] When the layout is horizontal, make sure the number of rows is as expected for the column

检查清单

  • 已增加测试用例或无须增加
  • 已补充文档或无须补充
  • Changelog已提供或无须提供

其他要求

  • 本条 PR 不需要纳入 Changelog

附加信息

Copy link

codesandbox-ci bot commented Apr 25, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 13ef2c7:

Sandbox Source
pr-story Configuration

@pointhalo
Copy link
Collaborator

由于问题描述有点欠缺,对这个修改有点疑问。

确认一下,你是希望解决类似下图(预期应该换行,但实际未换行)的问题吗?
image

horizontalList.push(curSpan.itemList);
curSpan.itemList = [];
curSpan.totalSpan = 0;
curSpan.totalSpan = item.span || 1;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个写法感觉有点绕。
建议 18行 totalSpan可以先不执行 + 操作吧。
想做的是尝试在 curSpan放入当前item,那么拿 restSpan剩余列数,跟item.span去做对比会更直观一些。如果 item.span <= restSpan 再做操作,否则就直接另起一行。

如果像现在任意情况下都 先加totalSpan,如果放不下还得还原。

@pointhalo
Copy link
Collaborator

我尝试重新写了一下这段逻辑,感觉是可以不用那么长的。

    getHorizontalList() {
        const { column: maxColumnPerLine } = this.getProps();
        const columns = this._adapter.getColumns();
        const horizontalList = []; // 二维数组

        const curRow = { totalSpan: 0, itemList: [] };

        columns.forEach((item, index) => {
            let itemSpan = item.span || 1;
            let restSpan = maxColumnPerLine - curRow.totalSpan;
            if (itemSpan <= restSpan) {
                curRow.itemList.push(item);
                curRow.totalSpan = curRow.totalSpan + itemSpan;
            } else {
                // 剩余空间放不下当前item,需要另起一行
                // 若新行放不下当前item,极端情况,例如用户给当前span数值远大于 maxColumnPerLine,即使另起新行都无法放得下,itemSpan直接按props.column处理
                itemSpan > maxColumnPerLine ? itemSpan = maxColumnPerLine : null;
                // 新行能放得下当前item,将原有行push到horizontalList中,然后重置curRow,将当前item存到curRow中
                horizontalList.push(curRow.itemList);
                curRow.totalSpan = itemSpan;
                curRow.itemList = [item];
            }
            if (index === columns.length -1) {
                horizontalList.push(curRow.itemList);
            }
        });
    }

另外 description 的 item.tsx里也发现了一个上次的PR #2121 review时忽略了的问题,这里为什么要 span *2 -1,似乎应该直接 span || 1也是ok的。

image

@rashagu
Copy link
Contributor Author

rashagu commented May 16, 2024

上次的PR #2121 span *2-1是因为 align不等于'plain'的时候,要把th的colspan也算进来,这样1column=1th+1td,减1减掉自身的th

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants