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

refactor: Extract helper functions and drop table-layout support #74

Closed
wants to merge 1 commit into from

Conversation

rahulsom
Copy link

  1. Extract helper functions
  • makeLabel
  • makeTr
  • makeTd
  • makeHidden
  • makeCheckbox
  • makeRadio
  1. Update JSDoc so type information is available to the IDE
  2. Remove support for table-based layout. The required Jenkins version for the plugin is 2.332.4 since commit b06c354. Jenkins core dropped table-based layout support in 2.277.1 in favor of div-based layout.

Testing done

No functionality has changed. All unit and acceptance tests pass.

Submitter checklist

Preview Give feedback

1. Extract helper functions
  * makeLabel
  * makeTr
  * makeTd
  * makeHidden
  * makeCheckbox
  * makeRadio
2. Update JSDoc so type information is available to the IDE
3. Remove support for table-based layout.
   The required Jenkins version for the plugin is 2.332.4 since commit b06c354.
   Jenkins core dropped table-based layout support in 2.277.1 in favor of div-based layout.
* @param proxy Stapler proxy object that references the CascadeChoiceParameter
*/
/* public */ function CascadeParameter(paramName, paramElement, randomName, proxy) {
Copy link
Author

Choose a reason for hiding this comment

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

The /* public */ interferes with JSDoc - so I've removed all occurrences of it.

* @param paramName parameter name
* @param paramElement parameter HTML element
* @param randomName randomName given to the parameter
* @param paramName {String} parameter name
Copy link
Author

Choose a reason for hiding this comment

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

I've added some type info where it was easy to determine types.

@@ -222,139 +221,6 @@ var UnoChoice = UnoChoice || ($ => {
_self.getFilterElement().setOriginalArray(originalArray);
}
} else if (parameterElement.tagName === 'DIV' || parameterElement.tagName === 'SPAN') {
if (parameterElement.children.length > 0 && parameterElement.children[0].tagName === 'TABLE') {
Copy link
Author

Choose a reason for hiding this comment

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

This is an example of code we could remove since moving the min-jenkins version past 2.277.1

input.setAttribute("class", " ");
input.setAttribute("type", "checkbox");
label.className = "attach-previous";
let input = makeCheckbox(key, selectedElements.indexOf(i) >= 0, disabledElements.indexOf(i) >= 0);
Copy link
Author

Choose a reason for hiding this comment

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

This is an example of a helper method I've introduced where we've had multiple places where we were creating checkboxes.

Copy link
Member

Choose a reason for hiding this comment

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

Brilliant simplification! 👏

if ($(paramElement).children().length > 0 && (paramElement.children[0].tagName === 'DIV' || paramElement.children[0].tagName === 'SPAN')) {
let tbody = paramElement.children[0];
if (paramElement.className === 'dynamic_checkbox') {
Copy link
Author

Choose a reason for hiding this comment

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

The code in the if block and else block were identical. I've removed the conditional logic.

Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

👏

From an initial look, the code looks great!

I will try to find some time to test the plug-in and review/merge it.

@rahulsom previously I used .. qunit I think, to write unit tests. But that was a bit clumsy and not reliable nor easy to maintain the tests. Do you think we could/should use unit tests for this new code, especially now that it's more modular? Maybe with jest, mocha, chai, etc?

Thanks!

@rahulsom
Copy link
Author

Do you think we could/should use unit tests for this new code, especially now that it's more modular? Maybe with jest, mocha, chai, etc?

I have very little experience with JS code.

I've written unit tests for React apps, but not much else. If you have a reference in mind, I'm glad to add that.

@kinow
Copy link
Member

kinow commented Jun 20, 2023

Ah, I thought you'd have a preferred solution. I'm used to these three I mentioned before, and have also used Karma in the past with angularjs. I will see how complicated it would be to add something like that when I review this PR (it could be that it makes more sense to merge and then open another issue for that to avoid blocking your work) 👍 Thanks heaps for preparing the PR.

@rahulsom
Copy link
Author

rahulsom commented Jun 21, 2023

😅 I've got some tests working for the javascript code. It uses jest. The code had to be split up into the tested code in Util.ts and untested code in unochoice.es6.
The toolchain is heavily inspired by what happens in Jenkins core.

I'll create a separate PR with that.

@rahulsom rahulsom force-pushed the extract-reusable-helpers branch from 8a7023e to c94bf7a Compare June 22, 2023 01:00
@rahulsom rahulsom mentioned this pull request Jun 22, 2023
Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

Code looks good! Just pending some manual smoke tests. Thanks @rahulsom !

@kinow
Copy link
Member

kinow commented Jun 23, 2023

(starting from this one as you've smartly built the other PR's on top of each change 🙂)

Copy link
Member

@kinow kinow left a comment

Choose a reason for hiding this comment

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

Tested with three parameter types. Everything worked, and got no errors logged on the JS console. Merging. Thanks @rahulsom !

@kinow kinow closed this in 2006a53 Jun 24, 2023
kinow added a commit that referenced this pull request Jun 24, 2023
@rahulsom rahulsom deleted the extract-reusable-helpers branch July 4, 2023 20:45
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.

2 participants