-
Notifications
You must be signed in to change notification settings - Fork 71
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
reports.vueをreactのReports.jsxに書き換えた #6236
Changes from all commits
56f7b3d
bc90fec
dcf52c2
c10fc9c
6a8af25
f2aea40
33a4cb7
2365a83
a17a224
17544ee
62bfb0b
252ec9e
926e426
34062a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,24 +6,37 @@ import LoadingListPlaceholder from './LoadingListPlaceholder' | |
import Report from './Report' | ||
import Pagination from './Pagination' | ||
import PracticeFilterDropdown from './PracticeFilterDropdown' | ||
import UnconfirmedLink from './UnconfirmedLink' | ||
|
||
export default function Reports({ user, currentUser, practices }) { | ||
export default function Reports({ all = false, userId = '', practices = false, unchecked = false, displayUserIcon = true, companyId = '', practiceId = '' }) { | ||
Comment on lines
-10
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 変数の増加が気になります 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. おそらくmono-nobeさんが仰っていることは、 export default function Reports (props) {
// 中の処理
} このように https://discord.com/channels/715806612824260640/959777673612251146/1070993776899784704 AntiSatoriさんにこちらのDiscordで教えていただいたのですが、今のReactでは
ことが推奨されているようです! そのため、ちょっとコードが長くなっていますが、このような形でコードを書きました。 ※引数がもっと増えてきたら、引数ごとに改行を入れることが多いです。今回は引数の数がそこまで多くないので、1行で書きました。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
そうです!
参考URLありがとうございます!!!
そうだったのですね 😳 |
||
const per = 20 | ||
const neighbours = 4 | ||
const defaultPage = parseInt(queryString.parse(location.search).page) || 1 | ||
const [page, setPage] = useState(defaultPage) | ||
const [practiceId, setPracticeId] = useState('') | ||
const [userPracticeId, setUserPracticeId] = useState('') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝プラクティスそのものの日報一覧と、特定のユーザー日報一覧で表示形式が違うため、処理が異なります。そのため、変数名が被らないように書き換えています。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
理由としては、これに近いです。 11行目で これと同じ変数名が、こちらで最近追加されたPull Requestで使われてしまっていました。 そのため、もしこの16行目が (そのままの状態だと、11行目の変数定義と16行目の変数定義がバッティングして、エラーが出てReactが表示されなくなってしまいます💧) 削除をしているわけではなく、変数名を変更してかぶらないようにすることで、既存の処理を壊すことなく実装することができます。 なので、
という2つの理由からおこなっているものです。 この変更に伴い、この直下の22行目や23行目など、影響範囲のあるところも修正しております。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
なるほどです! |
||
|
||
useEffect(() => { | ||
setPage(page) | ||
}, [page]) | ||
|
||
useEffect(() => { | ||
setPracticeId(practiceId) | ||
}, [practiceId]) | ||
setUserPracticeId(userPracticeId) | ||
}, [userPracticeId]) | ||
|
||
const { data, error } = useSWR( | ||
`/api/reports.json?user_id=${user.id}&page=${page}&practice_id=${practiceId}`, | ||
practices | ||
? `/api/reports.json?user_id=${userId}&page=${page}&practice_id=${userPracticeId}` | ||
: unchecked | ||
? `/api/reports/unchecked.json?page=${page}&user_id=${userId}` | ||
: userId !== '' | ||
? `/api/reports.json?page=${page}&user_id=${userId}` | ||
: practiceId !== '' | ||
? `/api/reports.json?page=${page}&practice_id=${practiceId}` | ||
: companyId !== '' | ||
? `/api/reports.json?page=${page}&company_id=${companyId}` | ||
: all === true | ||
? `/api/reports.json?page=${page}&practice_id=${userPracticeId}` | ||
: console.log('data_fetched!'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝Reactへ渡される引数によって、fetch先を変えています。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 複数の条件に合う引数が渡されることはありますか? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
複数の条件に合う引数が渡されることはありません。 slimを見て頂けると分かりやすいと思うのですが、例えば「全ての日報のデータをfetchしたい場合」と、「個人の日報のデータをfetchしてくる場合」で渡す引数が違うからです。 優先度も考えて三項演算子で処理致しました! なので、問題ないと思います。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
ありがとうございます! |
||
fetcher | ||
) | ||
|
||
|
@@ -39,22 +52,26 @@ export default function Reports({ user, currentUser, practices }) { | |
return ( | ||
<> | ||
{data.totalPages === 0 && ( | ||
<div className="container is-md"> | ||
<PracticeFilterDropdown | ||
practices={practices} | ||
setPracticeId={setPracticeId} | ||
practiceId={practiceId} | ||
/> | ||
<NoReports /> | ||
<div> | ||
{practices && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 |
||
<PracticeFilterDropdown | ||
practices={practices} | ||
setPracticeId={setUserPracticeId} | ||
practiceId={userPracticeId} | ||
/> | ||
)} | ||
<NoReports unchecked={unchecked} /> | ||
</div> | ||
)} | ||
{data.totalPages > 0 && ( | ||
<div className="container is-md"> | ||
<PracticeFilterDropdown | ||
practices={practices} | ||
setPracticeId={setPracticeId} | ||
practiceId={practiceId} | ||
/> | ||
<div> | ||
{practices && ( | ||
<PracticeFilterDropdown | ||
practices={practices} | ||
setPracticeId={setUserPracticeId} | ||
practiceId={userPracticeId} | ||
/> | ||
)} | ||
<div className="page-content reports"> | ||
{data.totalPages > 1 && ( | ||
<Pagination | ||
|
@@ -72,12 +89,16 @@ export default function Reports({ user, currentUser, practices }) { | |
<Report | ||
key={report.id} | ||
report={report} | ||
currentUser={currentUser} | ||
currentUserId={report.currentUserId} | ||
displayUserIcon={displayUserIcon} | ||
/> | ||
) | ||
})} | ||
</div> | ||
</ul> | ||
{unchecked && ( | ||
<UnconfirmedLink label={'未チェックの日報を一括で開く'} /> | ||
)} | ||
{data.totalPages > 1 && ( | ||
<Pagination | ||
sum={data.totalPages * per} | ||
|
@@ -94,12 +115,14 @@ export default function Reports({ user, currentUser, practices }) { | |
) | ||
} | ||
|
||
const NoReports = () => { | ||
const NoReports = ({ unchecked }) => { | ||
return ( | ||
<div className="o-empty-message"> | ||
<div className="o-empty-message__icon"> | ||
<i className="fa-regular fa-face-sad-tear" /> | ||
<p className="o-empty-message__text">日報はまだありません。</p> | ||
{unchecked | ||
? <><i className="fa-regular fa-smile" /><p className="o-empty-message__text">未チェックの日報はありません</p></> | ||
: <><i className="fa-regular fa-sad-tear" /><p className="o-empty-message__text">'日報はまだありません。'</p></> | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 |
||
</div> | ||
</div> | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -455,10 +455,8 @@ def wait_for_watch_change | |
|
||
test 'display recently reports' do | ||
visit_with_auth report_path(reports(:report10)), 'mentormentaro' | ||
within first('.side-tabs .card-list-item') do | ||
assert_selector 'img[alt="happy"]' | ||
assert_text '今日は頑張りました' | ||
end | ||
assert_selector 'img[alt="happy"]' | ||
assert_text '今日は頑張りました' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝CSSの構造が変わったためテストを書き換えました |
||
end | ||
|
||
test 'display list of submission when mentor is access' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝displayUserIconがある場合のみ、カッコ内の処理が行われます。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
この部分を別コンポーネントにするとわかりやすいかな〜と思いました。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
別コンポーネントを作成致しました!
差分はこちらになります。→ 34062a1