Skip to content

Commit

Permalink
fix: selected departments not being displayed due to pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandernsilva committed Sep 12, 2023
1 parent 8202f27 commit 8788776
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/slimy-cheetahs-heal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rocket.chat/meteor': patch
---

Fixed selected departments not being displayed due to pagination
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ type DepartmentListItem = {
_id: string;
label: string;
value: string;
_updatedAt: Date;
};

export const useDepartmentsList = (
Expand Down Expand Up @@ -66,7 +65,6 @@ export const useDepartmentsList = (
_id,
label: department.archived ? `${name} [${t('Archived')}]` : name,
value: _id,
_updatedAt: new Date(_updatedAt || ''),
};
});

Expand All @@ -75,15 +73,13 @@ export const useDepartmentsList = (
_id: '',
label: t('All'),
value: 'all',
_updatedAt: new Date(),
});

options.haveNone &&
items.unshift({
_id: '',
label: t('None'),
value: '',
_updatedAt: new Date(),
});

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const EditDepartmentWithData = ({ id, title }: EditDepartmentWithDataProps) => {
});

if (isInitialLoading) {
return <FormSkeleton />;
return <FormSkeleton padding='1.5rem 1rem' maxWidth='37.5rem' margin='0 auto' />;
}

if (isError || (id && !data?.department)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ export const DepartmentForwarding = ({ departmentId, value = [], handler, label

const { phase: departmentsPhase, items: departmentsItems, itemCount: departmentsTotal } = useRecordList(departmentsList);

const options = useMemo(() => {
const pending = value.filter(({ value }) => !departmentsItems.find((dep) => dep.value === value));
return [...departmentsItems, ...pending];
}, [departmentsItems, value]);

return (
<Field>
<Field.Label>{t(label)}</Field.Label>
Expand All @@ -41,7 +46,7 @@ export const DepartmentForwarding = ({ departmentId, value = [], handler, label
filter={debouncedDepartmentsFilter}
setFilter={setDepartmentsFilter}
onChange={handler}
options={departmentsItems}
options={options}
value={value}
placeholder={t('Select_an_option')}
endReached={
Expand Down

0 comments on commit 8788776

Please sign in to comment.