[#596] displays all calendar from user in search even if one of them is present in the list of shared/delegated calendars (#604)
Co-authored-by: Camille Moussu <cmoussu@linagora.com>
This commit is contained in:
@@ -290,36 +290,6 @@ describe("calendar Availability search", () => {
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("does not import temp calendars if user already has a calendar but toggles the shared one", async () => {
|
||||
mockedSearchUsers.mockResolvedValueOnce([
|
||||
{
|
||||
email: "alice@example.com",
|
||||
displayName: "Alice",
|
||||
avatarUrl: "image.png",
|
||||
openpaasId: "1234567890",
|
||||
},
|
||||
]);
|
||||
const spy = jest
|
||||
.spyOn(servicesModule, "getTempCalendarsListAsync")
|
||||
.mockImplementation((payload) => {
|
||||
return () => Promise.resolve(payload) as any;
|
||||
});
|
||||
await act(async () =>
|
||||
renderWithProviders(<CalendarTestWrapper />, preloadedState)
|
||||
);
|
||||
|
||||
const input = screen.getByPlaceholderText(
|
||||
"peopleSearch.availabilityPlaceholder"
|
||||
);
|
||||
await act(async () => userEvent.type(input, "Alice"));
|
||||
|
||||
const option = await screen.findByText("Alice");
|
||||
await act(async () => {
|
||||
fireEvent.click(option);
|
||||
});
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("open window with attendees filled after temp search on create event button click", async () => {
|
||||
const spy = jest
|
||||
.spyOn(servicesModule, "getTempCalendarsListAsync")
|
||||
|
||||
@@ -646,8 +646,6 @@ export default function CalendarApp({
|
||||
handleToggleEventPreview={() => {
|
||||
eventHandlers.handleDateSelect(null as unknown as DateSelectArg);
|
||||
}}
|
||||
selectedCalendars={selectedCalendars}
|
||||
setSelectedCalendars={setSelectedCalendars}
|
||||
/>
|
||||
</Box>
|
||||
<div className="calendarList">
|
||||
|
||||
@@ -15,19 +15,14 @@ export function TempCalendarsInput({
|
||||
tempUsers,
|
||||
setTempUsers,
|
||||
handleToggleEventPreview,
|
||||
selectedCalendars,
|
||||
setSelectedCalendars,
|
||||
}: {
|
||||
tempUsers: User[];
|
||||
setTempUsers: (users: User[]) => void;
|
||||
handleToggleEventPreview: () => void;
|
||||
selectedCalendars: string[];
|
||||
setSelectedCalendars: React.Dispatch<React.SetStateAction<string[]>>;
|
||||
}) {
|
||||
const dispatch = useAppDispatch();
|
||||
const tempcalendars =
|
||||
useAppSelector((state) => state.calendars.templist) ?? {};
|
||||
const calendars = useAppSelector((state) => state.calendars.list);
|
||||
const theme = useTheme();
|
||||
const { t } = useI18n();
|
||||
|
||||
@@ -48,14 +43,9 @@ export function TempCalendarsInput({
|
||||
|
||||
prevUsersRef.current = users;
|
||||
|
||||
const { calendarsToImport, calendarsToToggle } = getCalendarsFromUsersDelta(
|
||||
addedUsers,
|
||||
buildEmailToCalendarMap(calendars),
|
||||
selectedCalendars
|
||||
);
|
||||
|
||||
if (calendarsToImport.length > 0) {
|
||||
for (const user of calendarsToImport) {
|
||||
if (addedUsers.length > 0) {
|
||||
dispatch(setView("calendar"));
|
||||
for (const user of addedUsers) {
|
||||
const controller = new AbortController();
|
||||
requestControllers.set(user.email, controller);
|
||||
|
||||
@@ -70,19 +60,12 @@ export function TempCalendarsInput({
|
||||
light: lightColor,
|
||||
dark: getAccessiblePair(lightColor, theme),
|
||||
};
|
||||
dispatch(setView("calendar"));
|
||||
dispatch(
|
||||
getTempCalendarsListAsync(user, { signal: controller.signal })
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (calendarsToToggle.length > 0) {
|
||||
setSelectedCalendars((prev: string[]) => [
|
||||
...new Set([...prev, ...calendarsToToggle]),
|
||||
]);
|
||||
}
|
||||
|
||||
for (const user of removedUsers) {
|
||||
const controller = requestControllers.get(user.email);
|
||||
if (controller) {
|
||||
@@ -108,29 +91,6 @@ export function TempCalendarsInput({
|
||||
);
|
||||
}
|
||||
|
||||
function getCalendarsFromUsersDelta(
|
||||
addedUsers: User[],
|
||||
emailToCalendarId: Map<string, string[]>,
|
||||
selectedCalendars: string[]
|
||||
) {
|
||||
const selectedSet = new Set(selectedCalendars);
|
||||
|
||||
const calendarsToImport: User[] = [];
|
||||
const calendarsToToggle: string[] = [];
|
||||
|
||||
for (const user of addedUsers) {
|
||||
const calIds = emailToCalendarId.get(user.email) ?? [];
|
||||
|
||||
if (!calIds || calIds.every((calId) => !selectedSet.has(calId))) {
|
||||
calendarsToImport.push(user);
|
||||
} else {
|
||||
// calIds.forEach((calId) => calendarsToToggle.push(calId));
|
||||
}
|
||||
}
|
||||
|
||||
return { calendarsToImport, calendarsToToggle };
|
||||
}
|
||||
|
||||
function buildEmailToCalendarMap(calRecord: Record<string, Calendar>) {
|
||||
const map = new Map<string, string[]>();
|
||||
for (const [id, cal] of Object.entries(calRecord)) {
|
||||
|
||||
Reference in New Issue
Block a user