Skip to content
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

fix: 30380 Tag - Unable to unselect tag from created expense when the tag is disabled #30672

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/components/TagPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import {defaultProps, propTypes} from './tagPickerPropTypes';

function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubmit}) {
function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubmit, shouldShowDisabledAndSelectedOption}) {
const styles = useThemeStyles();
const {translate} = useLocalize();
const [searchValue, setSearchValue] = useState('');
Expand Down Expand Up @@ -48,10 +48,18 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm
return 0;
}, [policyTagList, selectedOptions, isTagsCountBelowThreshold]);

const enabledTags = useMemo(() => {
if (!shouldShowDisabledAndSelectedOption) {
return policyTagList;
}
const selectedNames = _.map(selectedOptions, (s) => s.name);
const tags = [...selectedOptions, ..._.filter(policyTagList, (policyTag) => policyTag.enabled && !selectedNames.includes(policyTag.name))];
return tags;
}, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]);

const sections = useMemo(
() =>
OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], true, policyTagList, policyRecentlyUsedTagsList, false).tagOptions,
[searchValue, selectedOptions, policyTagList, policyRecentlyUsedTagsList],
() => OptionsListUtils.getFilteredOptions({}, {}, [], searchValue, selectedOptions, [], false, false, false, {}, [], true, enabledTags, policyRecentlyUsedTagsList, false).tagOptions,
[searchValue, enabledTags, selectedOptions, policyRecentlyUsedTagsList],
);

const headerMessage = OptionsListUtils.getHeaderMessageForNonUserList(lodashGet(sections, '[0].data.length', 0) > 0, searchValue);
Expand Down
4 changes: 4 additions & 0 deletions src/components/TagPicker/tagPickerPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,15 @@ const propTypes = {

/** List of recently used tags */
policyRecentlyUsedTags: PropTypes.objectOf(PropTypes.arrayOf(PropTypes.string)),

/** Should show the selected option that is disabled? */
shouldShowDisabledAndSelectedOption: PropTypes.bool,
};

const defaultProps = {
policyTags: {},
policyRecentlyUsedTags: {},
shouldShowDisabledAndSelectedOption: false,
};

export {propTypes, defaultProps};
1 change: 1 addition & 0 deletions src/pages/EditRequestTagPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ function EditRequestTagPage({defaultTag, policyID, tagName, onSubmit}) {
tag={tagName}
policyID={policyID}
onSubmit={selectTag}
shouldShowDisabledAndSelectedOption
/>
</ScreenWrapper>
);
Expand Down
Loading