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

Shorten UI code with new $step method #710

Merged
merged 29 commits into from
Jun 21, 2019
Merged

Shorten UI code with new $step method #710

merged 29 commits into from
Jun 21, 2019

Conversation

harshkhandeparkar
Copy link
Member

@harshkhandeparkar harshkhandeparkar commented Jan 24, 2019

Fixes #833

Refactors the UI code by using new methods $step and $stepAll.

instead of

$(step.ui.querySelector('query')).show().hide();
$(step.ui.querySelectorAll('q2')).show().hide();

Use

$step('query').show().hide();
$stepAll('q2').show().hide();

Also with (what I call) selector chaining:

$step('query').show().hide().elemAll('q2').show().hide();

How does it work

  1. Import the scopeSelector and scopeSelectorAll methods from lib/scopeQuery.js
  2. Call the methods with scope(step.ui in this case)
var scopeQuery = require('./scopeQuery');

var $step = scopeQuery.scopeSelector(step.ui),
  $stepAll = scopeQuery.scopeSelectorAll(step.ui);
  1. This will return an object with a constructor which returns a jQuery object (from inside the scope) but with new elem and elemAll methods.

This method can reduce the frequent occurrences of $(step.ui.querySelector('q')) especially with selector chaining.

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with npm test
  • code is in uniquely-named feature branch and has no merge conflicts
  • PR is descriptively titled
  • ask @publiclab/reviewers and @publiclab/is-reviewers for help, in a comment below

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@harshkhandeparkar
Copy link
Member Author

@publiclab/is-reviewers please review.

@harshkhandeparkar
Copy link
Member Author

harshkhandeparkar commented Jan 24, 2019

I'm going to change the names to scopeQuery tomorrow 😋

@harshkhandeparkar
Copy link
Member Author

@publiclab/is-reviewers I have made the changes and rebased. Please review

@harshkhandeparkar
Copy link
Member Author

@jywarren can you please merge my PRs before the other ones since I will not be able to touch my PC until 16th of april. I don't know if I will get time past that date as well.

@harshkhandeparkar harshkhandeparkar added user-interface refactoring Issues/PRs which deal with code refactoring labels Mar 3, 2019
@jywarren
Copy link
Member

jywarren commented Mar 4, 2019

Hi, sorry I missed this way back. I'm wondering if we could pass this with the utility functions we make available to steps:

https://github.com/publiclab/image-sequencer/blob/main/CONTRIBUTING.md#draw

What do you think? I like the idea of a convenience method, though! Thanks!

@jywarren
Copy link
Member

jywarren commented Mar 4, 2019

Also, i think it'd be best to have a test -- no rush on this, i know you're busy, but just to reply (finally, apologies again!)

@harshkhandeparkar
Copy link
Member Author

No need for an apology. Also I think tests and docs can be added in a followup by somebody else since I'm not very experienced with jasmine and also someone can add to the docs(maybe a newcomer) very easily. What do you think?

@jywarren
Copy link
Member

jywarren commented Mar 4, 2019 via email

@harshkhandeparkar
Copy link
Member Author

harshkhandeparkar commented Mar 4, 2019 via email

@harshkhandeparkar
Copy link
Member Author

Shall I open it now or after this is merged?

@jywarren
Copy link
Member

jywarren commented Mar 4, 2019 via email

@harshkhandeparkar
Copy link
Member Author

Yep. Sure!

})

})

Choose a reason for hiding this comment

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

Okay so basically you are testing your new method by creating an example html! Why don't we test it for a particular step? I mean a module. I understand the results would be same but I want to know if you tried doing that and have been stuck as it happened with me as well!

Copy link
Member Author

Choose a reason for hiding this comment

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

It took me a day to figure this out.

Choose a reason for hiding this comment

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

Yeah the way is great as we basically have to test the functionality but have you tried it for a module? I just want to know if you faced issues with doing it with jasmine-jquery and fixtures and spyOnEvent

Copy link
Member Author

Choose a reason for hiding this comment

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

@aashna27 I didn't understand your question properly. If there is some problem in my code, please let me know here. If you want to ask some questions, DM me on gitter and resolve this conversation. Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

I hear what @aashna27 is saying here, but although I see the logic in the suggestion of the HTML fixture being of similar structure to the one @harshkhandeparkar has used, I think it's basically OK for now. The important thing is that it serves a generalized purpose and that the HTML example here properly demonstrates it. Thanks!!!

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, now I understand. This is just a unit test, maybe we can write integration tests in the future. Currently, even the unit tests are incomplete so maybe integration tests and e2e tests can be written in the near future. What do ya'll say?

Choose a reason for hiding this comment

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

@aashna27 I didn't understand your question properly. If there is some problem in my code, please let me know here. If you want to ask some questions, DM me on gitter and resolve this conversation. Thanks!

No no problem with the code just wanted to know if you tried another approach, this one is great though!

examples/lib/intermediateHtmlStepUi.js Outdated Show resolved Hide resolved
})

})

Choose a reason for hiding this comment

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

Yeah the way is great as we basically have to test the functionality but have you tried it for a module? I just want to know if you faced issues with doing it with jasmine-jquery and fixtures and spyOnEvent

@jywarren
Copy link
Member

Hi, all, this looks really good and with one extra addition I think it is good to merge. @harshkhandeparkar you've written some great docs in the How does it work at top. And I see docs were added in #916 -- next time let's please merge docs and code in a single PR, even if we review it in multiple PRs - like, we could have the docs and tests and functions all merge into a joint feature branch maybe? Or just generally try to work in small pieces. But this looks really good and pending the "out of date branch" I see here being resolved, I think we are fine to merge it!

Also cc @MargaretAN9 who is working on an overall image-sequencer manual at https://publiclab.org/notes/MaggPi/06-10-2019/draft-of-public-lab-image-sequencer-user-manual-comments-welcome, as this will change some of the UI helper methods behaviors. @MargaretAN9 will you post your manual for comment in Markdown in a PR in this repository? Thank you!

@harshkhandeparkar
Copy link
Member Author

@jywarren at the time the docs were written, I didn't think I would have time to write them myself so I made the FTO. But it ended up helping a first timer anyway 😄

@jywarren
Copy link
Member

jywarren commented Jun 18, 2019 via email

@harshkhandeparkar
Copy link
Member Author

Wow! I could rebase it from the browser. New GitHub features, which are added silently, are awesome.

examples/lib/intermediateHtmlStepUi.js Outdated Show resolved Hide resolved
examples/lib/intermediateHtmlStepUi.js Outdated Show resolved Hide resolved
examples/lib/intermediateHtmlStepUi.js Outdated Show resolved Hide resolved
examples/lib/intermediateHtmlStepUi.js Outdated Show resolved Hide resolved
@jywarren
Copy link
Member

All good here? Can you mention when it's totally ready to merge? Thank you!

aashna27
aashna27 previously approved these changes Jun 18, 2019
test/ui/defaultHtmlStepUi.spec.js Outdated Show resolved Hide resolved
@aashna27 aashna27 dismissed their stale review June 19, 2019 18:23

Changes Needed

@harshkhandeparkar
Copy link
Member Author

@aashna27 please review this again. Made the requested changes.

Copy link

@aashna27 aashna27 left a comment

Choose a reason for hiding this comment

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

Great, I think it is all set!! 🎉

@harshkhandeparkar
Copy link
Member Author

harshkhandeparkar commented Jun 21, 2019 via email

@jywarren jywarren merged commit 257113a into publiclab:main Jun 21, 2019
@jywarren
Copy link
Member

🎉

@harshkhandeparkar
Copy link
Member Author

Thanks a lot to everyone!
@jywarren @aashna27 @rexagod @publiclab/is-reviewers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
refactoring Issues/PRs which deal with code refactoring user-interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Completion Of $step helper method
5 participants