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

Nc feat/form validation #8409

Merged
merged 61 commits into from
May 9, 2024
Merged

Nc feat/form validation #8409

merged 61 commits into from
May 9, 2024

Conversation

rameshmane7218
Copy link
Collaborator

Change Summary

Provide summary of changes with issue number if any.

Change type

  • feat: (new feature for the user, not a new feature for build script)
  • fix: (bug fix for the user, not a fix to a build script)
  • docs: (changes to the documentation)
  • style: (formatting, missing semi colons, etc; no production code change)
  • refactor: (refactoring production code, eg. renaming a variable)
  • test: (adding missing tests, refactoring tests; no production code change)
  • chore: (updating grunt tasks etc; no production code change)

Test/ Verification

Provide summary of changes.

Additional information / screenshots (optional)

Anything for maintainers to be made aware of

Copy link
Contributor

coderabbitai bot commented May 6, 2024

Walkthrough

Walkthrough

The recent updates aim to enhance form functionalities and validation processes within the nc-gui package. Changes include adding new properties and functions to improve user interactions, updating templates for better data handling, and streamlining components by removing unused declarations. The SDK has been expanded with new validation types and interfaces, providing a more comprehensive toolset for form validation and management.

Changes

Files Summary
.../cell/Currency.vue, .../cell/Decimal.vue, .../cell/Percent.vue Added placeholder properties and updated template bindings. Currency.vue also includes a hidePrefix property.
.../cell/PhoneNumber.vue Renamed isSurveyForm to isForm and adjusted usage for improved logic.
.../cell/attachment/index.vue Introduced removeFile function for file handling and added a close circle icon for file removal UI.
.../smartsheet/Form.vue Streamlined the component by removing unused declarations and functions.
.../smartsheet/form/field-config-error.vue, .../smartsheet/form/field-settings.vue Added new files for handling field configuration errors and managing field settings.
.../composables/useSharedFormViewStore.ts, .../composables/useViewData.ts Updated validation and form handling logic, with significant changes in imported modules and functions.
.../pages/index/[...]/form/[...]/index/index.vue, .../pages/index/[...]/form/[...]/index/survey.vue Adjusted imports and modified function parameters to align with updated form validation logic.
.../utils/formValidations.ts, .../utils/iconUtils.ts Expanded utilities with new validators and an icon for enhanced form validation capabilities and UI elements.
nocodb-sdk/src/lib/form.ts, nocodb-sdk/src/lib/index.ts Expanded the SDK with new validation types and interfaces, and exposed the form module for broader use.

These changes reflect a concerted effort to improve form-related features and validation mechanisms, enhancing the overall user experience and application functionality.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Out of diff range and nitpick comments (5)
packages/nc-gui/components/cell/PhoneNumber.vue (1)

[!TIP]
Codebase Verification

The search results indicate that the identifier isSurveyForm is still being used in multiple Vue components within the packages/nc-gui/components/cell directory. This contradicts the expectation that all occurrences should have been replaced by isForm. The presence of isSurveyForm in these files suggests that the renaming might not have been fully implemented across all relevant components, or that both identifiers are being used for potentially different purposes.

Files still using isSurveyForm:

  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/cell/SingleSelect.vue
  • packages/nc-gui/components/cell/RichText.vue
  • packages/nc-gui/components/cell/MultiSelect.vue
  • packages/nc-gui/components/cell/Checkbox.vue
Analysis chain

Line range hint 4-37: Renaming to isForm and updates to phone number validation logic.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the impact of renaming `isSurveyForm` to `isForm` on other components.

# Test: Search for occurrences of `isSurveyForm`. Expect: No occurrences, should be replaced by `isForm`.
rg --type vue 'isSurveyForm' 'packages/nc-gui/components/cell'

Length of output: 88



Script:

#!/bin/bash
# Description: Verify the impact of renaming `isSurveyForm` to `isForm` on other components.

# Test: Search for occurrences of `isSurveyForm`. Expect: No occurrences, should be replaced by `isForm`.
rg 'isSurveyForm' 'packages/nc-gui/components/cell'

Length of output: 1205

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (2)

195-195: Consider adding documentation for handleAddMissingRequiredFieldDefaultState.

The function handleAddMissingRequiredFieldDefaultState is called without any comments or documentation. Adding a brief comment describing its purpose and usage can improve code readability and maintainability.


564-587: Ensure consistent styling rules in scoped and global styles.

The component mixes scoped and global styles, which might lead to styling conflicts or unexpected behaviors. Consider reviewing the necessity of global styles or ensure that they are scoped properly to avoid affecting other components unintentionally.

packages/nc-gui/components/smartsheet/Form.vue (2)

250-250: Clarify the purpose of clearValidate in comments for better maintainability.

Consider adding a comment explaining the purpose of clearValidate to improve code readability and maintainability.


1481-1498: Review the logic for disabling the switch based on field requirements.

Consider reviewing the logic for disabling the switch based on field requirements to ensure it aligns with the intended functionality.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2d1c743 and 6d943bf.
Files ignored due to path filters (1)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
Files selected for processing (19)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (3 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (22 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (14 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/composables/useViewFilters.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nc-gui/utils/index.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review due to trivial changes (5)
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/composables/useViewFilters.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (13)
packages/nc-gui/utils/index.ts (1)

28-28: Export of formValidations module added.

Verification successful

The verification process aimed to confirm the existence and correct implementation of the formValidations module in the packages/nc-gui/utils directory. The results from the executed scripts provide the following information:

  1. The formValidations.ts file exists within the specified directory, as confirmed by the fd command.
  2. The rg command, which was intended to detect basic syntax errors by searching for the phrase "syntax error" within the formValidations.ts file, did not return any results. This suggests that there are no overt syntax errors labeled as such in the file.

Given this information, it appears that the formValidations module exists and does not contain basic syntax errors as per the search criteria used. Therefore, the export addition in the index.ts file is correctly referencing an existing module without apparent syntax issues.

Export of formValidations module verified.

  • The module exists in the expected directory.
  • No basic syntax errors were detected in the module.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the existence and correct implementation of the `formValidations` module.

# Test: Search for the `formValidations.ts` file. Expect: File should exist.
fd --type file 'formValidations.ts' 'packages/nc-gui/utils'

# Test: Check for basic syntax errors in the `formValidations.ts` file.
rg --type ts -N 'syntax error' 'packages/nc-gui/utils/formValidations.ts'

Length of output: 172

packages/nocodb-sdk/src/lib/form.ts (1)

1-83: Comprehensive addition of validation types and enums.

packages/nc-gui/utils/formValidations.ts (1)

1-109: Addition of form validation functions for email, phone number, URL, and number inputs.

packages/nc-gui/components/cell/Decimal.vue (1)

Line range hint 10-106: Addition of placeholder prop to enhance flexibility in decimal input handling.

Verification successful

The verification of the placeholder prop in the Decimal.vue file has been successful. The prop is defined in the component's props and is used correctly in the template. The usage includes a conditional expression that checks if placeholder is defined; if not, it defaults to a localized string if isEditColumn is true, otherwise, it defaults to an empty string. This ensures that the placeholder text is appropriately internationalized and dynamically set based on the component's state.

Conclusion:

  • The placeholder prop is correctly defined and used within the component.
  • The prop's usage in the template includes proper internationalization.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the internationalization and usage of the `placeholder` prop in `Decimal.vue`.

# Test: Search for usage of the `placeholder` prop in the template. Expect: Correct internationalization and usage.
rg --type vue 'placeholder' 'packages/nc-gui/components/cell/Decimal.vue'

Length of output: 99



Script:

#!/bin/bash
# Description: Verify the internationalization and usage of the `placeholder` prop in `Decimal.vue`.

# Test: Search for usage of the `placeholder` prop in the template. Expect: Correct internationalization and usage.
rg 'placeholder' 'packages/nc-gui/components/cell/Decimal.vue'

Length of output: 186

packages/nc-gui/components/cell/Currency.vue (1)

Line range hint 18-123: Addition of placeholder and hidePrefix props to enhance flexibility in currency input handling.

Verification successful

The verification of the placeholder and hidePrefix props in the Currency.vue file has been successful. The script output confirms that both properties are correctly utilized within the template:

  • The hidePrefix property is used in a conditional rendering statement to determine whether to display the currency prefix.
  • The placeholder property is used to set the placeholder text of an input element, with a fallback to a localized string if placeholder is not defined.

This confirms that the implementation aligns with the intended functionality as described in the review comment.

Correct Usage of placeholder and hidePrefix Properties:

  • hidePrefix is used to conditionally hide the currency prefix in the component based on the property's value.
  • placeholder provides a dynamic placeholder text for the input field, which can default to a localized label if not specified.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct usage of `placeholder` and `hidePrefix` props in `Currency.vue`.

# Test: Search for usage of the `placeholder` and `hidePrefix` props in the template. Expect: Correct usage and functioning of the prefix hiding logic.
rg --type vue 'placeholder|hidePrefix' 'packages/nc-gui/components/cell/Currency.vue'

Length of output: 113



Script:

#!/bin/bash
# Description: Re-verify the correct usage of `placeholder` and `hidePrefix` props in `Currency.vue`.

# Test: Search for usage of the `placeholder` and `hidePrefix` props in the template. Expect: Correct usage and functioning of the prefix hiding logic.
rg 'placeholder|hidePrefix' 'packages/nc-gui/components/cell/Currency.vue'

Length of output: 273

packages/nc-gui/components/smartsheet/form/field-settings.vue (1)

8-18: Addition of updateSelectFieldLayout and columnSupportsScanning functions to enhance field configurability in forms.

Verification successful

The verification of the updateSelectFieldLayout and columnSupportsScanning functions in the field-settings.vue file has been successful. The script output confirms that both functions are defined and used within the Vue template. Specifically:

  • The updateSelectFieldLayout function is triggered by an event (@update:value), which is a common pattern in Vue.js for reacting to user inputs.
  • The columnSupportsScanning function is used within a conditional rendering directive (v-if), which is appropriate for controlling the display of elements based on the type of the active field.

This confirms that the functions are not only present but are also integrated into the component's logic as intended.

Conclusion:
The addition and usage of updateSelectFieldLayout and columnSupportsScanning functions are correctly implemented in the field-settings.vue file. This enhances the configurability and functionality of the form fields as intended in the pull request.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct implementation and usage of `updateSelectFieldLayout` and `columnSupportsScanning` functions in `field-settings.vue`.

# Test: Search for usage of these functions in the template. Expect: Correct implementation and usage.
rg --type vue 'updateSelectFieldLayout|columnSupportsScanning' 'packages/nc-gui/components/smartsheet/form/field-settings.vue'

Length of output: 154



Script:

#!/bin/bash
# Description: Re-verify the correct implementation and usage of `updateSelectFieldLayout` and `columnSupportsScanning` functions in `field-settings.vue`.

# Test: Search for usage of these functions in the template. Expect: Correct implementation and usage.
rg 'updateSelectFieldLayout|columnSupportsScanning' packages/nc-gui/components/smartsheet/form/field-settings.vue

Length of output: 393

packages/nc-gui/composables/useFormViewStore.ts (1)

1-138: Comprehensive management of form view state and utilities.

Verification successful

The shell script output indicates that the hooks and utilities from useFormViewStore.ts are being used in multiple composables within the packages/nc-gui/composables directory. Specifically, useForm and useProvideFormViewStore are utilized in useFormViewStore.ts, useSharedFormViewStore.ts, and useColumnCreateStore.ts. This suggests that the hooks are being reused across different modules, which is generally a good practice for maintaining consistency and reducing code duplication.

However, the script was primarily focused on finding occurrences of useForm and useProvideFormViewStore. To fully verify the correct usage and performance of these hooks and utilities, we would need to inspect how they are integrated within each composable and ensure that there are no performance issues or incorrect implementations.

Given the current output, there is no direct evidence of misuse or performance issues, but a deeper inspection into how these hooks are used in context would be necessary for a comprehensive verification.

Conclusion

The hooks and utilities from useFormViewStore.ts are being reused in multiple composables, which is a positive sign of modular and reusable code. However, for a complete verification of correct usage and performance, further detailed code review or runtime profiling would be required.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the correct usage and performance of hooks and utilities in `useFormViewStore.ts`.

# Test: Search for usage of hooks and utilities from `useFormViewStore.ts`. Expect: Correct usage and no performance issues.
rg --type ts 'useForm|useProvideFormViewStore' 'packages/nc-gui/composables'

Length of output: 1295

packages/nc-gui/components/cell/attachment/index.vue (1)

78-78: Ensure proper error handling for removeFile function.

packages/nc-gui/composables/useViewData.ts (1)

307-307: Ensure that validators array initialization is correctly implemented and used.

Verification successful

The initialization and usage of the validators array in the useViewData composable appear to be correctly implemented. The array is initialized as empty and is designed to be overridden by metadata properties from fieldById and c.meta, which is consistent with patterns observed in other parts of the codebase. This approach allows for dynamic handling of validation rules based on field-specific metadata, aligning with the design seen in related composables.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the `validators` array is correctly initialized and used within the composable.

# Test: Search for usage of `validators` array. Expect: Proper initialization and usage in validation logic.
rg --type ts $'validators'

Length of output: 1439

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (1)

176-276: Review form validation logic to ensure it meets the requirements.

Verification successful

The verification of the form validation logic in the file packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue has been successful. The script output confirms the presence of validation logic within this specific file, as indicated by multiple instances of the validate function and validateInfos being used. This suggests that the form validation logic is indeed implemented and likely aligns with the requirements as it is actively used in the form component.

  • The validate function is called directly and also bound to UI events to ensure fields are validated on updates.
  • The validateInfos object is used to bind validation rules to form fields, indicating a structured approach to validation.

This comprehensive use of validation mechanisms within the form component confirms that the form validation logic is implemented as expected.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the form validation logic is comprehensive and aligns with the requirements.

# Test: Search for validation logic in the form component. Expect: Comprehensive validation rules that align with the requirements.
rg --type vue $'validate'

Length of output: 52



Script:

#!/bin/bash
# Description: Verify that the form validation logic is comprehensive and aligns with the requirements.

# Test: Search for validation logic in the form component. Expect: Comprehensive validation rules that align with the requirements.
rg --type vue -g '*.vue' 'validate' .

Length of output: 65



Script:

#!/bin/bash
# Description: Verify that the form validation logic is comprehensive and aligns with the requirements.

# Test: Search for validation logic in the form component. Expect: Comprehensive validation rules that align with the requirements.
rg -g '*.vue' 'validate' .

Length of output: 29555

packages/nc-gui/composables/useSharedFormViewStore.ts (1)

218-250: Ensure that the form validation rules are correctly implemented and cover all necessary cases.

Verification successful

The form validation rules in the useSharedFormViewStore.ts file are implemented using a combination of computed properties and utility functions, which is consistent with other parts of the codebase. The use of extractFieldValidator to dynamically add validation rules based on column metadata suggests that the implementation is designed to be flexible and comprehensive.

  • The extractFieldValidator function is utilized in multiple composables, indicating a shared approach to handling additional validation rules.
  • The use of computed properties for validators in various stores supports a reactive validation pattern, which is typical in Vue.js applications.

Overall, the implementation appears to be correctly set up to handle the necessary validation cases dynamically and reactively.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify that the form validation rules are correctly implemented and cover all necessary cases.

# Test: Search for the implementation of form validation rules. Expect: Comprehensive and correct implementation of validation rules.
rg --type ts $'validators'

Length of output: 1439

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (1)

377-495: Review the use of dynamic references in Vue templates.

The template uses dynamic references such as :key="field?.title" which can lead to re-rendering issues if field.title changes unexpectedly. Verify that the field titles are stable or consider using a more stable property for keys.

packages/nc-gui/components/smartsheet/Form.vue (1)

102-115: Ensure proper error handling in useProvideFormViewStore.

Copy link
Contributor

github-actions bot commented May 6, 2024

Uffizzi Preview deployment-51296 was deleted.

@o1lab o1lab force-pushed the nc-feat/form-validation branch from 6d943bf to 0e30071 Compare May 6, 2024 11:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 8

Out of diff range and nitpick comments (1)
packages/nc-gui/composables/useSharedFormViewStore.ts (1)

43-43: Consider using a more specific import for Form.useForm to avoid potential confusion.

It's generally a good practice to import specific functions directly from their modules to avoid confusion and potential errors in larger projects. Consider changing the import statement to something like import { useForm } from 'ant-design-vue/es/form'.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 2d1c743 and 0e30071.
Files ignored due to path filters (2)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
  • packages/nc-gui/lang/en.json is excluded by !**/*.json
Files selected for processing (19)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (3 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (22 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (14 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/composables/useViewFilters.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nc-gui/utils/index.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (16)
  • packages/nc-gui/components/cell/Currency.vue
  • packages/nc-gui/components/cell/Decimal.vue
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/cell/PhoneNumber.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/components/smartsheet/form/field-settings.vue
  • packages/nc-gui/composables/useFormViewStore.ts
  • packages/nc-gui/composables/useViewData.ts
  • packages/nc-gui/composables/useViewFilters.ts
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  • packages/nc-gui/utils/formValidations.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nc-gui/utils/index.ts
  • packages/nocodb-sdk/src/lib/form.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (7)
packages/nc-gui/composables/useSharedFormViewStore.ts (1)

553-553: Ensure that clearValidate is called in all necessary scenarios.

The clearValidate function is called in several places, but it's important to ensure that it's being called in all scenarios where the form validation state needs to be reset. Consider adding additional calls to clearValidate where necessary.

packages/nc-gui/components/smartsheet/Form.vue (6)

221-226: Ensure proper handling of undefined form fields.

This comment is still valid as the proposed change ensures that undefined required fields are set to null only if they fail validation.


228-228: Add error handling for the validate function to manage exceptions properly.

This comment is still valid as it suggests adding error handling to manage exceptions during form validation.


616-616: Ensure that validate function handles all potential exceptions.

This comment is still valid as it suggests ensuring that all potential exceptions are handled in the validate function.


221-228: The form submission logic appears correctly implemented.

Ensure that the form validation and submission process is thoroughly tested, especially the new validation logic.


250-250: The form clearing logic is correctly implemented.

Ensure that the form clearing process works as expected, especially in conjunction with the form reload functionality.


1481-1498: The field visibility toggle logic is correctly implemented.

Ensure that the visibility toggle works as expected, especially in scenarios where fields are required or the form is locked.

@@ -186,6 +196,7 @@

handlePreFillForm()
} catch (e: any) {
console.log('err', e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error handling by providing more specific error messages.

The error handling in the loadSharedView function logs a generic error message. It would be beneficial for debugging and user feedback to log more specific error messages based on the type of error encountered.

Comment on lines 218 to 224
const rulesObj: Record<string, RuleObject[]> = {}

if (!formColumns.value) return obj
if (!formColumns.value) return rulesObj

for (const column of formColumns.value) {
if (
!isVirtualCol(column) &&
((column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)) || column.required)
) {
obj.localState[column.title!] = {
required: fieldRequired(undefined, !!(column.uidt === UITypes.Checkbox && column.required)),
}
} else if (
isLinksOrLTAR(column) &&
column.colOptions &&
(column.colOptions as LinkToAnotherRecordType).type === RelationTypes.BELONGS_TO
) {
const col = columns.value?.find((c) => c.id === (column?.colOptions as LinkToAnotherRecordType)?.fk_child_column_id)
let rules: RuleObject[] = []

rules.push({
validator: (_rule: RuleObject, value: any) => {
return new Promise((resolve, reject) => {
if (isRequired(column)) {
if (column.uidt === UITypes.Checkbox && !value) {
return reject(t('msg.error.fieldRequired', { value: 'This field' }))
} else if (column.uidt !== UITypes.Checkbox)
if (value === null || !value?.length) {
return reject(t('msg.error.fieldRequired', { value: 'This field' }))
}
}
return resolve()
})
},
})

if ((col && col.rqd && !col.cdf) || column.required) {
if (col) {
obj.virtual[column.title!] = { required: fieldRequired() }
}
}
} else if (isVirtualCol(column) && column.required) {
obj.virtual[column.title!] = {
minLength: minLength(1),
required: fieldRequired(),
}
const additionalRules = extractFieldValidator(parseProp(column.meta).validators ?? [], column)
rules = [...rules, ...additionalRules]

if (rules.length) {
rulesObj[column.title!] = rules
}
}

return rulesObj
})
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize the validation rules setup for better performance and readability.

The setup for validation rules in the validators computed property is quite complex and could be optimized for better performance and readability. Consider breaking down the rule setup into smaller functions or using a more declarative approach to define the rules.

@o1lab o1lab force-pushed the nc-feat/form-validation branch from 0e30071 to 72b915e Compare May 7, 2024 06:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 08dfcfa and 72b915e.
Files ignored due to path filters (2)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
  • packages/nc-gui/lang/en.json is excluded by !**/*.json
Files selected for processing (19)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (4 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (3 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (22 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (14 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/composables/useViewFilters.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nc-gui/utils/index.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (17)
  • packages/nc-gui/components/cell/Currency.vue
  • packages/nc-gui/components/cell/Decimal.vue
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/cell/PhoneNumber.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/components/smartsheet/form/field-settings.vue
  • packages/nc-gui/composables/useFormViewStore.ts
  • packages/nc-gui/composables/useViewData.ts
  • packages/nc-gui/composables/useViewFilters.ts
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue
  • packages/nc-gui/utils/formValidations.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nc-gui/utils/index.ts
  • packages/nocodb-sdk/src/lib/form.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (4)
packages/nc-gui/composables/useSharedFormViewStore.ts (4)

149-163: Refactor default value setting to reduce complexity.

This comment is still valid as the logic for setting default values based on the column type is quite verbose and repetitive. Consider creating a helper function that handles the setting of default values based on the column type to make this code cleaner and more maintainable.


199-199: Improve error handling by providing more specific error messages.

This comment is still valid. The error handling in the loadSharedView function logs a generic error message. It would be beneficial for debugging and user feedback to log more specific error messages based on the type of error encountered.


218-250: Optimize the validation rules setup for better performance and readability.

This comment is still valid as the setup for validation rules in the validators computed property is quite complex and could be optimized for better performance and readability. Consider breaking down the rule setup into smaller functions or using a more declarative approach to define the rules.


256-256: Ensure proper cleanup of form validation state.

This comment is still valid. The useForm hook is used here to manage form validation state, but there's no clear mechanism for cleaning up this state when the component is unmounted or when the form is reset. Consider adding a cleanup function to properly reset the validation state.

@o1lab o1lab force-pushed the nc-feat/form-validation branch 5 times, most recently from b497075 to 8d4f141 Compare May 8, 2024 12:52
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 34a0003 and 8d4f141.
Files ignored due to path filters (2)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
  • packages/nc-gui/lang/en.json is excluded by !**/*.json
Files selected for processing (17)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (2 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (22 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (13 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (14)
  • packages/nc-gui/components/cell/Currency.vue
  • packages/nc-gui/components/cell/Decimal.vue
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/cell/PhoneNumber.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/components/smartsheet/form/field-settings.vue
  • packages/nc-gui/composables/useFormViewStore.ts
  • packages/nc-gui/composables/useViewData.ts
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  • packages/nc-gui/utils/formValidations.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nocodb-sdk/src/lib/form.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (15)
packages/nc-gui/composables/useSharedFormViewStore.ts (6)

78-84: Ensure consistent filtering logic for form columns.


124-138: Refactor default value setting to reduce complexity.


174-174: Improve error handling by providing more specific error messages.


193-225: Optimize the validation rules setup for better performance and readability.


231-231: Ensure proper cleanup of form validation state.


528-528: Ensure that clearValidate is called appropriately to reset validation states.

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (4)

20-34: Consider using TypeScript's utility types for destructuring with better type safety.


80-80: Add error handling for missing validateInfos entries.


112-118: Refactor validateField to handle exceptions more transparently.


196-196: Optimize the conditional checks in showSubmitConfirmModal.

packages/nc-gui/components/smartsheet/Form.vue (5)

194-199: Ensure proper handling of undefined form fields.


201-201: Add error handling for the validate function to manage exceptions properly.


589-589: Ensure that validate function handles all potential exceptions.


223-223: Implementation of clearForm looks good.


223-223: Implementation of onMove function looks good.

@o1lab o1lab force-pushed the nc-feat/form-validation branch from 8d4f141 to aceeceb Compare May 8, 2024 13:02
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Out of diff range and nitpick comments (1)
packages/nc-gui/components/smartsheet/Form.vue (1)

Line range hint 862-1136: Review the form layout and ensure accessibility and responsiveness.

Consider reviewing the form layout to ensure it is accessible and responsive. This includes checking for proper use of ARIA attributes and ensuring that the form is usable on all devices and screen sizes.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 34a0003 and aceeceb.
Files ignored due to path filters (2)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
  • packages/nc-gui/lang/en.json is excluded by !**/*.json
Files selected for processing (16)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (3 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (22 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (13 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (13)
  • packages/nc-gui/components/cell/Currency.vue
  • packages/nc-gui/components/cell/Decimal.vue
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/cell/PhoneNumber.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/components/smartsheet/form/field-settings.vue
  • packages/nc-gui/composables/useFormViewStore.ts
  • packages/nc-gui/composables/useViewData.ts
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  • packages/nc-gui/utils/formValidations.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nocodb-sdk/src/lib/form.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (13)
packages/nc-gui/composables/useSharedFormViewStore.ts (7)

18-19: Consider removing the unused constant useForm.


78-84: Ensure consistent filtering logic for form columns.


124-138: Refactor default value setting to reduce complexity.


174-174: Improve error handling by providing more specific error messages.


193-225: Optimize the validation rules setup for better performance and readability.


231-231: Ensure proper cleanup of form validation state.


528-528: Ensure that clearValidate is called appropriately to reset validation states.

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (4)

20-34: Consider using TypeScript's utility types for destructuring with better type safety.


80-80: Add error handling for missing validateInfos entries.


112-118: Refactor validateField to handle exceptions more transparently.


196-196: Optimize the conditional checks in showSubmitConfirmModal.

packages/nc-gui/components/smartsheet/Form.vue (2)

201-201: Ensure robust error handling in the validate function.

This is a duplicate of a previous comment made on an outdated commit, but it remains relevant. Proper error handling is crucial for maintaining the robustness of form validation processes.


589-589: Refactor error handling in the validate function to improve clarity and maintainability.

This is a duplicate of a previous comment made on an outdated commit, but it remains relevant. Refactoring error handling can help in better understanding and maintaining the code, especially when dealing with form validations.

@o1lab o1lab force-pushed the nc-feat/form-validation branch from aceeceb to bb51f2b Compare May 8, 2024 18:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 34a0003 and bb51f2b.
Files ignored due to path filters (2)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
  • packages/nc-gui/lang/en.json is excluded by !**/*.json
Files selected for processing (17)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (2 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (22 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (13 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (14)
  • packages/nc-gui/components/cell/Currency.vue
  • packages/nc-gui/components/cell/Decimal.vue
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/cell/PhoneNumber.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/components/smartsheet/form/field-settings.vue
  • packages/nc-gui/composables/useFormViewStore.ts
  • packages/nc-gui/composables/useViewData.ts
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  • packages/nc-gui/utils/formValidations.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nocodb-sdk/src/lib/form.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (17)
packages/nc-gui/composables/useSharedFormViewStore.ts (8)

15-15: Import of RuleObject from ant-design-vue/es/form added.

This import is necessary for the new validation logic introduced in the file.


78-84: Ensure consistent filtering logic for form columns.

This comment is still valid as the complexity in the filtering logic remains. Consider simplifying this logic or breaking it down into smaller, more testable functions.


124-138: Refactor default value setting to reduce complexity.

This comment is still valid as the logic for setting default values based on the column type is verbose and repetitive. Consider creating a helper function that handles the setting of default values based on the column type to make this code cleaner and more maintainable.


174-174: Improve error handling by providing more specific error messages.

This comment is still valid as the error handling in the loadSharedView function logs a generic error message. It would be beneficial for debugging and user feedback to log more specific error messages based on the type of error encountered.


193-225: Optimize the validation rules setup for better performance and readability.

This comment is still valid as the setup for validation rules in the validators computed property is quite complex and could be optimized for better performance and readability. Consider breaking down the rule setup into smaller functions or using a more declarative approach to define the rules.


231-231: Ensure proper cleanup of form validation state.

This comment is still valid as there's no clear mechanism for cleaning up the validation state when the component is unmounted or when the form is reset. Consider adding a cleanup function to properly reset the validation state.


528-528: Ensure that clearValidate is called appropriately to reset validation states.

This comment is still valid. The call to clearValidate should be accompanied by a comment explaining its purpose, especially in a complex function like watch. This helps maintain clarity in the code's intention, particularly for future maintainers or during debugging.


18-19: Consider removing the unused constant useForm.

This comment is still valid. This line defines useForm but it is not used anywhere in the provided code. Removing unused code helps in maintaining cleaner and more readable codebases.

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (4)

20-34: Consider using TypeScript's utility types for destructuring with better type safety.

This comment is still valid as the destructuring of useSharedFormStoreOrThrow() could benefit from TypeScript's utility types to ensure that all properties are correctly typed. This can prevent runtime errors due to incorrect property accesses and improve maintainability.


80-80: Add error handling for missing validateInfos entries.

This comment is still valid as the code assumes that validateInfos[field.value.title] will always be valid. Consider adding a check or a default value to handle cases where validateInfos does not have an entry for a given title to prevent runtime errors.


112-118: Refactor validateField to handle exceptions more transparently.

This comment is still valid as the catch block in validateField function uses a catch-all type any for the exception. It's a good practice to avoid using any and instead use a more specific error type or at least log the error for debugging purposes.

-  } catch (_e: any) {
+  } catch (_e: Error) {
+    console.error("Validation failed:", _e);
     return false
   }

196-196: Optimize the conditional checks in showSubmitConfirmModal.

This comment is still valid as the function showSubmitConfirmModal performs multiple checks in a single line, which can be refactored for better readability and efficiency. Consider separating these conditions or restructuring the function to early return on simpler conditions.

packages/nc-gui/components/smartsheet/Form.vue (5)

194-199: Consider initializing formState properties to null only if they are required and currently undefined.


201-201: Add error handling for the validate function to manage exceptions properly.


223-223: Ensure clearValidate is called only when necessary.


589-589: Ensure that validate function handles all potential exceptions.


1454-1471: Ensure that the logic for showing or hiding columns is clear and handles all edge cases.

@o1lab o1lab force-pushed the nc-feat/form-validation branch 2 times, most recently from 7c5eb55 to e263a8a Compare May 9, 2024 07:57
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

Out of diff range and nitpick comments (1)
packages/nc-gui/components/smartsheet/Form.vue (1)

Line range hint 860-1134: Review the form rendering logic for potential improvements in clarity and performance.

Consider simplifying the form rendering logic to improve readability and potentially enhance performance. This could involve breaking down complex conditional structures into smaller, more manageable components or using more computed properties to handle visibility and styling.

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 7c5eb55 and e263a8a.
Files ignored due to path filters (2)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
  • packages/nc-gui/lang/en.json is excluded by !**/*.json
Files selected for processing (17)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (2 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (22 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (12 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (14)
  • packages/nc-gui/components/cell/Currency.vue
  • packages/nc-gui/components/cell/Decimal.vue
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/cell/PhoneNumber.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/components/smartsheet/form/field-settings.vue
  • packages/nc-gui/composables/useFormViewStore.ts
  • packages/nc-gui/composables/useViewData.ts
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  • packages/nc-gui/utils/formValidations.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nocodb-sdk/src/lib/form.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (12)
packages/nc-gui/composables/useSharedFormViewStore.ts (6)

15-15: Added import for RuleObject from ant-design-vue/es/form.

This import is necessary for the new validation logic introduced in this file.


18-19: Consider removing the unused constant useForm.

This line defines useForm but it is not used anywhere in the provided code. Removing unused code helps in maintaining cleaner and more readable codebases.


124-138: Ensure correct handling of default values based on column types.

The logic to handle default values based on different column types (e.g., Number, Checkbox) is implemented correctly.


192-224: Refactor the validation rules setup for better performance and readability.

The setup for validation rules in the validators computed property is quite complex and could be optimized for better performance and readability. Consider breaking down the rule setup into smaller functions or using a more declarative approach to define the rules.


226-229: Ensure that validationFieldState correctly aggregates state for validation.

This computed property correctly combines formState and additionalState for validation purposes.


566-576: Ensure that the watcher for additionalState correctly triggers validation.

The watcher setup for additionalState is correctly configured to trigger validation when the state changes.

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (6)

20-34: Ensure that destructured imports from useSharedFormStoreOrThrow are used correctly.

The destructured imports are used throughout the component, ensuring that the component's functionality is maintained with the new store structure.


80-80: Validate that validateInfos is correctly accessed for error status.

The access pattern for validateInfos to check the validation status of a field is implemented correctly.


112-118: Ensure that validateField function handles validation correctly.

The validateField function correctly uses the validate method to check the validation status of a field and handles exceptions appropriately.


165-165: Ensure that clearValidate is called appropriately in resetForm.

The clearValidate method is called to reset the validation state when the form is reset, which is a correct usage.


182-182: Ensure that handleAddMissingRequiredFieldDefaultState is called at the start of the form interaction.

Calling handleAddMissingRequiredFieldDefaultState at the start ensures that any missing required fields are initialized properly.


364-482: Ensure that the form is structured correctly and all bindings are accurate.

The form structure and bindings, including dynamic references to formState and validation information, are correctly implemented.

Comment on lines +194 to +199
for (const col of visibleColumns.value) {
if (isRequired(col, col.required) && formState.value[col.title] === undefined) {
formState.value[col.title] = null
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Initialization of form state fields to null should be conditional.

  for (const col of visibleColumns.value) {
    if (isRequired(col, col.required) && formState.value[col.title] === undefined) {
+     if (isRequired(col, col.required)) {
        formState.value[col.title] = null
+     }
    }
  }

This change ensures that only required fields that are not already defined get initialized to null, preventing unnecessary overwrites.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
for (const col of visibleColumns.value) {
if (isRequired(col, col.required) && formState.value[col.title] === undefined) {
formState.value[col.title] = null
}
}
for (const col of visibleColumns.value) {
if (isRequired(col, col.required) && formState.value[col.title] === undefined) {
if (isRequired(col, col.required)) {
formState.value[col.title] = null
}
}
}

try {
await formRef.value?.validateFields()
await validate([...Object.keys(formState.value)])
Copy link
Contributor

Choose a reason for hiding this comment

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

Add error handling for the validate function to manage exceptions properly.

    await validate([...Object.keys(formState.value)])
+ } catch (e) {
+   console.error('Validation failed:', e);
+   throw e;
  } catch (e: any) {
    if (e.errorFields.length) {
      message.error(t('msg.error.someOfTheRequiredFieldsAreEmpty'))
      return
    }
  }

This change adds a more generic error handler for the validate function, ensuring that any type of exception is caught and logged, improving the robustness of the form submission process.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
await validate([...Object.keys(formState.value)])
await validate([...Object.keys(formState.value)])
} catch (e) {
console.error('Validation failed:', e);
throw e;
} catch (e: any) {
if (e.errorFields.length) {
message.error(t('msg.error.someOfTheRequiredFieldsAreEmpty'))
return
}
}

@@ -234,7 +220,7 @@

formState.value = {}
state.value = {}
await formRef.value?.clearValidate()
clearValidate()
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure clearValidate is called only when necessary.

  clearValidate()
+ if (shouldClearValidation) {
    clearValidate()
+ }

Consider adding a condition to check whether clearing the validation state is necessary based on the current form state or other conditions. This prevents unnecessary operations and potential side effects.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
clearValidate()
if (shouldClearValidation) {
clearValidate()
}

} catch (e: any) {
e.errorFields.map((f: Record<string, any>) => console.error(f.errors.join(',')))
}
await validate([...Object.keys(formState.value)])
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that validate function handles all potential exceptions.

      await validate([...Object.keys(formState.value)])
+ } catch (e) {
+   console.error('Validation error:', e);
+   throw e;
  } catch (e: any) {
      e.errorFields.map((f: Record<string, any>) => console.error(f.errors.join(',')))
    }

This modification ensures that all exceptions from the validate function are properly handled, providing better error reporting and control flow management.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
await validate([...Object.keys(formState.value)])
await validate([...Object.keys(formState.value)])
} catch (e) {
console.error('Validation error:', e);
throw e;
} catch (e: any) {
e.errorFields.map((f: Record<string, any>) => console.error(f.errors.join(',')))
}

Comment on lines +78 to +84
const formColumns = computed(
() =>
columns.value
?.filter((c) => c.show)
.filter(
(col) => !isSystemColumn(col) && col.uidt !== UITypes.SpecificDBType && (!isVirtualCol(col) || isLinksOrLTAR(col.uidt)),
) || [],
Copy link
Contributor

Choose a reason for hiding this comment

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

Optimize the filtering logic in formColumns computed property.

- .filter((col) => !isSystemColumn(col) && col.uidt !== UITypes.SpecificDBType && (!isVirtualCol(col) || isLinksOrLTAR(col.uidt)),
+ .filter((col) => !isSystemColumn(col) && col.uidt !== UITypes.SpecificDBType && (!isVirtualCol(col) || isLinksOrLTAR(col.uidt))),

Ensure that the filtering conditions are correctly grouped to avoid logical errors.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
const formColumns = computed(
() =>
columns.value
?.filter((c) => c.show)
.filter(
(col) => !isSystemColumn(col) && col.uidt !== UITypes.SpecificDBType && (!isVirtualCol(col) || isLinksOrLTAR(col.uidt)),
) || [],
const formColumns = computed(
() =>
columns.value
?.filter((c) => c.show)
.filter(
(col) => !isSystemColumn(col) && col.uidt !== UITypes.SpecificDBType && (!isVirtualCol(col) || isLinksOrLTAR(col.uidt))),
) || [],

Comment on lines +1452 to +1469
<NcTooltip
:disabled="!field.required || isLocked || !isEditable"
class="flex"
placement="topRight"
>
<template #title> You can't hide a required field.</template>
<a-switch
:checked="!!field.show"
:disabled="field.required || isLocked || !isEditable"
class="flex-none nc-switch"
size="small"
@change="
(value) => {
showOrHideColumn(field, value, true)
}
"
/>
</NcTooltip>
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure that the logic for showing or hiding columns is clear and handles all edge cases.

  showOrHideColumn(field, value, true)
+ if (canModifyField(field)) {
    showOrHideColumn(field, value, true)
+ }

Adding a check to ensure that the field can be modified before attempting to show or hide it can prevent runtime errors and ensure that the UI behaves as expected.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
<NcTooltip
:disabled="!field.required || isLocked || !isEditable"
class="flex"
placement="topRight"
>
<template #title> You can't hide a required field.</template>
<a-switch
:checked="!!field.show"
:disabled="field.required || isLocked || !isEditable"
class="flex-none nc-switch"
size="small"
@change="
(value) => {
showOrHideColumn(field, value, true)
}
"
/>
</NcTooltip>
<NcTooltip
:disabled="!field.required || isLocked || !isEditable"
class="flex"
placement="topRight"
>
<template #title> You can't hide a required field.</template>
<a-switch
:checked="!!field.show"
:disabled="field.required || isLocked || !isEditable"
class="flex-none nc-switch"
size="small"
@change="
(value) => {
if (canModifyField(field)) {
showOrHideColumn(field, value, true)
}
}
"
/>
</NcTooltip>

Comment on lines +531 to +550
function isRequired(column: Record<string, any>) {
if (!isVirtualCol(column) && ((column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)) || column.required)) {
return true
} else if (
isLinksOrLTAR(column) &&
column.colOptions &&
(column.colOptions as LinkToAnotherRecordType).type === RelationTypes.BELONGS_TO
) {
const col = columns.value?.find((c) => c.id === (column?.colOptions as LinkToAnotherRecordType)?.fk_child_column_id)

if ((col && col.rqd && !col.cdf) || column.required) {
if (col) {
return true
}
}
} else if (isVirtualCol(column) && column.required) {
return true
}
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor the isRequired function to improve readability and maintainability.

- if (!isVirtualCol(column) && ((column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)) || column.required)) {
+ if (!isVirtualCol(column) && (column.required || (column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)))) {

Reorder conditions for clarity and ensure that all necessary checks are performed in a logical sequence.


Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
function isRequired(column: Record<string, any>) {
if (!isVirtualCol(column) && ((column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)) || column.required)) {
return true
} else if (
isLinksOrLTAR(column) &&
column.colOptions &&
(column.colOptions as LinkToAnotherRecordType).type === RelationTypes.BELONGS_TO
) {
const col = columns.value?.find((c) => c.id === (column?.colOptions as LinkToAnotherRecordType)?.fk_child_column_id)
if ((col && col.rqd && !col.cdf) || column.required) {
if (col) {
return true
}
}
} else if (isVirtualCol(column) && column.required) {
return true
}
return false
}
function isRequired(column: Record<string, any>) {
if (!isVirtualCol(column) && (column.required || (column.rqd && !column.cdf) || (column.pk && !(column.ai || column.cdf)))) {
return true
} else if (
isLinksOrLTAR(column) &&
column.colOptions &&
(column.colOptions as LinkToAnotherRecordType).type === RelationTypes.BELONGS_TO
) {
const col = columns.value?.find((c) => c.id === (column?.colOptions as LinkToAnotherRecordType)?.fk_child_column_id)
if ((col && col.rqd && !col.cdf) || column.required) {
if (col) {
return true
}
}
} else if (isVirtualCol(column) && column.required) {
return true
}
return false
}

@o1lab o1lab force-pushed the nc-feat/form-validation branch from e263a8a to e809d0d Compare May 9, 2024 10:31
@o1lab o1lab force-pushed the nc-feat/form-validation branch from e809d0d to a33dade Compare May 9, 2024 10:33
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between e809d0d and a33dade.
Files ignored due to path filters (2)
  • packages/nc-gui/assets/nc-icons/alert-triangle.svg is excluded by !**/*.svg, !**/*.svg
  • packages/nc-gui/lang/en.json is excluded by !**/*.json
Files selected for processing (17)
  • packages/nc-gui/components/cell/Currency.vue (3 hunks)
  • packages/nc-gui/components/cell/Decimal.vue (2 hunks)
  • packages/nc-gui/components/cell/Percent.vue (2 hunks)
  • packages/nc-gui/components/cell/PhoneNumber.vue (3 hunks)
  • packages/nc-gui/components/cell/attachment/index.vue (2 hunks)
  • packages/nc-gui/components/smartsheet/Form.vue (24 hunks)
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue (1 hunks)
  • packages/nc-gui/components/smartsheet/form/field-settings.vue (1 hunks)
  • packages/nc-gui/composables/useFormViewStore.ts (1 hunks)
  • packages/nc-gui/composables/useSharedFormViewStore.ts (12 hunks)
  • packages/nc-gui/composables/useViewData.ts (1 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue (3 hunks)
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (9 hunks)
  • packages/nc-gui/utils/formValidations.ts (1 hunks)
  • packages/nc-gui/utils/iconUtils.ts (2 hunks)
  • packages/nocodb-sdk/src/lib/form.ts (1 hunks)
  • packages/nocodb-sdk/src/lib/index.ts (1 hunks)
Files skipped from review as they are similar to previous changes (14)
  • packages/nc-gui/components/cell/Currency.vue
  • packages/nc-gui/components/cell/Decimal.vue
  • packages/nc-gui/components/cell/Percent.vue
  • packages/nc-gui/components/cell/PhoneNumber.vue
  • packages/nc-gui/components/cell/attachment/index.vue
  • packages/nc-gui/components/smartsheet/form/field-config-error.vue
  • packages/nc-gui/components/smartsheet/form/field-settings.vue
  • packages/nc-gui/composables/useFormViewStore.ts
  • packages/nc-gui/composables/useViewData.ts
  • packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/index.vue
  • packages/nc-gui/utils/formValidations.ts
  • packages/nc-gui/utils/iconUtils.ts
  • packages/nocodb-sdk/src/lib/form.ts
  • packages/nocodb-sdk/src/lib/index.ts
Additional comments not posted (18)
packages/nc-gui/composables/useSharedFormViewStore.ts (7)

15-15: Added import for RuleObject from ant-design-vue/es/form.

This import is necessary for the new validation logic introduced in this file.


78-84: Optimized filtering logic in formColumns computed property.

The filtering conditions are correctly grouped, ensuring logical correctness and improved readability.


124-138: Introduced default value handling for various field types in the form state initialization.

This change ensures that default values are correctly parsed and set based on the field type, enhancing the robustness of form initialization.


192-224: Refactored validation rules setup in validators computed property.

The new setup is more modular and easier to understand, improving maintainability and performance of the validation logic.


226-229: Added validationFieldState computed property to manage the state of fields during validation.

This addition helps in maintaining a consistent state across validations, improving the reliability of form validations.


232-247: Introduced handleAddMissingRequiredFieldDefaultState function to handle missing required fields.

This function ensures that all required fields have a default state before validation, which is crucial for maintaining form integrity.


531-550: Refactored isRequired function to improve readability and maintainability.

The conditions are reordered for clarity, and all necessary checks are performed in a logical sequence, enhancing the function's reliability.

packages/nc-gui/pages/index/[typeOrId]/form/[viewId]/index/survey.vue (6)

20-34: Imported and destructured various properties and functions from useSharedFormStoreOrThrow.

These imports are necessary for the form functionality and are correctly destructured for use within the component.


80-80: Added error handling for form fields in fieldHasError computed property.

This addition improves user feedback by correctly identifying and displaying errors related to form fields.


112-118: Refactored validateField function to handle field validation asynchronously.

This change allows for asynchronous validation of fields, improving the responsiveness and accuracy of form validations.


165-165: Added clearValidate call in resetForm function to reset form validations.

This ensures that validations are correctly reset when the form is reset, maintaining the integrity of form state.


182-182: Called handleAddMissingRequiredFieldDefaultState in onStart function to ensure all required fields are initialized.

This call is crucial for ensuring that all required fields are properly initialized before the form starts, enhancing form reliability.


364-482: Implemented a dynamic form layout with conditional rendering and validation.

The dynamic layout allows for flexible form configurations and robust validation handling, improving the user experience and form functionality.

packages/nc-gui/components/smartsheet/Form.vue (5)

194-199: Initialization of form state fields to null should be conditional.


201-201: Add error handling for the validate function to manage exceptions properly.


223-223: Ensure clearValidate is called only when necessary.


589-589: Ensure that validate function handles all potential exceptions.


1452-1469: Ensure that the logic for showing or hiding columns is clear and handles all edge cases.

@dstala dstala merged commit f852408 into develop May 9, 2024
19 of 23 checks passed
@dstala dstala deleted the nc-feat/form-validation branch May 9, 2024 16:47
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.

None yet

2 participants