-
Notifications
You must be signed in to change notification settings - Fork 114
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
Customize Labels Step 1 #1110
Customize Labels Step 1 #1110
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1110 +/- ##
==========================================
- Coverage 77.55% 76.96% -0.59%
==========================================
Files 28 28
Lines 1702 1715 +13
Branches 367 367
==========================================
Hits 1320 1320
- Misses 382 395 +13
Flags with carried forward coverage won't be shown. Click here to find out more.
|
increase new mode frequency and decrease old mode frequency
@JGreenlee |
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.
Good first steps. Interface looks great!
Left some comments for code cleanliness + an open question about performance
const chosenLabel = useMemo<string>(() => { | ||
if (otherLabel != null) return 'other'; | ||
return timelineLabelMap[trip._id.$oid]?.[modalVisibleFor]?.value; | ||
}, [modalVisibleFor, otherLabel]); | ||
|
||
const initialLabel = chosenLabel; |
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 don't see the purpose of this variable. It seems like initialLabel
will always be the same as chosenLabel
.
It is never reassigned (and can't be anyway because it is const
)
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.
The reason I used initialLabel
was that I couldn't access the 'chosenLabel' value because the store
function had a 'chosenLabel' parameter.
To access chosenLabel
, I needed to either change the parameter name from chosenLabel
to a different one or create a new variable that contains chosenLabel
. That's why I declared 'initialLabel.'
I deleted line 50, changed chosenLabel
to initialLabel
, and modified the parameter name from chosenLabel
to newLabel
. I think it seems more intuitive.
Let me know if it doesn't make sense to you
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.
Great step forward! The logic in MultiLabelButtonGroup is cleaner now and I think this will be better for network performance.
Now, I have some questions about the design: Is this supposed to work for custom purposes too?
If so, it needs to be made more generic, and the feature may be more accurately described as "custom labels" rather than just "custom modes".
If not, we need to fix regressions. The current behavior is that the same list of "Custom modes" shows up for both "mode" and "purpose" popups, which is not what we want.
TODO : handling custom purpose label
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.
If the expectation for this PR is to only support custom modes, and not custom purposes / custom replaced modes, it looks ready.
However, if the expectation is to have both custom modes and custom purposes supported (as was supported previously), I would still suggest revising this PR to a more generic "custom labels" implementation. It would be more efficient to do in one PR rather than two.
Sending this along to the next step of review so @shankari can weigh in.
…replaced_mode ...) functions to em
@JGreenlee |
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 have a few other nitpicks for code style and tidieness left below
But when I tried to test this (I was using this branch customize-modes
and the server branch customize-modes
), I got the following peculiar result:
When I selected "Other" to add a custom mode, the text box appeared below, but the radio button next to "Other" did not fill in, making it look like "Other" was not selected
If I continued with trying to add a custom mode and clicked "Save", I got this message:
www/js/diary/LabelTab.tsx
Outdated
} from './LabelTabContext'; | ||
|
||
let showPlaces; | ||
const ONE_DAY = 24 * 60 * 60; // seconds | ||
const ONE_WEEK = ONE_DAY * 7; // seconds | ||
const CUSTOM_LABEL_KEYS = ['mode', 'purpose', 'replaced_mode']; |
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.
Why lowercase? As you may have noticed, the rest of the codebase uses uppercase.
I think if you stuck to uppercase, you wouldn't have to use .toLowercase()
a bunch of times
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 opted for lowercase because the keys in the database are stored in lowercase. This way, I aimed to send the key to the server without the need for any preprocessing. I changed variable name to CUSTOM_LABEL_KEYS_IN_DATABASE
. What do you think about it?
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.
That's a good reason and makes sense. Thanks for clarifying!
customLabel[key] = res['label']; | ||
setCustomLabel(customLabel); |
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 would use ...
here to create a shallow copy of the object with the new key added. This is to avoid mutating the old customLabel
object
customLabel[key] = res['label']; | |
setCustomLabel(customLabel); | |
setCustomLabel({ | |
...customLabel, | |
[key]: rest['label'], | |
}); |
www/js/diary/LabelTabContext.ts
Outdated
export type CustomLabelKey = { | ||
[k: string]: string[]; | ||
}; |
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.
When I initially saw customLabel
I thought it must contain just one label. Now that I am looking at the type definition I understand that it is an object of keys to string arrays.
Would you mind renaming customLabel
to something like customLabelMap
, or at least customLabels
?
Sorry to be picky but I think this could help others in the future comprehend the code better
@JGreenlee |
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.
Great! I created a new test user and verified that the error did not occur, so that was my mistake.
I also verified that the other comments have been addressed.
All I have left are a couple design questions:
-
Should the same list of custom modes be shared for "mode" and "replaced mode" ?
-- It was clear before that "mode" and "purpose" should be kept as separate lists. But after testing this branch and envisioning day-to-day use, I think it may be more logical for "replaced mode" to use the same list of custom labels as "mode". -
Is it necessary to have the section title "Default Mode", "Default Purpose", etc?
-- I think this takes up extra space and the layout would be clearer without it.
That's a very good point! I was also unsure in separating 'mode' and 'replaced_mode'. I agree with using the same list. Please check my updates! |
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.
LGTM!
…-mission-phone into customize-modes
Resolved merge conflicts. @jiji14 Can you please change the target of this PR to |
Done! |
@jiji14 I am reviewing this, but please note that the codecov tests are failing. The |
@shankari We're currently facing challenges with testing API fetching functions, as they rely on native functions within BEMServerComm. While considering mocking these native functions for testing purposes, we initially deemed it unnecessary, as it would involve skipping tests for the actual API fetching functions. However, I will do some research about it! Here are the comments about the test:
|
@jiji14 I saw that, but codecov didn't 😄 It is possible to mark these as integration wrapper functions so that codecov only considers them for integration tests? |
I am going to suggest that we close this PR and focus on the Step 2 PR (#1120), because:
So concretely, my suggestions for @jiji14:
|
@JGreenlee |
Related Issue
What I added
Next Step
Result
Please check out to
customize-modes
branch in theServer
repository for testing.