-
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
卒業証書のPDFファイルをアップロードできる機能を追加 #8190
base: main
Are you sure you want to change the base?
Conversation
@machida |
@hagiya0121 了解です!! |
@hagiya0121 お待たせしました!!デザイン入れましたのでご確認お願いします。OKでしたらレビューに進めてくださいー |
@ham-cap |
@hagiya0121 |
@ham-cap |
@mousu-a |
@hagiya0121 |
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.
@hagiya0121
実装お疲れ様です🍵
レビューお待たせいたしました🙏
いくつかコメントしているのでご確認いただければと思います〜
以下 "変更確認方法"について気になったところのフィードバックになります!
5番 のpdfのパスについてですが、bootcamp/test/fixtures/files/users/diplomas/diploma.pdf
の方がいいかもです。
あと、「アップロードして更新する」とありますが、「アップロードして、ページ下部の"更新する"ボタンを押す」 とかの方が間違いがないと思います。8番も同様です!
一瞬「画面の更新かな?」と思ってしまいました😅
app/javascript/fileinput.js
Outdated
const removeDiplomaFlag = document.getElementById('remove-diploma-flag') | ||
|
||
removeDiplomaButton.addEventListener('click', () => { | ||
diplomaFileLink && (diplomaFileLink.style.display = 'none') |
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.
すみません、ここの説明ほしいです🙏
なぜこのコードが必要なのかがわからない感じです。
diplomaFileLink && (diplomaFileLink.style.display = 'none')
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.
diplomaFileLinkが存在する場合のみ右辺が発火するわけですね。
勉強になります🙏
その場合下記のような形ではどうでしょうか?
if (diplomaFileLink) diplomaFileLink.style.display = 'none'
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.
町田さんがデザインを入れた際に変更してくれたみたいです🤔18c14ab2e02b8526752
app/views/users/_form.html.slim
Outdated
- if @user.diploma_file.attached? | ||
= link_to @user.diploma_file.filename, url_for(@user.diploma_file), class: 'a-text-input', id: 'diploma-file-link' | ||
- display = @user.diploma_file.attached? ? 'display: none' : 'display: block' | ||
= f.file_field :diploma_file, class: 'a-text-input', id: 'diploma-upload-field', style: display |
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.
display
→ display_style
でもいいかもです。
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.
そちらの名前の方がわかりやすいですね。変更しました!
fd1d8db
- display = @user.diploma_file.attached? ? 'display: none' : 'display: block' | ||
= f.file_field :diploma_file, class: 'a-text-input', id: 'diploma-upload-field', style: display | ||
button type='button' id='remove-diploma-button' class='a-button is-md is-secondary' 削除 | ||
|
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.
button_tagが使えそうです!
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.
変更しました
3aeb25a
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.
ファイルがアップロードされていない状態で削除ボタンがあるのはおかしい気がします🤔
config/locales/ja.yml
Outdated
@@ -111,6 +111,7 @@ ja: | |||
other_editor: その他のエディタ | |||
hide_mentor_profile: プロフィール非公開 | |||
invoice_payment: 「請求書払い」 | |||
diploma_file: 卒業証書PDF |
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.
提案です!
"卒業証書(PDF)"とかでもいいかもです。
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.
そちらの方がいいと思います。変更しました
b2ff53d
app/javascript/fileinput.js
Outdated
@@ -85,3 +85,42 @@ document.addEventListener('DOMContentLoaded', () => { | |||
} | |||
initializeFileInput(document) | |||
}) | |||
|
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.
今回実装する部分を関数にして↑の DOMContentLoadedに入れてはどうでしょうか?
あと画面の読み込み時に実行していますが、該当する画面でない場合のreturnがなさそうです。
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.
変更しました
6b5d653
app/views/users/_form.html.slim
Outdated
@@ -104,6 +104,28 @@ | |||
.form-item-block__item | |||
= render 'users/form/graduate', f: f | |||
|
|||
.form-item | |||
// 卒業証書 |
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.
削除しました
fd1d8db
app/javascript/fileinput.js
Outdated
@@ -85,3 +85,42 @@ document.addEventListener('DOMContentLoaded', () => { | |||
} | |||
initializeFileInput(document) | |||
}) | |||
|
|||
document.addEventListener('DOMContentLoaded', () => { | |||
const removePdfButton = document.getElementById('js-remove-pdf-button') |
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.
この辺りの変数名も、先のコメントで触れたように関数で括れば変数名にpdfってつけなくて良さそうです。
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.
変数名の変更とリファクタリングも一緒に行いました。
6b5d653
@mousu-a |
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.
@hagiya0121
レビューお待たせいたしました🙏
いくつかコメントしているのでご確認いただければと思います〜
- display = @user.diploma_file.attached? ? 'display: none' : 'display: block' | ||
= f.file_field :diploma_file, class: 'a-text-input', id: 'diploma-upload-field', style: display | ||
button type='button' id='remove-diploma-button' class='a-button is-md is-secondary' 削除 | ||
|
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.
ファイルがアップロードされていない状態で削除ボタンがあるのはおかしい気がします🤔
app/javascript/fileinput.js
Outdated
@@ -75,6 +75,45 @@ function extractField(elements) { | |||
} | |||
} | |||
|
|||
function initializePdfUploadField() { |
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.
提案です!
initializeDiplomaUploadField
の方がいいかも?
app/javascript/fileinput.js
Outdated
const removeButton = document.getElementById('js-remove-pdf-button') | ||
const fileLink = document.getElementById('js-pdf-file-link') | ||
const removeFlag = document.getElementById('js-remove-pdf-flag') | ||
const fileNameDisplay = document.getElementById('js-pdf-name') |
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.
提案です!
fileNameDisplay → fileName でも良さそうです🙆
app/javascript/fileinput.js
Outdated
const fileNameDisplay = document.getElementById('js-pdf-name') | ||
const fileInput = uploadField.querySelector('input[type="file"]') | ||
|
||
const updateFileNameDisplay = (name = '') => { |
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.
提案です!
updateDisplayedFileName とかではどうでしょうか?
app/javascript/fileinput.js
Outdated
} | ||
|
||
removeButton.addEventListener('click', () => { | ||
if (fileLink) fileLink.style.display = 'none' |
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.
ファイルがアップロードされている時のみ削除ボタンが表示されていれば、if文は不要になるかもです
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.
fileLinkはHTMLが生成されない場合があるのでエラーになるようです。
app/javascript/fileinput.js
Outdated
const fileInput = uploadField.querySelector('input[type="file"]') | ||
|
||
const updateFileNameDisplay = (name = '') => { | ||
if (name) { |
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.
こんな感じで書けそうです🙆
fileNameDisplay.textContent = name
const displayedStatus = name ? 'block' : 'none'
fileNameDisplay.style.display = displayedStatus
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.
指摘された点とfileInputのイベントリスナーのロジックもリファクタリングしました。
97b19ed
@mousu-a |
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.
@hagiya0121
変更ありがとうございます!
気になる点少しだけコメントさせていただきましたのでご確認をお願いいたします🙇♂️
他は良さそうです👌
app/javascript/fileinput.js
Outdated
uploadField.style.display = fileLink ? 'none' : 'flex' | ||
removeButton.style.display = fileLink ? 'block' : 'none' | ||
|
||
const updateDisplayedFileName = (name = '') => { |
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.
細かい点ですが、removeButton.style.display = displayedStatus
を関数の中に入れるのならばupdateDisplayedFileName
は命名を変更したほうが良さそうに思いました。
"表示状態をアップデートする"ということでupdateDisplayStatus
、updateDisplayState
とかどうでしょうか。StateはReactにもある概念なので相手に意味が伝わりやすいかも?
もっと良いものがあればそちらにしていただいて構いません🙇♂️
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.
updateDisplayState
がわかりやすそうなのでそっちに変更しました。
app/javascript/fileinput.js
Outdated
const fileName = document.getElementById('js-pdf-name') | ||
const fileInput = uploadField.querySelector('input[type="file"]') | ||
|
||
uploadField.style.display = fileLink ? 'none' : 'flex' |
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.
fileLinkをよくif文に使われているので、if文の条件として分かりやすい名前をつけてあげると可読性があがるかもです。
こんな感じでどうでしょうか。const isFileUploaded = fileLink
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.
必要あるか微妙なんですけどisFileUploaded
は名前的に真偽値を期待させるので二重否定して真偽値になるようにしました。
@mousu-a |
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.
isFileUploadedは名前的に真偽値を期待させる
すみません、後で気づきました🙏
個人的には、fileLink はそのままで変数名をfileUploaded
とかにするのが丸いように思います。
(たしかrubocopの方で二重否定はOUTとされていたので、個人的に二重否定に対して若干否定的な気持ちがあります😅)
ただ修正必須ではないのでApproveとさせていただきます〜。
変更ありがとうございました!
@mousu-a |
@komagata |
Issue
概要
管理者のユーザー登録情報変更画面で卒業証書のPDFファイルをアップロード及び削除できる機能を追加しました。
変更確認方法
feature/add-diploma-pdf-upload
をローカルに取り込むgit fetch origin pull/8190/head:feature/add-diploma-pdf-upload
git checkout feature/add-diploma-pdf-upload
foreman start -f Procfile.dev
でローカルサーバーを立ち上げkomagata
(管理者)でログイン卒業証書PDF
項目でbootcamp/test/fixtures/files/users/diplomas/diploma.pdf
をアップロードして、ページ下部の
更新する
ボタンを押す卒業証書PDF
項目にdiploma.pdf
と表示され、PDFを確認
を押してPDFが表示されることを確認する卒業証書PDF
項目で削除
ボタンを押して、ページ下部の更新する
ボタンを押す卒業証書PDF
項目でdiploma.pdf
という表示が消えていることを確認Screenshot
変更前
変更後