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

feat(cdk:forms): formArray supports clearControls #1490

Merged
merged 1 commit into from Mar 6, 2023

Conversation

danranVm
Copy link
Member

@danranVm danranVm commented Mar 6, 2023

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines
  • Tests for the changes have been added/updated or not needed
  • Docs and demo have been added/updated or not needed

What is the current behavior?

What is the new behavior?

支持清空子控件

Other information

expect(array.length.value).toEqual(0)
expect(array.getValue()).toEqual([])
})

test('setControl work', async () => {
expect(array.getValue()).toEqual([basicValue])
const group = new FormGroup<BasicGroup>({
Copy link

Choose a reason for hiding this comment

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

with the code review
The code looks okay and should be able to provide the expected functionality. However, I would suggest adding more tests to ensure that the clearControls() method is working as expected. Additionally, you can add a try-catch block to handle any unexpected errors. Also, if possible, use linting tools for better readability and formatting of your code.

/**
* 清空数组中的所有子空间
*/
clearControls(): void;
/**
* 替换数组中给定 `index` 处现有的子控件
*
Copy link

Choose a reason for hiding this comment

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

the review

  1. The code looks quite straightforward, and it seems to have added a new function to the FormArray class.
  2. The new method 'clearControls' looks like it does what it says it does, which is to clear out all of the objects from an array.
  3. However, I would suggest to add a check to make sure that the array is not empty before running the method, to avoid errors.
  4. Also, consider adding a comment block that explains what the method does and what arguments are accepted.

@idux-bot
Copy link

idux-bot bot commented Mar 6, 2023

This preview will be available after the AzureCI is passed.

*/
clearControls(): void {
this._controls.value = []
}

/**
* Replace an existing control.
Copy link

Choose a reason for hiding this comment

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

with the code review

  1. The code looks syntactically correct, as it follows the standard Javascript syntax.
  2. The code is adding a new method ‘clearControls’ to the existing FormArray class which removes all the existing controls from the array.
  3. The method is properly documented using Javadoc style comments which is a good practice.
  4. The logic of the method is simple and easy to understand, so no issues in that regard.
  5. There are no obvious bugs in the code, but it would be better to add some unit tests to make sure it works as expected.
  6. The code should also include some input validation to make sure that the input is valid.
  7. It would also be good to add some logging statements to the method for debugging purposes.

@codecov
Copy link

codecov bot commented Mar 6, 2023

Codecov Report

Merging #1490 (95faadd) into main (950f1b1) will not change coverage.
The diff coverage is 100.00%.

❗ Current head 95faadd differs from pull request most recent head f7a9a39. Consider uploading reports for the commit f7a9a39 to get more accurate results

@@           Coverage Diff           @@
##             main    #1490   +/-   ##
=======================================
  Coverage   92.73%   92.73%           
=======================================
  Files         331      331           
  Lines       30754    30754           
  Branches     3533     3533           
=======================================
  Hits        28520    28520           
  Misses       2234     2234           
Impacted Files Coverage Δ
packages/pro/config/src/defaultConfig.ts 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@danranVm danranVm merged commit 1cd4dcc into IDuxFE:main Mar 6, 2023
@danranVm danranVm deleted the feat-cdk-forms branch March 7, 2023 07:21
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

1 participant