-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Categories UI/UX #26501
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
Categories UI/UX #26501
Changes from all commits
9de59bd
0de8fc9
a4e8623
ce8519c
4271f61
df09636
3136cba
8ab4fa4
16584e9
ed22582
9ec3adf
e84005d
b7a28e1
c1bedca
24b3f85
b8acd96
678b4c6
2b481b2
9064496
8ef7ad3
b2bd62e
30210f7
5212989
c6eaa66
46ef605
136db9d
323184b
e96b876
a83a539
b1c72c4
a688c13
d2cf77a
f89e2f3
1d1ee6d
75e808d
099c1fc
c2ad63e
b55359e
0e0f317
e49f2dd
d7e1560
c2980fe
278b103
d59ddb1
4cdf856
10a711a
c6f425f
90dd075
748dcfc
5acfae0
b5d1657
c3a77d1
0fbc6d1
1a7cb65
3d47748
305b6a2
b61d13a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,88 @@ | ||
| import React, {useMemo} from 'react'; | ||
| import _ from 'underscore'; | ||
| import React, {useMemo, useState} from 'react'; | ||
| import {withOnyx} from 'react-native-onyx'; | ||
| import _ from 'underscore'; | ||
| import lodashGet from 'lodash/get'; | ||
| import ONYXKEYS from '../../ONYXKEYS'; | ||
| import {propTypes, defaultProps} from './categoryPickerPropTypes'; | ||
| import OptionsList from '../OptionsList'; | ||
| import styles from '../../styles/styles'; | ||
| import ScreenWrapper from '../ScreenWrapper'; | ||
| import Navigation from '../../libs/Navigation/Navigation'; | ||
| import ROUTES from '../../ROUTES'; | ||
| import CONST from '../../CONST'; | ||
| import * as IOU from '../../libs/actions/IOU'; | ||
| import * as OptionsListUtils from '../../libs/OptionsListUtils'; | ||
| import OptionsSelector from '../OptionsSelector'; | ||
| import useLocalize from '../../hooks/useLocalize'; | ||
|
|
||
| function CategoryPicker({policyCategories, reportID, iouType, iou, policyRecentlyUsedCategories}) { | ||
| const {translate} = useLocalize(); | ||
| const [searchValue, setSearchValue] = useState(''); | ||
|
|
||
| const policyCategoriesCount = _.size(policyCategories); | ||
| const isCategoriesCountBelowThreshold = policyCategoriesCount < CONST.CATEGORY_LIST_THRESHOLD; | ||
|
rezkiy37 marked this conversation as resolved.
|
||
|
|
||
| function CategoryPicker({policyCategories, reportID, iouType}) { | ||
| const sections = useMemo(() => { | ||
| const categoryList = _.chain(policyCategories) | ||
| .values() | ||
| .map((category) => ({ | ||
| text: category.name, | ||
| keyForList: category.name, | ||
| tooltipText: category.name, | ||
| })) | ||
| .value(); | ||
| const selectedOptions = useMemo(() => { | ||
| if (!iou.category) { | ||
| return []; | ||
| } | ||
|
|
||
| return [ | ||
| { | ||
| data: categoryList, | ||
| name: iou.category, | ||
| enabled: true, | ||
| accountID: null, | ||
| }, | ||
| ]; | ||
| }, [policyCategories]); | ||
| }, [iou.category]); | ||
|
|
||
| const initialFocusedIndex = useMemo(() => { | ||
| if (isCategoriesCountBelowThreshold && selectedOptions.length > 0) { | ||
| return _.chain(policyCategories) | ||
| .values() | ||
| .findIndex((category) => category.name === selectedOptions[0].name, true) | ||
| .value(); | ||
| } | ||
|
|
||
| return 0; | ||
| }, [policyCategories, selectedOptions, isCategoriesCountBelowThreshold]); | ||
|
|
||
| const sections = useMemo( | ||
| () => OptionsListUtils.getNewChatOptions({}, {}, [], searchValue, selectedOptions, [], false, false, true, policyCategories, policyRecentlyUsedCategories, false).categoryOptions, | ||
| [policyCategories, policyRecentlyUsedCategories, searchValue, selectedOptions], | ||
| ); | ||
|
|
||
| const headerMessage = OptionsListUtils.getHeaderMessage(lodashGet(sections, '[0].data.length', 0) > 0, false, searchValue); | ||
|
Member
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. Hi, issue: #28078
Contributor
Author
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. @rushatgabhane, is it fixed already or I can work on it?
Member
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. it's fixed in the linked issue |
||
| const shouldShowTextInput = !isCategoriesCountBelowThreshold; | ||
|
|
||
| const navigateBack = () => { | ||
| Navigation.goBack(ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID)); | ||
| }; | ||
|
|
||
| const updateCategory = (category) => { | ||
| if (category.searchText === iou.category) { | ||
| IOU.resetMoneyRequestCategory(); | ||
| } else { | ||
| IOU.setMoneyRequestCategory(category.searchText); | ||
| } | ||
|
|
||
| navigateBack(); | ||
| }; | ||
|
|
||
| return ( | ||
| <ScreenWrapper includeSafeAreaPaddingBottom={false}> | ||
| {({safeAreaPaddingBottomStyle}) => ( | ||
| <OptionsList | ||
| optionHoveredStyle={styles.hoveredComponentBG} | ||
| contentContainerStyles={[safeAreaPaddingBottomStyle]} | ||
| sections={sections} | ||
| onSelectRow={navigateBack} | ||
| /> | ||
| )} | ||
| </ScreenWrapper> | ||
| <OptionsSelector | ||
| optionHoveredStyle={styles.hoveredComponentBG} | ||
| sections={sections} | ||
| selectedOptions={selectedOptions} | ||
| value={searchValue} | ||
| initialFocusedIndex={initialFocusedIndex} | ||
| headerMessage={headerMessage} | ||
| shouldShowTextInput={shouldShowTextInput} | ||
| textInputLabel={translate('common.search')} | ||
| boldStyle | ||
| highlightSelectedOptions | ||
| isRowMultilineSupported | ||
| onChangeText={setSearchValue} | ||
| onSelectRow={updateCategory} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -53,4 +94,10 @@ export default withOnyx({ | |
| policyCategories: { | ||
| key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, | ||
| }, | ||
| policyRecentlyUsedCategories: { | ||
| key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, | ||
| }, | ||
| iou: { | ||
| key: ONYXKEYS.IOU, | ||
| }, | ||
| })(CategoryPicker); | ||
Uh oh!
There was an error while loading. Please reload this page.