feat: enable save button only when form is modified#5927
Conversation
Signed-off-by: yuda <yuda@megazone.com>
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
2 Skipped Deployments
|
|
✅ There are no commits in this PR that require review. |
|
🎉 @skdud4659 has been randomly selected as the reviewer! Please review. 🙏 |
There was a problem hiding this comment.
Pull Request Overview
This PR ensures the Save button is only enabled when form values differ from the loaded configuration.
- Adds a new
isFormChangedcomputed property that deep-compares form state against the initial config - Updates the Save button’s
disabledbinding to include!isFormChanged - Imports
isEqualfrom lodash for comparison
Comments suppressed due to low confidence (2)
apps/web/src/services/cost-explorer/components/AdvancedSettingsCostReportConfiguration.vue:67
- [nitpick] The name
isFormChangedis a bit generic; consider renaming toisFormModifiedorhasUnsavedChangesfor clearer intent.
const isFormChanged = computed<boolean>(() => !isEqual(state.selectedLanguage, costReportConfig.value?.language)
apps/web/src/services/cost-explorer/components/AdvancedSettingsCostReportConfiguration.vue:289
- There's no existing test to verify the Save button toggles based on form modifications; adding a unit or integration test for this behavior would help prevent regressions.
:disabled="isSaveDisabled || !isFormChanged"
| const isFormChanged = computed<boolean>(() => !isEqual(state.selectedLanguage, costReportConfig.value?.language) | ||
| || !isEqual(state.selectedCurrency, costReportConfig.value?.currency) | ||
| || !isEqual(Number(issueDate.value), Number(costReportConfig.value?.issue_day)) | ||
| || !isEqual(state.lastDayOfMonth, !!costReportConfig.value?.is_last_day) | ||
| || !isEqual(state.enableAdjustments, !!costReportConfig.value?.adjustment_options?.enabled) | ||
| || !isEqual(Number(manualAdjustablePeriod.value), Number(costReportConfig.value?.adjustment_options?.period))); | ||
|
|
There was a problem hiding this comment.
Manually comparing each field can become hard to maintain as new settings are added; consider capturing the form state as an object and doing a single deep compare against a snapshot of the initial values.
| const isFormChanged = computed<boolean>(() => !isEqual(state.selectedLanguage, costReportConfig.value?.language) | |
| || !isEqual(state.selectedCurrency, costReportConfig.value?.currency) | |
| || !isEqual(Number(issueDate.value), Number(costReportConfig.value?.issue_day)) | |
| || !isEqual(state.lastDayOfMonth, !!costReportConfig.value?.is_last_day) | |
| || !isEqual(state.enableAdjustments, !!costReportConfig.value?.adjustment_options?.enabled) | |
| || !isEqual(Number(manualAdjustablePeriod.value), Number(costReportConfig.value?.adjustment_options?.period))); | |
| const initialFormState = computed(() => ({ | |
| selectedLanguage: costReportConfig.value?.language, | |
| selectedCurrency: costReportConfig.value?.currency, | |
| issueDate: Number(costReportConfig.value?.issue_day), | |
| lastDayOfMonth: !!costReportConfig.value?.is_last_day, | |
| enableAdjustments: !!costReportConfig.value?.adjustment_options?.enabled, | |
| manualAdjustablePeriod: Number(costReportConfig.value?.adjustment_options?.period), | |
| })); | |
| const isFormChanged = computed<boolean>(() => !isEqual(state, initialFormState.value)); |
Skip Review (optional)
style,chore,ci,test,docs)Description (optional)
Things to Talk About (optional)