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

Feature/645 Add units in map screen #654

Merged
merged 8 commits into from
May 12, 2021

Conversation

ismaelbej
Copy link
Contributor

@ismaelbej ismaelbej commented May 6, 2021

Also includes #644 and #651.

@ismaelbej ismaelbej requested a review from ggiraldez May 6, 2021 21:15
@ismaelbej ismaelbej force-pushed the feature/635-source-type-template branch 2 times, most recently from ced16a7 to 67b867c Compare May 8, 2021 02:06
@ismaelbej ismaelbej force-pushed the feature/645-add-units-in-map-screen branch from 3a2246e to 58e81ca Compare May 8, 2021 02:39
@ismaelbej ismaelbej changed the base branch from feature/635-source-type-template to master May 8, 2021 02:39
Copy link
Member

@ggiraldez ggiraldez left a comment

Choose a reason for hiding this comment

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

Looks good! Check the comments for improvements suggestions. Seeing the amount of string manipulation and building in the UI, it may be beneficial to add the cuerdas library or something similar. But it's probably a bit late in the iteration.

[{:keys [capacity-unit demand-unit] :as props} {:keys [name change satisfied-demand] :as provider}]
(let [action (:action change)]
[:div
[:div {:class-name "section changeset-row"
Copy link
Member

Choose a reason for hiding this comment

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

For fixed CSS classes, the notation on the keyword is preferred. Eg. :div.section.changeset-row in this case.

Comment on lines 38 to 48
(str (get action-texts action)
" "
(utils/format-number (:capacity change))
" "
capacity-unit
" to serve "
(utils/format-number satisfied-demand)
" "
demand-unit
(when (pos? (:investment change))
(str " at " (utils/format-currency (:investment change)))))]]]]
Copy link
Member

Choose a reason for hiding this comment

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

I'd extract this into a function and try to keep the action string prefix (action-texts) together with the rest of the interpolation. That way you can easily spot if the whole sentence makes sense. Eg.

(defn- action-string
  [{:keys [action capacity capacity-unit demand-unit investment satisfied-demand]}]
  (let [formatted-capacity (format-number-with-unit capacity capacity-unit)
        formatted-demand (format-number-with-unit satisfied-demand demand-unit)
        formatted-investment (when (pos? investment) (str " at " (utils/format-currency investment)))]
    (case action
      "create-provider"   (str "New build with " formatted-capacity " to serve " formatted-demand formatted-investment)
      "upgrade-provider"  (str "Upgraded and increased capacity on " formatted-capacity " to serve " formatted-demand formatted-investment)
      "increase-provider" (str "Increased capacity on " formatted-capacity " to serve " formatted-demand formatted-investment)))

There is a bit of repetition, but I think it's worth it and makes it easier to change the phrase for one type of change if necessary. The investment part is still "hard-coded" and could even be extracted further, or maybe you could enumerate all 6 cases separately (the 3 actions, with or without investment).

@ismaelbej ismaelbej merged commit 616bb75 into master May 12, 2021
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