Skip to content

Commit d00a4d6

Browse files
authored
Merge pull request #27765 from BeeMargarida/feat/26126-tag_picker_sections
#26126: Tag picker sections
2 parents 665c7e9 + 993b4c2 commit d00a4d6

14 files changed

+657
-116
lines changed

src/CONST.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,7 @@ const CONST = {
26382638
INDENTS: ' ',
26392639
PARENT_CHILD_SEPARATOR: ': ',
26402640
CATEGORY_LIST_THRESHOLD: 8,
2641+
TAG_LIST_THRESHOLD: 8,
26412642
DEMO_PAGES: {
26422643
SAASTR: 'SaaStrDemoSetup',
26432644
SBE: 'SbeDemoSetup',

src/components/CategoryPicker/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function CategoryPicker({policyCategories, reportID, iouType, iou, policyRecentl
4646
}, [policyCategories, selectedOptions, isCategoriesCountBelowThreshold]);
4747

4848
const sections = useMemo(
49-
() => OptionsListUtils.getNewChatOptions({}, {}, [], searchValue, selectedOptions, [], false, false, true, policyCategories, policyRecentlyUsedCategories, false).categoryOptions,
49+
() => OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, true, policyCategories, policyRecentlyUsedCategories, false).categoryOptions,
5050
[policyCategories, policyRecentlyUsedCategories, searchValue, selectedOptions],
5151
);
5252

src/components/MoneyRequestConfirmationList.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ function MoneyRequestConfirmationList(props) {
201201
const tagList = lodashGet(props.policyTags, [tagListKey, 'tags'], []);
202202
const tagListName = lodashGet(props.policyTags, [tagListKey, 'name'], '');
203203
const canUseTags = Permissions.canUseTags(props.betas);
204+
const shouldShowTags = canUseTags && _.any(tagList, (tag) => tag.enabled);
204205

205206
const hasRoute = TransactionUtils.hasRoute(transaction);
206207
const isDistanceRequestWithoutRoute = props.isDistanceRequest && !hasRoute;
@@ -527,7 +528,7 @@ function MoneyRequestConfirmationList(props) {
527528
disabled={didConfirm || props.isReadOnly}
528529
/>
529530
)}
530-
{canUseTags && !!tagList && (
531+
{shouldShowTags && (
531532
<MenuItemWithTopDescription
532533
shouldShowRightIcon={!props.isReadOnly}
533534
title={props.iouTag}

src/components/TagPicker/index.js

Lines changed: 37 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,58 @@
1-
import React, {useMemo} from 'react';
1+
import React, {useMemo, useState} from 'react';
22
import _ from 'underscore';
33
import lodashGet from 'lodash/get';
44
import {withOnyx} from 'react-native-onyx';
5+
import CONST from '../../CONST';
56
import ONYXKEYS from '../../ONYXKEYS';
67
import styles from '../../styles/styles';
7-
import Navigation from '../../libs/Navigation/Navigation';
8-
import ROUTES from '../../ROUTES';
98
import useLocalize from '../../hooks/useLocalize';
109
import * as OptionsListUtils from '../../libs/OptionsListUtils';
1110
import OptionsSelector from '../OptionsSelector';
1211
import {propTypes, defaultProps} from './tagPickerPropTypes';
1312

14-
function TagPicker({policyTags, reportID, tag, iouType, iou}) {
13+
function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubmit}) {
1514
const {translate} = useLocalize();
15+
const [searchValue, setSearchValue] = useState('');
16+
17+
const policyRecentlyUsedTagsList = lodashGet(policyRecentlyUsedTags, tag, []);
18+
const policyTagList = lodashGet(policyTags, [tag, 'tags'], {});
19+
const policyTagsCount = _.size(_.filter(policyTagList, (policyTag) => policyTag.enabled));
20+
const isTagsCountBelowThreshold = policyTagsCount < CONST.TAG_LIST_THRESHOLD;
21+
22+
const shouldShowTextInput = !isTagsCountBelowThreshold;
1623

1724
const selectedOptions = useMemo(() => {
18-
if (!iou.tag) {
25+
if (!selectedTag) {
1926
return [];
2027
}
2128

2229
return [
2330
{
24-
name: iou.tag,
31+
name: selectedTag,
2532
enabled: true,
33+
accountID: null,
2634
},
2735
];
28-
}, [iou.tag]);
29-
30-
// Only shows one section, which will be the default behavior if there are
31-
// less than 8 policy tags
32-
// TODO: support sections with search
33-
const sections = useMemo(() => {
34-
const tagList = _.chain(lodashGet(policyTags, [tag, 'tags'], {}))
35-
.values()
36-
.map((t) => ({
37-
text: t.name,
38-
keyForList: t.name,
39-
tooltipText: t.name,
40-
}))
41-
.value();
36+
}, [selectedTag]);
4237

43-
return [
44-
{
45-
data: tagList,
46-
},
47-
];
48-
}, [policyTags, tag]);
38+
const initialFocusedIndex = useMemo(() => {
39+
if (isTagsCountBelowThreshold && selectedOptions.length > 0) {
40+
return _.chain(policyTagList)
41+
.values()
42+
.findIndex((policyTag) => policyTag.name === selectedOptions[0].name, true)
43+
.value();
44+
}
4945

50-
const headerMessage = OptionsListUtils.getHeaderMessage(lodashGet(sections, '[0].data.length', 0) > 0, false, '');
46+
return 0;
47+
}, [policyTagList, selectedOptions, isTagsCountBelowThreshold]);
5148

52-
const navigateBack = () => {
53-
Navigation.goBack(ROUTES.getMoneyRequestConfirmationRoute(iouType, reportID));
54-
};
49+
const sections = useMemo(
50+
() =>
51+
OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], true, policyTagList, policyRecentlyUsedTagsList, false).tagOptions,
52+
[searchValue, selectedOptions, policyTagList, policyRecentlyUsedTagsList],
53+
);
5554

56-
const updateTag = () => {
57-
// TODO: add logic to save the selected tag
58-
navigateBack();
59-
};
55+
const headerMessage = OptionsListUtils.getHeaderMessage(lodashGet(sections, '[0].data.length', 0) > 0, false, '');
6056

6157
return (
6258
<OptionsSelector
@@ -66,9 +62,13 @@ function TagPicker({policyTags, reportID, tag, iouType, iou}) {
6662
headerMessage={headerMessage}
6763
textInputLabel={translate('common.search')}
6864
boldStyle
69-
value=""
70-
onSelectRow={updateTag}
71-
shouldShowTextInput={false}
65+
highlightSelectedOptions
66+
isRowMultilineSupported
67+
shouldShowTextInput={shouldShowTextInput}
68+
value={searchValue}
69+
initialFocusedIndex={initialFocusedIndex}
70+
onChangeText={setSearchValue}
71+
onSelectRow={onSubmit}
7272
/>
7373
);
7474
}
@@ -84,7 +84,4 @@ export default withOnyx({
8484
policyRecentlyUsedTags: {
8585
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${policyID}`,
8686
},
87-
iou: {
88-
key: ONYXKEYS.IOU,
89-
},
9087
})(TagPicker);
Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
import PropTypes from 'prop-types';
22
import tagPropTypes from '../tagPropTypes';
3-
import {iouPropTypes, iouDefaultProps} from '../../pages/iou/propTypes';
43

54
const propTypes = {
6-
/** The report ID of the IOU */
7-
reportID: PropTypes.string.isRequired,
8-
95
/** The policyID we are getting tags for */
106
policyID: PropTypes.string.isRequired,
117

8+
/** The selected tag of the money request */
9+
selectedTag: PropTypes.string.isRequired,
10+
1211
/** The name of tag list we are getting tags for */
1312
tag: PropTypes.string.isRequired,
1413

15-
/** The type of IOU report, i.e. bill, request, send */
16-
iouType: PropTypes.string.isRequired,
17-
1814
/** Callback to submit the selected tag */
19-
onSubmit: PropTypes.func,
15+
onSubmit: PropTypes.func.isRequired,
2016

2117
/* Onyx Props */
2218
/** Collection of tags attached to a policy */
@@ -29,15 +25,11 @@ const propTypes = {
2925

3026
/** List of recently used tags */
3127
policyRecentlyUsedTags: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string)),
32-
33-
/** Holds data related to Money Request view state, rather than the underlying Money Request data. */
34-
iou: iouPropTypes,
3528
};
3629

3730
const defaultProps = {
3831
policyTags: {},
3932
policyRecentlyUsedTags: {},
40-
iou: iouDefaultProps,
4133
};
4234

4335
export {propTypes, defaultProps};

0 commit comments

Comments
 (0)