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

Improve currency component #184

Closed
wants to merge 11 commits into from

Conversation

DedrickEnc
Copy link
Contributor

Summary

This PR improves the currency input component and introduces a new design to deal with component.

Tasks accomplished

In this PR, I did followings :

  • Moving the currency component code from directive to component
  • Adding possibility to use max value
  • Introducing new design to deal with component
  • Incorporate currency select component (@jniles's code) to the currency input component (cascaded components)
  • Using persistence possibility to the correct place (currency select component).

This PR closes #161

@DedrickEnc
Copy link
Contributor Author

@jniles you can give it a review

@jniles
Copy link
Collaborator

jniles commented Mar 9, 2016

@DedrickEnc, this is good code. Unfortunately, it it does close all of #161. Here is what is missing:

  • strict option, making the currency input not accept parts of a currency (45 FCs, 0.0034 USD, etc)
  • Default text when no currency is selected
  • Remove the binding to the parent form (form), and use a child form instead to do local validation.

If you have comments on those objectives, please post them on #161.

This PR improves the bhCurrencyInput by removing the $watch() on scope, which is excellent. However, it does this by tightly coupling two components, making the developer unable to alter the appearance or placement of the bhCurrencySelect component when using the bhCurrencyInput. I'm not sure this is a better solution in that respect, but it is a good start.

I'm confused why you blocked #178 and then used it's code. You did not give any feedback on how to improve #178, and did not fix the problem from #178. The problem with #178 is that it uses $scope.$watch() implement the functionality of disable-ids. See here. Otherwise, #178 handled changed exactly the same way you do here - with an on-change() callback.

My question from https://github.com/IMA-WorldHealth/bhima-2.X/pull/178/files#r55346517 still remains. Can you produce a better design for handling the disable-ids case?

@DedrickEnc
Copy link
Contributor Author

  • A component can use an other component, there is no problem. So a currency input component is using a currency select component which remains an independent component because it can be used with out currency input component.
  • The placement of currency select component in the currency input component is natural, I can not find a better position than that, otherwise I must put it at the bottom of currency input component which is strange.
  • A currency select component should let user select a currency (so simple), so my question is what is the purpose of disable-ids? I tried to see the code, but you did not provide many comment about that, so it is complicate for me to understand, what is his purpose exactly?

@jniles
Copy link
Collaborator

jniles commented Mar 9, 2016

I have no problem with this intercomponent communication. If every bhCurrencyInput needs to have a selection of currencies, than it makes sense to join them together into a single component. I was under the impression that there might be some places we would not have the option of choosing a currency, but would still want the power of the bhCurrencyInput's validation.

To answer your last question, some cashboxes do not have currency accounts configured for them. In this case, we should disable the currency option so that the user cannot create a transaction involving that cashbox in a different currency.

... if you didn't understand the code, why not comment asking for an explanation instead of simply removing the feature?

@jniles
Copy link
Collaborator

jniles commented Mar 9, 2016

To show you what I mean about the placement of components, here is a comparison of the cash page before and after:
Cash Before
cashbefore

Cash After
cashafter

It's not a huge problem, but in the first case, changing the currency will affect everything below the currency selection. In the second case, the currency will change both the totals above and the input below. It's a tiny regression from a usability perspective.

@DedrickEnc
Copy link
Contributor Author

@jniles
I completed the other improvement tasks, here are things you have to know :

  • I found an other alternative to perform disabled currency, so now it is handled by the currency input component not as a disabled ids but has an unsupported currency ids so the currency input component does not allow user to insert an amount if an unsupported currency is chosen and show a message.
  • I remove some methods in cash which was related to date select as we should use a date component
  • Now the currency input component can handle a part of currency and show a message, since angular does not recognize step attribute I used a custom validation.

@jniles
Copy link
Collaborator

jniles commented Mar 13, 2016

I'll take a look at this this evening. I'd also be interested in hearing opinions from other developers. @IMA-WorldHealth/local-contributors what do you think?

@jniles
Copy link
Collaborator

jniles commented Mar 14, 2016

This is a difficult design for me to support. Here are some of the issues that concern me:

  1. Tightly Coupling Components: There is no way to use the bhCurrencyInput on its own without the bhCurrencySelect embedded in it. It is not difficult to think of examples where you may need to use a pre-selected currency without giving the user an option to change currency (paying a bill in USD, but still want to have the validation of the bhCurrencyInput). Additionally, this proposal removes the possibility of having multiple bhCurrencyInputs on a page. For example, in a grid. Each one will embed its own currency select.

  2. No Layout Flexibility: A significant downside to this layout is that the radio buttons will always be right on top of the currency input, where I would naturally expect to find a total field or something similar. This is shown in the above images. In bhima-2.X, we are focusing on making things clean and tested, both in the code and the user experience. This proposal takes away the programmers ability do define what form components go where on their forms, and creates a strange UX for our clients.

  3. Regression in UX: If a user is not allowed to pay in a currency, it makes more sense to remove their ability to choose that currency than it does to allow them to make an incorrect choice and then send a big error message at them.

  4. Unclear Component Responsibility: The goal of these components is generally to perform a single function. Before, the functions where:

    1. bhCurrencySelect - take in a list of currencies and a filtering array, allowing the user to choose all currencies satisfying the filter conditions.
    2. bhCurrencyInput - ensure that a number entered into the input is an actual currency.

    This proposal adds to these responsibilities, so that bhCurrencyInput does a lot of work to validate currencies, not only based on whether the currency is valid or not, but if the module is allowed to use that currency.

For these reasons above, I am uncomfortable with this proposal. It seems to me this was a solution looking for a problem, rather than a solution to a problem. It is unclear to me what problem this code is trying to solve that is not already solved in a clearer fashion in this PR. Since there was no feedback on why the PR was not merged it is difficult to understand why this is a better proposal.

I'll wait for @sfount's opinion before merging this code.

@DedrickEnc, if you would like to present an analysis of the two proposals with reasons why this one is better, I would be interested to read it.

@DedrickEnc
Copy link
Contributor Author

@jniles
I. I disagree, go to see the angular documentation, embedded components are not bad thing.
Using the bhCurrencyInput in the grid is possible and there are two possibilities :

  • Say the currency input to not include the currency select (Recommended)
  • Create an other component

II. Yesterday, about the layout problem you said it was acceptable, today it is changed?

III. The bhCurrencyInput is closed to the page than bhCurrencySelect, it makes more sense to charge the bhCurrencyInput checking this situation.
Also a choice him self can not be invalid, the choice is invalid for an other component or a page since I don't need to handle this situation in the page level, that why I prefer to do it in the currency input.
On a page a currency can only be invalid in a particular context and the context I choose for this page is currency input component, this component will consider some currency as unsupported.

IV. I disagree, where did you take this theory? a component must have clears responsibilities and that is the case for this PR :

  • bhCurrencySelect just propose currencies choices to the user and store selected currency to remember (so simple)
  • bhCurrencyInput receive an amount just for a supported currency. the page will inform the bhCurrencyInput about the list of unsupported currencies.

Yesterday, this PR was very good and I was supposed to add one or two more functionnalities and today every thing is bad, here is your comment :

@DedrickEnc, this is good code. Unfortunately, it it does close all of #161. Here is what is missing:

  • strict option, making the currency input not accept parts of a currency (45 FCs, 0.0034 USD, etc)
  • Default text when no currency is selected
  • Remove the binding to the parent form (form), and use a child form instead to do local validation.

If you have comments on those objectives, please post them on #161.

This PR improves the bhCurrencyInput by removing the $watch() on scope, which is excellent. However, it does this by tightly coupling two components, making the developer unable to alter the appearance or placement of the bhCurrencySelect component when using the bhCurrencyInput. I'm not sure this is a better solution in that respect, but it is a good start.

I'm confused why you blocked #178 and then used it's code. You did not give any feedback on how to improve #178, and did not fix the problem from #178. The problem with #178 is that it uses $scope.$watch() implement the functionality of disable-ids. See here. Otherwise, #178 handled changed exactly the same way you do here - with an on-change() callback.

My question from https://github.com/IMA-WorldHealth/bhima-2.X/pull/178/files#r55346517 still remains. Can you produce a better design for handling the disable-ids case?

This PR request is a good thing, If you are not at easy to discuss about that, I will be ok to wait for @sfount even until april if possible.
Thanks

@jniles
Copy link
Collaborator

jniles commented Mar 14, 2016

@DedrickEnc, I never said embedded components was a bad thing. Where did I say that? In this case, it is inappropriate. By default we embed an entire extra component, and you recommend we pass a flag to turn it off? That is poor design.

I am comparing the two designs, one proposed in #178 and this one. The design proposed in #178 is modular, composable, and decoupled. It is easy for developers to get the best user experience using it. It satisfies all the requirements without imposing any new requirements of its own. It certainly doesn't ask developers to create a new component not have the currency select radios embedded in this component.

I took the theory because I built the original components. Those were my design requirements. It's called the Single Responsibility Principle in programming. I just applied it to my components.

The code was good. Now, it is less good (for example, the validation should be done with an ngModel $validator), but still acceptable for a first PR. We could clean it up later. The design is bad. All my critiques are about the design.

@jniles
Copy link
Collaborator

jniles commented Mar 14, 2016

You also never responded to the last part of my comments last week, which I hoped would help me understand why this PR even exists in the first place. Since I do not have any arguments why this is a better idea than the previous code and I've supplied plenty of critiques of this, particularly from the UI/UX perspective, I have a hard time evaluating the benefits of this PR.

@DedrickEnc
Copy link
Contributor Author

@sfount

When ready you can review this pull request, thanks!

@DedrickEnc
Copy link
Contributor Author

@jniles @sfount
This PR should be reviewed.
Thanks

@jniles
Copy link
Collaborator

jniles commented Apr 26, 2016

@sfount, this one's on you.

@sfount
Copy link
Contributor

sfount commented Oct 21, 2016

The code changes and discussion here were factored into #414 (currently in use in many modules). This pull request contains good code that should be referenced to complete #161, however it is 7 months out of date and cannot be merged with the current master.

@sfount sfount closed this Oct 21, 2016
jniles referenced this pull request in jniles/bhima Feb 2, 2017
This commit implements a POS receipt for the voucher page.  This receipt
also puts the transaction type at the top of the receipt and groups by
debits/credits.

Fixes #184. Fixes #185.
jniles referenced this pull request in jniles/bhima Feb 2, 2017
This commit implements a POS receipt for the voucher page.  This receipt
also puts the transaction type at the top of the receipt and groups by
debits/credits.

Fixes #184. Fixes #185.
jniles referenced this pull request in jniles/bhima Feb 2, 2017
This commit implements a POS receipt for the voucher page.  This receipt
also puts the transaction type at the top of the receipt and groups by
debits/credits.

Fixes #184. Fixes #185.
jniles referenced this pull request in jniles/bhima Feb 3, 2017
This commit implements a POS receipt for the voucher page.  This receipt
also puts the transaction type at the top of the receipt and groups by
debits/credits.

Fixes #184. Fixes #185.
jniles referenced this pull request in jniles/bhima Feb 4, 2017
This commit implements a POS receipt for the voucher page.  This receipt
also puts the transaction type at the top of the receipt and groups by
debits/credits.

Fixes #184. Fixes #185.
jniles referenced this pull request in jniles/bhima Feb 4, 2017
This commit implements a POS receipt for the voucher page.  This receipt
also puts the transaction type at the top of the receipt and groups by
debits/credits.

Fixes #184. Fixes #185.
@DedrickEnc DedrickEnc deleted the CurrencyCmp branch May 12, 2017 09:33
bors bot added a commit that referenced this pull request Aug 8, 2018
3010: Update snyk to the latest version 🚀 r=jniles a=greenkeeper[bot]




## Version **1.90.1** of **snyk** was just published.

<table>
  <tr>
    <th align=left>
      Dependency
    </th>
    <td>
      <a target=_blank href=https://github.com/snyk/snyk>snyk</a>
    </td>
  </tr>
  <tr>
      <th align=left>
       Current Version
      </th>
      <td>
        1.90.0
      </td>
    </tr>
  <tr>
    <th align=left>
      Type
    </th>
    <td>
      dependency
    </td>
  </tr>
</table>



The version **1.90.1** is **not covered** by your **current version range**.

If you don’t accept this pull request, your project will work just like it did before. However, you might be missing out on a bunch of new features, fixes and/or performance improvements from the dependency update.

It might be worth looking into these changes and trying to get this project onto the latest version of snyk.

If you have a solid test suite and good coverage, a passing build is a strong indicator that you can take advantage of these changes directly by merging the proposed change into your project. If the build fails or you don’t have such unconditional trust in your tests, this branch is a great starting point for you to work on the update.


---


<details>
<summary>Release Notes</summary>
<strong>v1.90.1</strong>

<p>Bumps various deps:</p>
<ul>
<li>bump snyk-config to fix env merge issue</li>
<li>bump go plugin to update doc/typos</li>
<li>bump nuget plugin to get rid of an unneeded dep</li>
<li>bump python plugin to fix pipenv monitoring issue</li>
<li>bump sbt plugin to update 'debug' dep version</li>
</ul>
</details>

<details>
<summary>Commits</summary>
<p>The new version differs by 12 commits.</p>
<ul>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/e14ab9eaf5ba6cc66751f3fc2803d54d354b6b6c"><code>e14ab9e</code></a> <code>Merge pull request #185 from snyk/fix/bump-deps</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/c6735e4f4ef5a44b9ae158687682193da284f3f8"><code>c6735e4</code></a> <code>Merge pull request #184 from snyk/chore/github-release</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/ace19f7394a9500d34bdb2247a6d75e78601cf5a"><code>ace19f7</code></a> <code>Merge pull request #183 from snyk/chore/eslint</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/f31602440e9740e73c1c8b659bd396ba4ceb29ac"><code>f316024</code></a> <code>fix: bump sbt plugin to update 'debug' dep version</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/2c79a4efd4580e251decbfa4587a5fd86f9e5155"><code>2c79a4e</code></a> <code>fix: bump python plugin to fix pipenv monitoring issue</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/975ca1ca1198c0eda61d60b586ce3d3702287e8e"><code>975ca1c</code></a> <code>fix: bump nuget plugin to get rid of an unneeded dep</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/828d579ff27d582635c1b1db4b15f50331c5d91f"><code>828d579</code></a> <code>fix: bump go plugin to update doc/typos</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/be8fa57983cf566c280d29d91a0d28814f14625e"><code>be8fa57</code></a> <code>fix: bump snyk-config to fix env merge issue</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/b638a37c093ba7200da94fc5424bd2816874ca35"><code>b638a37</code></a> <code>chore: eslint instead of jscs</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/0bfeb0b06df49b9acd67a2bb27993313546d138c"><code>0bfeb0b</code></a> <code>chore: fix github-release for assets uploading</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/9312a048c1d27021b52a90d335a8f68d0a7f9db5"><code>9312a04</code></a> <code>Merge pull request #181 from snyk/chore/semantic-release</code></li>
<li><a href="https://urls.greenkeeper.io/snyk/snyk/commit/6abdfd957d07337b86e0ba3aafb1e219e1083665"><code>6abdfd9</code></a> <code>chore: upgrade semantic-release, proper travis &amp; appveyor setup</code></li>
</ul>
<p>See the <a href="https://urls.greenkeeper.io/snyk/snyk/compare/2a6938fe92377c99fe4991f0159a1e32e6e58834...e14ab9eaf5ba6cc66751f3fc2803d54d354b6b6c">full diff</a></p>
</details>

<details>
  <summary>FAQ and help</summary>

  There is a collection of [frequently asked questions](https://greenkeeper.io/faq.html). If those don’t help, you can always [ask the humans behind Greenkeeper](https://github.com/greenkeeperio/greenkeeper/issues/new).
</details>

---


Your [Greenkeeper](https://greenkeeper.io) bot 🌴



Co-authored-by: greenkeeper[bot] <greenkeeper[bot]@users.noreply.github.com>
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.

Improve bhCurrencyInput
3 participants