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(data-table): fixed group column box-shadow error and right fixed … #1833

Merged
merged 5 commits into from
Dec 14, 2021

Conversation

zanqwq
Copy link
Contributor

@zanqwq zanqwq commented Dec 13, 2021

fixed group column box-shadow error and right fixed column render order error

@vercel
Copy link

vercel bot commented Dec 13, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/tusimple/naive-ui/JDvaCXWdFCb5PBDpzRujGE9kwoKN
✅ Preview: https://naive-ui-git-fork-zanqwq-main-tusimple.vercel.app

@zanqwq
Copy link
Contributor Author

zanqwq commented Dec 13, 2021

修改内容:

  1. use-scroll hook 中在调用 traverse 函数对 rightFixedColumnsRef.value 进行搜索时不应该调用数组的 reverse 函数, 因为 reverse 函数会修改原数组, 而 rightFixedColumnsRef 是一个 computed 的值, 不应该主动去修改它的值. 修复后可以解决 right fixed column 渲染顺序反转的 bug.
  2. data-tableuse-scroll hook 中添加 leftActiveFixedChildrenColKeysRefrightActiveFixedChildrenColKeysRef 来记录被 fixed 的 children
  3. Body.tsx 使用 leftActiveFixedChildrenColKeysRefrightActiveFixedChildrenColKeysRef 配合 css-render 渲染 box-shadow

Comment on lines +99 to +114
function deriveActiveLeftFixedChildrenColumns (): void {
leftActiveFixedChildrenColKeysRef.value = []
let activeLeftFixedColumn = props.columns.find(
(col) => getColKey(col) === leftActiveFixedColKeyRef.value
)
while (activeLeftFixedColumn && 'children' in activeLeftFixedColumn) {
const length: number = activeLeftFixedColumn.children.length
if (length === 0) break
const nextActiveLeftFixedColumn =
activeLeftFixedColumn.children[length - 1]
leftActiveFixedChildrenColKeysRef.value.push(
getColKey(nextActiveLeftFixedColumn)
)
activeLeftFixedColumn = nextActiveLeftFixedColumn
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

沿着 activeLeftFixedColKeyRef.value 的最右边的儿子一直搜索来计算 leftActiveFixedChildrenColKeysRef.value

Copy link
Collaborator

Choose a reason for hiding this comment

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

确实应该这么做的

Comment on lines 283 to 302
const createActiveRightFixedStyle = (
rightActiveFixedColKey: string | null
): CNode | null => {
if (rightActiveFixedColKey === null) return null
return c(
`[data-n-id="${
cProps.componentId as string
}"] [data-col-key="${rightActiveFixedColKey}"]::before`,
{
boxShadow: 'var(--box-shadow-before)'
}
)
}

return c([
createActiveLeftFixedStyle(cProps.leftActiveFixedColKey as string),
createActiveRightFixedStyle(cProps.rightActiveFixedColKey as string),
(cProps.leftActiveFixedChildrenColKeys as string[]).map(
(leftActiveFixedColKey) =>
createActiveLeftFixedStyle(leftActiveFixedColKey)
Copy link
Collaborator

@07akioni 07akioni Dec 13, 2021

Choose a reason for hiding this comment

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

这块 cProps 需要在函数参数那里把类型声明完全,原先写成 Record<string, string> 是因为凑活够用,在这个 case 下应该把 leftActiveFixedColKey、...、componentId 都写好对应的类型,而不是用 as 来判断类型

Copy link
Contributor Author

Choose a reason for hiding this comment

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

已改进 cProps 的类型提示

@XieZongChen XieZongChen linked an issue Dec 14, 2021 that may be closed by this pull request
@codecov
Copy link

codecov bot commented Dec 14, 2021

Codecov Report

Merging #1833 (7ac1ad7) into main (ba56af8) will decrease coverage by 0.08%.
The diff coverage is 16.66%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1833      +/-   ##
==========================================
- Coverage   64.83%   64.74%   -0.09%     
==========================================
  Files         890      890              
  Lines       17312    17342      +30     
  Branches     4104     4107       +3     
==========================================
+ Hits        11224    11228       +4     
- Misses       5312     5338      +26     
  Partials      776      776              
Impacted Files Coverage Δ
src/data-table/src/DataTable.tsx 76.38% <ø> (ø)
src/data-table/src/interface.ts 100.00% <ø> (ø)
src/data-table/src/use-scroll.ts 24.16% <16.00%> (-3.39%) ⬇️
src/data-table/src/TableParts/Body.tsx 67.38% <18.18%> (-1.51%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ba56af8...7ac1ad7. Read the comment docs.

@07akioni 07akioni merged commit 21fe821 into tusen-ai:main Dec 14, 2021
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.

DataTable group column 的列顺序错误
2 participants