-
Notifications
You must be signed in to change notification settings - Fork 6
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
Conversation
ced16a7
to
67b867c
Compare
3a2246e
to
58e81ca
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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.
(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)))))]]]] |
There was a problem hiding this comment.
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).
Also includes #644 and #651.