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: ActionDialogの内部処理を整理する #5324

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

AtsushiM
Copy link
Member

関連URL

概要

変更内容

確認方法

@AtsushiM AtsushiM changed the title chore: ActionDialog chore: ActionDialogの内部処理を整理する Jan 23, 2025
@yagimushi yagimushi force-pushed the chore-refactoring-ActionDialog branch from 84983bc to 703c0e3 Compare January 23, 2025 06:47
Copy link

pkg-pr-new bot commented Jan 23, 2025

Open in Stackblitz

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

commit: 703c0e3

@@ -24,7 +24,7 @@ export const ActionDialog: React.FC<Props & ElementProps> = ({
onClickClose,
onPressEscape = onClickClose,
responseMessage,
actionDisabled = false,
actionDisabled,
Copy link
Member Author

Choose a reason for hiding this comment

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

最終的にButtonのdisabledに設定されるだけだったため、初期化の意味が薄く、削除しました

if (!props.isOpen) {
return
if (props.isOpen) {
onClickClose()
Copy link
Member Author

Choose a reason for hiding this comment

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

早期returnしていますが

  • 直後の処理の判定を逆転させているだけであり、理解が一手遅れる
  • !とreturn分の処理が余計にかかる

というデメリットのほうが大きそうだったため調整しています

onClickAction(onClickClose)
}, [onClickAction, onClickClose])
const isRequestProcessing = responseMessage && responseMessage.status === 'processing'
const calcedResponseStatus = useMemo(() => {
Copy link
Member Author

Choose a reason for hiding this comment

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

responseMessageの判定が煩雑になっていたため、扱いやすい形に変換、memo化しています。
この処理は他のコンポーネントでもよくあるもののため、カスタムhookを別PRで作成予定です

Comment on lines +24 to +27
const onClickOpen = useMemo(
() => (onClickTrigger ? () => onClickTrigger(open) : open),
[onClickTrigger, open],
)
Copy link
Member Author

Choose a reason for hiding this comment

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

useCallbackではなくuseMemoにしています。
こうすることでどの場合でもonClickOpen実行時に行っているif判定を事前に行えます

@AtsushiM AtsushiM marked this pull request as ready for review January 23, 2025 22:42
@AtsushiM AtsushiM requested a review from a team as a code owner January 23, 2025 22:42
@AtsushiM AtsushiM requested review from moshisora and hiroki0525 and removed request for a team January 23, 2025 22:42
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.

1 participant