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

project duration直した #288

Merged
merged 10 commits into from
Jul 4, 2024
Merged

project duration直した #288

merged 10 commits into from
Jul 4, 2024

Conversation

mehm8128
Copy link
Contributor

@mehm8128 mehm8128 commented Jun 16, 2024

煩雑になってしまったけどしょうがないかも

@mehm8128 mehm8128 self-assigned this Jun 16, 2024
@mehm8128 mehm8128 requested a review from Pugma June 16, 2024 09:07
@mehm8128
Copy link
Contributor Author

/help

Copy link
Contributor

github-actions bot commented Jun 28, 2024

PR Agent Walkthrough 🤖

Welcome to the PR Agent, an AI-powered tool for automated pull request analysis, feedback, suggestions and more.

Here is a list of tools you can use to interact with the PR Agent:

ToolDescriptionTrigger Interactively 💎

DESCRIBE

Generates PR description - title, type, summary, code walkthrough and labels
  • Run

REVIEW

Adjustable feedback about the PR, possible issues, security concerns, review effort and more
  • Run

IMPROVE

Code suggestions for improving the PR
  • Run

UPDATE CHANGELOG

Automatically updates the changelog
  • Run

ADD DOCS 💎

Generates documentation to methods/functions/classes that changed in the PR
  • Run

TEST 💎

Generates unit tests for a specific component, based on the PR code change
  • Run

IMPROVE COMPONENT 💎

Code suggestions for a specific component that changed in the PR
  • Run

ANALYZE 💎

Identifies code components that changed in the PR, and enables to interactively generate tests, docs, and code suggestions for each component
  • Run

ASK

Answering free-text questions about the PR

[*]

GENERATE CUSTOM LABELS 💎

Generates custom labels for the PR, based on specific guidelines defined by the user

[*]

CI FEEDBACK 💎

Generates feedback and analysis for a failed CI job

[*]

CUSTOM PROMPT 💎

Generates custom suggestions for improving the PR code, derived only from a specific guidelines prompt defined by the user

[*]

SIMILAR ISSUE

Automatically retrieves and presents similar issues

[*]

(1) Note that each tool be triggered automatically when a new PR is opened, or called manually by commenting on a PR.

(2) Tools marked with [*] require additional parameters to be passed. For example, to invoke the /ask tool, you need to comment on a PR: /ask "<question content>". See the relevant documentation for each tool for more details.

@mehm8128
Copy link
Contributor Author

/review

Copy link
Contributor

PR Reviewer Guide 🔍

⏱️ Estimated effort to review [1-5] 3
🧪 Relevant tests No
🔒 Security concerns No
⚡ Key issues to review 型の一貫性:
元々YearWithSemester型を使用していたが、文字列に変更されています。これにより型安全性が低下している可能性があります。特に、handleInput関数でNumber(semester)Semester型として扱っていますが、これは安全ではありません。Semester型の範囲を超える値が入力された場合の処理が不足しています。
コメントの追加:
コードにコメントが追加されていますが、なぜこの変更が必要だったのかの説明が不足しています。特に、vue-selectが初期値を上手く表示しない問題に対する具体的な説明や、なぜ文字列型に変更することで問題が解決されるのかの説明が必要です。

@mehm8128
Copy link
Contributor Author

/improve

Copy link
Contributor

github-actions bot commented Jun 28, 2024

PR Code Suggestions ✨

Latest suggestions up to b2c66f3

CategorySuggestion                                                                                                                                    Score
Possible bug
型安全性を確保し、コードの正確性を向上させます。

stringToObject 関数において、semester の値を Number で変換していますが、これは Semester
型の列挙値に直接変換する必要があります。適切な型変換を行うことで、型安全性を確保しましょう。

src/components/UI/FormProjectDuration.vue [58-67]

 const stringToObject = (value: string | undefined) => {
   if (value === undefined) {
     return undefined
   }
   const [year, semester] = value.split(' ')
   return {
     year: Number(year),
-    semester: Number(semester) as Semester
+    semester: semester === '1' ? Semester.first : Semester.second
   }
 }
 
Suggestion importance[1-10]: 9

Why: この提案は型安全性を確保し、潜在的なバグを防ぐため、コードの正確性を大幅に向上させます。重要な改善です。

9
Enhancement
コードの重複を減らし、可読性と効率を向上させます。

computed で定義された options 配列の生成において、currentYear - i
を繰り返し使用しています。これを変数に格納して再利用することで、コードの可読性と効率を向上させることができます。

src/components/UI/FormProjectDuration.vue [26-38]

 const options = computed<Option<string | undefined>[]>(() =>
   Array(props.yearsAgo)
     .fill(null)
-    .flatMap((_, i) => [
-      {
-        label: `${(currentYear - i).toString()} 後期`,
-        value: `${currentYear - i} ${Semester.second}`
-      },
-      {
-        label: `${(currentYear - i).toString()} 前期`,
-        value: `${currentYear - i} ${Semester.first}`
-      }
-    ])
+    .flatMap((_, i) => {
+      const year = currentYear - i;
+      return [
+        {
+          label: `${year.toString()} 後期`,
+          value: `${year} ${Semester.second}`
+        },
+        {
+          label: `${year.toString()} 前期`,
+          value: `${year} ${Semester.first}`
+        }
+      ];
+    })
 )
 
Suggestion importance[1-10]: 7

Why: この提案はコードの重複を減らし、可読性と効率を向上させますが、機能的な変更はありません。したがって、重要度は中程度です。

7

Previous suggestions

Suggestions up to commit b2c66f3
CategorySuggestion                                                                                                                                    Score
Possible bug
semester の値を適切に検証し、Semester 型として正しく扱うように改善します。

stringToObject 関数で、semester の値を Number に変換していますが、Semester 型として扱うべきです。Number から Semester
への変換が不適切な場合、不正な値が発生する可能性があります。semester の値を適切に変換するための検証ロジックを追加してください。

src/components/UI/FormProjectDuration.vue [63-66]

-const [year, semester] = value.split(' ')
+const [year, semesterStr] = value.split(' ')
+const semester = parseInt(semesterStr)
+if (!Object.values(Semester).includes(semester)) {
+  throw new Error('Invalid semester value')
+}
 return {
   year: Number(year),
-  semester: Number(semester) as Semester
+  semester: semester as Semester
 }
 
Suggestion importance[1-10]: 9

Why: This suggestion addresses a potential bug by adding validation logic to ensure that the semester value is correctly converted to the Semester type, preventing invalid values.

9
Possible issue
options が未定義または空の場合のエラーを防ぐために、存在確認を追加します。

computed プロパティ untilOptionsoptions.value を展開していますが、options
が未定義または空の場合、エラーが発生する可能性があります。options の存在を確認する条件を追加することで、この問題を防ぐことができます。

src/components/UI/FormProjectDuration.vue [46]

-...options.value
+...(options.value || [])
 
Suggestion importance[1-10]: 8

Why: Adding a check for options existence prevents potential runtime errors, enhancing the stability of the code.

8
Enhancement
undefined を返す代わりに、デフォルトの文字列を返すように改善します。

objectToString 関数で undefined を返す場合がありますが、この関数の戻り値を直接 model-value にバインドしています。これにより、意図しない
undefined の値がコンポーネントに渡される可能性があります。戻り値が undefined の場合には、デフォルトの文字列を返すように修正してください。

src/components/UI/FormProjectDuration.vue [51-52]

 if (value === undefined) {
-  return undefined
+  return '未定'
 }
 
Suggestion importance[1-10]: 7

Why: Returning a default string instead of undefined improves robustness by ensuring that the component does not receive unintended undefined values.

7
不要な toString() 呼び出しを削除してコードを簡潔にします。

computed で生成される options 配列のラベルに年度と学期を表示していますが、toString()
メソッドを使用して年度を文字列に変換しています。これにより、不要な文字列変換が発生しています。テンプレートリテラル内で直接数値を使用することで、コードの簡潔性を向上させることができます。

src/components/UI/FormProjectDuration.vue [32-33]

-label: `${(currentYear - i).toString()} 後期`,
+label: `${currentYear - i} 後期`,
 value: `${currentYear - i} ${Semester.second}`
 
Suggestion importance[1-10]: 5

Why: Removing the unnecessary toString() call simplifies the code, but the improvement is minor and does not address any functional issues.

5
Suggestions
CategorySuggestion                                                                                                                                    Score
Possible bug
Add validation for semester values before casting to ensure type safety

Validate the semester value before casting it to Semester type to ensure it matches
expected enum values, preventing runtime errors.

src/components/UI/FormProjectDuration.vue [55-64]

-semester: Number(semester) as Semester
+semester: isValidSemester(semester) ? Number(semester) as Semester : undefined
 
Suggestion importance[1-10]: 9

Why: Adding validation for the semester value before casting it to the Semester type prevents potential runtime errors, enhancing the robustness of the code.

9
Maintainability
Refactor redundant string formatting into a utility function

Consider using a utility function to handle the conversion of year and semester values to
a string format. This will reduce redundancy and improve maintainability.

src/components/UI/FormProjectDuration.vue [85-106]

-`${model.since.year} ${model.since.semester}`
-`${model.until.year} ${model.until.semester}`
+`formatYearSemester(model.since)`
+`formatYearSemester(model.until)`
 
Suggestion importance[1-10]: 8

Why: This suggestion improves code maintainability by reducing redundancy, making the code easier to manage and less error-prone.

8
Refactor model value update logic into a separate function

Extract the logic for updating model.value based on dateType into a separate function to
improve code readability and maintainability.

src/components/UI/FormProjectDuration.vue [49-67]

-model.value = {
-  since: dateType === 'since' ? value !== undefined ? { year: Number(year), semester: Number(semester) as Semester } : undefined : model.value.since,
-  until: dateType === 'until' ? value !== undefined ? { year: Number(year), semester: Number(semester) as Semester } : undefined : model.value.until
-}
+model.value = updateModelValue(dateType, value, year, semester)
 
Suggestion importance[1-10]: 8

Why: Extracting the logic for updating model.value into a separate function enhances code readability and maintainability by isolating complex logic.

8
Enhancement
Convert sinceOptions to a computed property to enhance reactivity

Use a computed property for generating sinceOptions and untilOptions based on
props.sinceRequired to improve reactivity and encapsulation of logic.

src/components/UI/FormProjectDuration.vue [44]

-const sinceOptions = props.sinceRequired ? options : untilOptions
+const sinceOptions = computed(() => props.sinceRequired ? options : untilOptions)
 
Suggestion importance[1-10]: 7

Why: Using a computed property for sinceOptions improves reactivity and encapsulates the logic, making the code more maintainable and easier to understand.

7

@mehm8128
Copy link
Contributor Author

メモ
処理をまとめる
options関連のをcomputedで囲む

@mehm8128
Copy link
Contributor Author

:kan:

...options.value
])
const sinceOptions = computed(() =>
props.sinceRequired ? options.value : untilOptions.value
Copy link
Member

Choose a reason for hiding this comment

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

どういう構造になってるか分からないけどsinceがrequiredじゃないときってある?(このpropいる?の意味)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

確かにこれ命名よくないですね、sinceがrequiredというかuntilがoptionalかどうかのpropsです

Copy link
Member

Choose a reason for hiding this comment

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

それで言うとuntilも常にoptionalかも

Copy link
Contributor Author

Choose a reason for hiding this comment

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

確かにsince-required指定してないところなかったのでpropsごと消しちゃいます

Comment on lines 49 to 70
// 出力。stringをオブジェクトに変換して出力
const handleInput = (value: string | undefined, dateType: DateType) => {
const [year, semester] = value?.split(' ') ?? [undefined, undefined]
const newValue = {
year: Number(year),
semester: Number(semester) as Semester
}

const handleInput = (
value: YearWithSemester | undefined,
dateType: DateType
) => {
model.value = {
since: dateType === 'since' ? value : model.value.since,
until: dateType === 'until' ? value : model.value.until
since:
dateType === 'since'
? value !== undefined
? newValue
: undefined
: model.value.since,
until:
dateType === 'until'
? value !== undefined
? newValue
: undefined
: model.value.until
}
Copy link
Member

Choose a reason for hiding this comment

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

ここDateTypeを使ってるのが分かりにくくなってそうだからstring->objectの部分だけ関数に切り出して@update:model-value=""の中に直接書くのが読みやすそうに見えます

Copy link
Member

Choose a reason for hiding this comment

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

ついでにobject->stringも関数で書くとコメントじゃなくてコードで伝わりそう

Copy link
Contributor Author

Choose a reason for hiding this comment

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

なんかめっちゃ簡単にできました:kansya_kansya:
再度動作確認お願いします:pray:

@Pugma
Copy link
Collaborator

Pugma commented Jul 4, 2024

/improve

@mehm8128 mehm8128 requested a review from ras0q July 4, 2024 14:10
@mehm8128
Copy link
Contributor Author

mehm8128 commented Jul 4, 2024

/improve

year: Number(year),
semester: Number(semester) as Semester
// ラベルとして表示する文字列
const objectToString = (value: YearWithSemester | undefined) => {
Copy link
Member

Choose a reason for hiding this comment

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

流石に関数名抽象的過ぎるけどいい代替が思いつかない
encodeYearWithSemester decodeYearWithSemester とか
最悪yearWithSemesterToStringとかでもいいけど

Comment on lines 49 to 51
if (value === undefined) {
return undefined
}
Copy link
Member

Choose a reason for hiding this comment

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

undefined受け取ってるのにundefinedが来たらundefined返すのちょっと違和感ある
ここは変に関数に閉じ込め過ぎずに変更前と同じように↓くらいの方が個人的に見やすいです
逆操作の方も同様

:model-value="model.since ? objectToString(model.since) : undefined"

Comment on lines 32 to 33
label: `${(currentYear - i).toString()} 後期`,
value: `${currentYear - i} ${Semester.second}`
Copy link
Member

Choose a reason for hiding this comment

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

toStringなくてよさそう

@mehm8128 mehm8128 requested a review from ras0q July 4, 2024 14:51
Copy link
Member

@ras0q ras0q left a comment

Choose a reason for hiding this comment

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

👍🏻

@mehm8128 mehm8128 merged commit 695eccb into main Jul 4, 2024
9 checks passed
@mehm8128 mehm8128 deleted the fix/project_duration branch July 4, 2024 15:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants