-
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
Custom Labels Step 2 #1120
Merged
Merged
Custom Labels Step 2 #1120
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
1b57f5e
show customized modes (used dummy data for now)
jiji14 cad2d7c
fix prettier issu
jiji14 74e2dfe
fetch post/mode
jiji14 0402a34
use displayErrorMsg
jiji14 09b56ee
Done with fetching data to server
jiji14 a3cb1f2
update mode - old mode and new mode
jiji14 abc7f8a
Change modes type to string array and call it when modal opens
jiji14 cb1c491
add comments
jiji14 0a7a4ba
change mode text in a desired format (ex) my_car => My Car
jiji14 8ba3fb6
add default mode & custom mode label
jiji14 aa18e98
noted that getModes & updateMode need to be tested after e2e testing …
jiji14 7548de7
reuse existing common function and delete the original function
jiji14 01c1afe
use dynamic color
jiji14 b5a63be
change logic for showing custom modes before 'other' option
jiji14 f64d719
change function names more descriptive
jiji14 14c4438
delete unnecessary variable and change variable names more intuitive
jiji14 447e7e2
add new translation entry
jiji14 0509d5e
Fetch custom modes on initial rendering to prevent unnecessary api calls
jiji14 23f4758
add 'custom modes' tab in Profile
jiji14 0ef37b4
Move customModes state to AppContext to be shared between the 'Label'…
jiji14 de9008f
separate the component for clean code
jiji14 07f4534
Add insert user custom mode feature
jiji14 189f79d
check if inputType is 'MODE' for custom mode label
jiji14 643ae90
Modify the mode functions to encompass all types of labels (purpose, …
jiji14 315561e
Merge branch 'customize-modes' into customize-modes-step2
jiji14 939480f
fix merge conflict related to LabelTabContext
jiji14 bf3754d
Done with "manage custom labels" in profile setting tab
jiji14 01a3729
fix radio button issue when 'other' option is selected
jiji14 8cec495
change variable names for better understanding
jiji14 606816b
update radio button comment
jiji14 2d7352b
combine replaced_mode and mode
jiji14 32e5708
Merge branch 'customize-modes' into customize-modes-step2
jiji14 5f87ab3
update merge changes
jiji14 d02d7aa
combine mode and replaced_mode for Label Setting
jiji14 f5f5551
error handling for empty label array
jiji14 4192269
add skipped test functions
jiji14 0e0569e
Change list title "edit custom labels" -> "manage custom labels""
jiji14 7eb31dd
Merge branch 'service_rewrite_2023' into customize-modes-step2
jiji14 2a1a12c
Merge branch 'customize-modes' of https://github.com/jiji14/e-mission…
JGreenlee 0c87797
bump 'react-native-paper' to ^5.11.0
JGreenlee 7e09923
Merge branch 'master' into customize-modes-step2
jiji14 ae66eff
fix label context issue after merge
jiji14 3453205
ignore commHelper from coverage report
jiji14 26264ce
delete not operator
jiji14 cba51b8
add comment why we need to ingnore commHelper in coverage report
jiji14 96386a3
delete duplicated code
jiji14 15c994a
show customLabel setting conditionally
jiji14 45bfc2d
Merge branch 'master' into customize-modes-step2
JGreenlee 52b0fb9
Merge branch 'master' of https://github.com/e-mission/e-mission-phone…
JGreenlee File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,16 +13,22 @@ | |
import { initPushNotify } from './splash/pushNotifySettings'; | ||
import { initStoreDeviceSettings } from './splash/storeDeviceSettings'; | ||
import { initRemoteNotifyHandler } from './splash/remoteNotifyHandler'; | ||
import { getUserCustomLabels } from './services/commHelper'; | ||
import { initCustomDatasetHelper } from './metrics/customMetricsHelper'; | ||
import AlertBar from './components/AlertBar'; | ||
import Main from './Main'; | ||
|
||
export const AppContext = createContext<any>({}); | ||
const CUSTOM_LABEL_KEYS_IN_DATABASE = ['mode', 'purpose']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @JGreenlee don't we need this for replaced mode as well? Or is the expectation that the replaced mode will also share the custom labels from the regular mode? |
||
type CustomLabelMap = { | ||
[k: string]: string[]; | ||
}; | ||
|
||
const App = () => { | ||
// will remain null while the onboarding state is still being determined | ||
const [onboardingState, setOnboardingState] = useState<OnboardingState | null>(null); | ||
const [permissionsPopupVis, setPermissionsPopupVis] = useState(false); | ||
const [customLabelMap, setCustomLabelMap] = useState<CustomLabelMap>({}); | ||
const appConfig = useAppConfig(); | ||
const permissionStatus = usePermissionStatus(); | ||
|
||
|
@@ -39,6 +45,7 @@ | |
initPushNotify(); | ||
initStoreDeviceSettings(); | ||
initRemoteNotifyHandler(); | ||
getUserCustomLabels(CUSTOM_LABEL_KEYS_IN_DATABASE).then((res) => setCustomLabelMap(res)); | ||
initCustomDatasetHelper(appConfig); | ||
}, [appConfig]); | ||
|
||
|
@@ -50,6 +57,8 @@ | |
permissionStatus, | ||
permissionsPopupVis, | ||
setPermissionsPopupVis, | ||
customLabelMap, | ||
setCustomLabelMap, | ||
}; | ||
|
||
let appContent; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import React, { useState, useContext } from 'react'; | ||
import SettingRow from './SettingRow'; | ||
import { | ||
Modal, | ||
View, | ||
Text, | ||
TouchableOpacity, | ||
StyleSheet, | ||
useWindowDimensions, | ||
ScrollView, | ||
} from 'react-native'; | ||
import { Icon, TextInput, Dialog, Button, useTheme, SegmentedButtons } from 'react-native-paper'; | ||
import { AppContext } from '../App'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { deleteUserCustomLabel, insertUserCustomLabel } from '../services/commHelper'; | ||
import { displayErrorMsg, logDebug } from '../plugin/logger'; | ||
import { labelKeyToReadable, readableLabelToKey } from '../survey/multilabel/confirmHelper'; | ||
|
||
const CustomLabelSettingRow = () => { | ||
const [isCustomLabelModalOpen, setIsCustomLabelModalOpen] = useState(false); | ||
const { customLabelMap, setCustomLabelMap } = useContext(AppContext); | ||
const [isAddLabelOn, setIsAddLabelOn] = useState(false); | ||
const [text, setText] = useState(''); | ||
const [key, setKey] = useState('mode'); | ||
|
||
const { t } = useTranslation(); //this accesses the translations | ||
const { colors } = useTheme(); // use this to get the theme colors instead of hardcoded #hex colors | ||
const { height } = useWindowDimensions(); | ||
|
||
const labelKeysButton = [ | ||
{ | ||
value: 'mode', | ||
label: t('diary.mode'), | ||
}, | ||
{ | ||
value: 'purpose', | ||
label: t('diary.purpose'), | ||
}, | ||
]; | ||
|
||
const onDeleteLabel = async (label) => { | ||
const processedLabel = readableLabelToKey(label); | ||
try { | ||
const res = await deleteUserCustomLabel(key, processedLabel); | ||
if (res) { | ||
setCustomLabelMap({ | ||
...customLabelMap, | ||
[key]: res['label'], | ||
}); | ||
logDebug(`Successfuly deleted custom ${key}, ${JSON.stringify(res)}`); | ||
} | ||
} catch (e) { | ||
displayErrorMsg(e, 'Delete Mode Error'); | ||
} | ||
}; | ||
|
||
const onSaveLabel = async () => { | ||
const processedLabel = readableLabelToKey(text); | ||
if (customLabelMap[key]?.length > 0 && customLabelMap[key].indexOf(processedLabel) > -1) { | ||
return; | ||
} | ||
try { | ||
const res = await insertUserCustomLabel(key, processedLabel); | ||
if (res) { | ||
setText(''); | ||
setCustomLabelMap({ | ||
...customLabelMap, | ||
[key]: res['label'], | ||
}); | ||
setIsAddLabelOn(false); | ||
logDebug(`Successfuly inserted custom ${key}, ${JSON.stringify(res)}`); | ||
} | ||
} catch (e) { | ||
displayErrorMsg(e, 'Create Mode Error'); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<SettingRow | ||
textKey="control.manage-custom-labels" | ||
iconName="label-multiple" | ||
action={() => setIsCustomLabelModalOpen(true)}></SettingRow> | ||
<Modal | ||
visible={isCustomLabelModalOpen} | ||
onDismiss={() => setIsCustomLabelModalOpen(false)} | ||
transparent={true}> | ||
<Dialog visible={isCustomLabelModalOpen} onDismiss={() => setIsCustomLabelModalOpen(false)}> | ||
<Dialog.Title> | ||
<Text>{t('trip-confirm.custom-labels')}</Text> | ||
<TouchableOpacity style={styles.plusIconWrapper} onPress={() => setIsAddLabelOn(true)}> | ||
<Icon source="plus-circle" size={24} /> | ||
</TouchableOpacity> | ||
</Dialog.Title> | ||
<Dialog.Content> | ||
<SegmentedButtons | ||
style={{ marginBottom: 10 }} | ||
value={key} | ||
onValueChange={setKey} | ||
buttons={labelKeysButton} | ||
/> | ||
{isAddLabelOn && ( | ||
<> | ||
<TextInput | ||
label={t('trip-confirm.services-please-fill-in', { | ||
text: key, | ||
})} | ||
value={text} | ||
onChangeText={setText} | ||
maxLength={25} | ||
style={{ marginTop: 10 }} | ||
/> | ||
<View style={styles.saveButtonWrapper}> | ||
<Button onPress={() => setIsAddLabelOn(false)}> | ||
{t('trip-confirm.services-cancel')} | ||
</Button> | ||
<Button onPress={onSaveLabel}>{t('trip-confirm.services-save')}</Button> | ||
</View> | ||
</> | ||
)} | ||
<ScrollView contentContainerStyle={{ height: height / 2 }}> | ||
{customLabelMap[key]?.length > 0 && | ||
customLabelMap[key].map((label, idx) => { | ||
return ( | ||
<View | ||
key={label + idx} | ||
style={[styles.itemWrapper, { borderBottomColor: colors.outline }]}> | ||
<Text>{labelKeyToReadable(label)}</Text> | ||
<TouchableOpacity onPress={() => onDeleteLabel(label)}> | ||
<Icon source="trash-can" size={20} /> | ||
</TouchableOpacity> | ||
</View> | ||
); | ||
})} | ||
</ScrollView> | ||
</Dialog.Content> | ||
<Dialog.Actions> | ||
<Button onPress={() => setIsCustomLabelModalOpen(false)}> | ||
{t('trip-confirm.services-cancel')} | ||
</Button> | ||
</Dialog.Actions> | ||
</Dialog> | ||
</Modal> | ||
</> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
itemWrapper: { | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
paddingVertical: 16, | ||
borderBottomWidth: 1, | ||
}, | ||
saveButtonWrapper: { | ||
display: 'flex', | ||
flexDirection: 'row', | ||
justifyContent: 'flex-end', | ||
}, | ||
plusIconWrapper: { | ||
position: 'absolute', | ||
right: 0, | ||
}, | ||
}); | ||
|
||
export default CustomLabelSettingRow; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Added Spanish translations in e-mission/e-mission-translate@e658a1a. Still need to add Lao translations @Abby-Wheelis