Skip to content
Closed
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
29 changes: 17 additions & 12 deletions src/components/TagPicker/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,25 +37,30 @@ function TagPicker({selectedTag, tag, policyTags, policyRecentlyUsedTags, onSubm
];
}, [selectedTag]);

const enabledTags = useMemo(() => {
const sortedTagList = _.chain(policyTagList)
.values()
.sortBy((policyTag) => policyTag.name)
.value();
Comment on lines +41 to +44

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add policyTag.enabled filter logic here as we don't show disabled tags in any case

As you see, wrong index after I disable 2nd tag, though not visually noticeable

Screen.Recording.2023-11-22.at.6.01.51.AM.mov


if (!shouldShowDisabledAndSelectedOption) {
return sortedTagList;
}
Comment on lines +46 to +48

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I don't see the need of this early return.
Can't we apply same logic to both new request and edit request?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not too sure either. The name suggests that we display disabled tags, but I'm not sure that that's happening

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tienifr @robertKozik could you check this logic? It seems like we'd want to return the policyTagList if shouldShowDisabledAndSelectedOption is true and not the inverse like we have in the code, right?

const selectedNames = _.map(selectedOptions, (s) => s.name);
return _.chain(sortedTagList)
.filter((policyTag) => policyTag.enabled || selectedNames.includes(policyTag.name))
.value();
}, [selectedOptions, policyTagList, shouldShowDisabledAndSelectedOption]);

const initialFocusedIndex = useMemo(() => {
if (isTagsCountBelowThreshold && selectedOptions.length > 0) {
return _.chain(policyTagList)
.values()
Comment thread
luacmartins marked this conversation as resolved.
return _.chain(enabledTags)
Comment thread
luacmartins marked this conversation as resolved.
.findIndex((policyTag) => policyTag.name === selectedOptions[0].name, true)
.value();
}

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]);
}, [enabledTags, selectedOptions, isTagsCountBelowThreshold]);

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