Skip to content

Commit

Permalink
regression: fix departments with empty ancestors not being returned (#…
Browse files Browse the repository at this point in the history
…22068)

* Regression: fix departments with empty ancestors not being returned

* fix not being able to select the same thing again
  • Loading branch information
MartinSchoeler authored and sampaiodiego committed May 19, 2021
1 parent fdb6639 commit a1d4be4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions ee/app/livechat-enterprise/server/lib/Department.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ export const findAllDepartmentsAvailable = async (unitId, offset, count, text) =
const filterReg = new RegExp(escapeRegExp(text), 'i');

const cursor = LivechatDepartment.find({
$or: [{ ancestors: { $in: [unitId] } }, { ancestors: { $exists: false } }],
$or: [{ ancestors: { $in: [[unitId], null, []] } }, { ancestors: { $exists: false } }],
...text && { name: filterReg },

}, { limit: count, offset });

const departments = await cursor.toArray();
const total = await cursor.count();
const departmentsFiltered = departments.filter((department) => !department.ancestors?.length);

return { departments: departmentsFiltered, total };
return { departments, total };
};

export const findAllDepartmentsByUnit = async (unitId, offset, count) => {
Expand Down
4 changes: 2 additions & 2 deletions ee/client/omnichannel/units/UnitEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ function UnitEdit({ data, unitId, isNew, unitMonitors, unitDepartments, reload,
const [departmentsFilter, setDepartmentsFilter] = useState('');

const { itemsList: monitorsList, loadMoreItems: loadMoreMonitors } = useMonitorsList(
useMemo(() => ({ limit: 50, filter: monitorsFilter }), [monitorsFilter]),
useMemo(() => ({ filter: monitorsFilter }), [monitorsFilter]),
);

const { phase: monitorsPhase, items: monitorsItems, itemCount: monitorsTotal } = useRecordList(
monitorsList,
);

const { itemsList: departmentsList, loadMoreItems: loadMoreDepartments } = useDepartmentsList(
useMemo(() => ({ limit: 50, filter: departmentsFilter }), [departmentsFilter]),
useMemo(() => ({ filter: departmentsFilter, unitId }), [departmentsFilter, unitId]),
);

const {
Expand Down

0 comments on commit a1d4be4

Please sign in to comment.