Skip to content
Snippets Groups Projects
Unverified Commit fcca326e authored by Aleksander Nicacio da Silva's avatar Aleksander Nicacio da Silva Committed by GitHub
Browse files

fix: selected options not being displayed on `PaginatedMultiSelect` (#30470)

parent 7e75bd87
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ type AutoCompleteDepartmentMultipleProps = { ...@@ -17,7 +17,7 @@ type AutoCompleteDepartmentMultipleProps = {
}; };
const AutoCompleteDepartmentMultiple = ({ const AutoCompleteDepartmentMultiple = ({
value, value = [],
onlyMyDepartments = false, onlyMyDepartments = false,
showArchived = false, showArchived = false,
enabled = false, enabled = false,
...@@ -37,6 +37,11 @@ const AutoCompleteDepartmentMultiple = ({ ...@@ -37,6 +37,11 @@ const AutoCompleteDepartmentMultiple = ({
const { phase: departmentsPhase, items: departmentsItems, itemCount: departmentsTotal } = useRecordList(departmentsList); const { phase: departmentsPhase, items: departmentsItems, itemCount: departmentsTotal } = useRecordList(departmentsList);
const departmentOptions = useMemo(() => {
const pending = value.filter(({ value }) => !departmentsItems.find((dep) => dep.value === value)) || [];
return [...departmentsItems, ...pending];
}, [departmentsItems, value]);
return ( return (
<PaginatedMultiSelectFiltered <PaginatedMultiSelectFiltered
withTitle withTitle
...@@ -44,7 +49,7 @@ const AutoCompleteDepartmentMultiple = ({ ...@@ -44,7 +49,7 @@ const AutoCompleteDepartmentMultiple = ({
onChange={onChange} onChange={onChange}
filter={departmentsFilter} filter={departmentsFilter}
setFilter={setDepartmentsFilter} setFilter={setDepartmentsFilter}
options={departmentsItems} options={departmentOptions}
width='100%' width='100%'
flexShrink={0} flexShrink={0}
flexGrow={0} flexGrow={0}
......
...@@ -38,6 +38,7 @@ export const useTagsList = (options: TagsListOptions): UseTagsListResult => { ...@@ -38,6 +38,7 @@ export const useTagsList = (options: TagsListOptions): UseTagsListResult => {
count: end + start, count: end + start,
...(viewAll && { viewAll: 'true' }), ...(viewAll && { viewAll: 'true' }),
...(department && { department }), ...(department && { department }),
sort: JSON.stringify({ name: 1 }),
}); });
return { return {
...@@ -45,7 +46,6 @@ export const useTagsList = (options: TagsListOptions): UseTagsListResult => { ...@@ -45,7 +46,6 @@ export const useTagsList = (options: TagsListOptions): UseTagsListResult => {
_id: tag._id, _id: tag._id,
label: tag.name, label: tag.name,
value: tag.name, value: tag.name,
_updatedAt: new Date(tag._updatedAt),
})), })),
itemCount: total, itemCount: total,
}; };
......
...@@ -24,16 +24,10 @@ const AutoCompleteTagMultiple = (props) => { ...@@ -24,16 +24,10 @@ const AutoCompleteTagMultiple = (props) => {
const { phase: tagsPhase, items: tagsItems, itemCount: tagsTotal } = useRecordList(tagsList); const { phase: tagsPhase, items: tagsItems, itemCount: tagsTotal } = useRecordList(tagsList);
const sortedByName = tagsItems.sort((a, b) => { const tagsOptions = useMemo(() => {
if (a.name > b.name) { const pending = value.filter(({ value }) => !tagsItems.find((tag) => tag.value === value));
return 1; return [...tagsItems, ...pending];
} }, [tagsItems, value]);
if (a.name < b.name) {
return -1;
}
return 0;
});
return ( return (
<PaginatedMultiSelectFiltered <PaginatedMultiSelectFiltered
...@@ -42,7 +36,7 @@ const AutoCompleteTagMultiple = (props) => { ...@@ -42,7 +36,7 @@ const AutoCompleteTagMultiple = (props) => {
onChange={onChange} onChange={onChange}
filter={tagsFilter} filter={tagsFilter}
setFilter={setTagsFilter} setFilter={setTagsFilter}
options={sortedByName} options={tagsOptions}
width='100%' width='100%'
flexShrink={0} flexShrink={0}
flexGrow={0} flexGrow={0}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment