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

chore: TableコンポーネントのuseReelCells のロジックを整理する #5248

Merged
merged 3 commits into from
Jan 13, 2025

Conversation

AtsushiM
Copy link
Member

@AtsushiM AtsushiM commented Jan 9, 2025

関連URL

概要

TableのuseReelCellsのロジックを整理し、効率化、可読性の向上を試みます

変更内容

確認方法

Copy link

pkg-pr-new bot commented Jan 9, 2025

Open in Stackblitz

npm i https://pkg.pr.new/kufu/smarthr-ui@5248

commit: e11b4ea

@AtsushiM AtsushiM changed the title chore: useReelCells のロジックを整理する chore: TableコンポーネントのuseReelCells のロジックを整理する Jan 9, 2025
@@ -7,42 +7,40 @@ export const useReelCells = () => {
useEffect(() => {
const currentRef = tableWrapperRef.current

if (!currentRef) {
Copy link
Member Author

@AtsushiM AtsushiM Jan 9, 2025

Choose a reason for hiding this comment

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

currentRefが存在しない限り、後続の処理は不要だったため、ロジックを修正しています
もともとのロジックでは各箇所にcurrentRefの存在チェックがありましたが、分散してしまい見づらかったのでここに集約させます。効率もよいです。

Copy link
Contributor

Choose a reason for hiding this comment

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

早期リターンいいですね 👍

})
const stickyCells = currentRef.querySelectorAll('.fixedElement')

if (!stickyCells) {
Copy link
Member Author

Choose a reason for hiding this comment

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

stickyCellsが存在しない場合、後続のロジックは不要だったのでifを追加しています

Comment on lines +23 to +26
const shouldFix = maxScrollLeft > 0 && scrollLeft < maxScrollLeft
const settableShowShadow = shouldFix
? scrollLeft > 0
: maxScrollLeft !== 0 || scrollLeft !== 0
Copy link
Member Author

Choose a reason for hiding this comment

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

forEachの中で毎回計算する必要がなかったため、forの外で計算を済ませておきます

@AtsushiM AtsushiM marked this pull request as ready for review January 9, 2025 06:10
@AtsushiM AtsushiM requested a review from a team as a code owner January 9, 2025 06:10
@AtsushiM AtsushiM requested review from yt-ymmt and Qs-F and removed request for a team January 9, 2025 06:10
: maxScrollLeft !== 0 || scrollLeft !== 0

stickyCells.forEach((cell) => {
cell.classList.toggle('fixed', shouldFix)
Copy link
Member Author

Choose a reason for hiding this comment

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

classListに対するadd, removeはそれぞれtoggleの第2引数にtrue, falseを渡すことで表現できます。

Copy link
Contributor

@Qs-F Qs-F left a comment

Choose a reason for hiding this comment

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

個人的には早期リターン推しなのでGOGOです!挙動も問題なさそうでした

@@ -7,42 +7,40 @@ export const useReelCells = () => {
useEffect(() => {
const currentRef = tableWrapperRef.current

if (!currentRef) {
Copy link
Contributor

Choose a reason for hiding this comment

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

早期リターンいいですね 👍

@AtsushiM AtsushiM merged commit 75446b3 into master Jan 13, 2025
22 of 23 checks passed
@AtsushiM AtsushiM deleted the chore-refactoring-useReelCell branch January 13, 2025 22:03
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.

2 participants