[#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();
|
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 () => {
|
it("open window with attendees filled after temp search on create event button click", async () => {
|
||||||
const spy = jest
|
const spy = jest
|
||||||
.spyOn(servicesModule, "getTempCalendarsListAsync")
|
.spyOn(servicesModule, "getTempCalendarsListAsync")
|
||||||
|
|||||||
@@ -646,8 +646,6 @@ export default function CalendarApp({
|
|||||||
handleToggleEventPreview={() => {
|
handleToggleEventPreview={() => {
|
||||||
eventHandlers.handleDateSelect(null as unknown as DateSelectArg);
|
eventHandlers.handleDateSelect(null as unknown as DateSelectArg);
|
||||||
}}
|
}}
|
||||||
selectedCalendars={selectedCalendars}
|
|
||||||
setSelectedCalendars={setSelectedCalendars}
|
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
<div className="calendarList">
|
<div className="calendarList">
|
||||||
|
|||||||
@@ -15,19 +15,14 @@ export function TempCalendarsInput({
|
|||||||
tempUsers,
|
tempUsers,
|
||||||
setTempUsers,
|
setTempUsers,
|
||||||
handleToggleEventPreview,
|
handleToggleEventPreview,
|
||||||
selectedCalendars,
|
|
||||||
setSelectedCalendars,
|
|
||||||
}: {
|
}: {
|
||||||
tempUsers: User[];
|
tempUsers: User[];
|
||||||
setTempUsers: (users: User[]) => void;
|
setTempUsers: (users: User[]) => void;
|
||||||
handleToggleEventPreview: () => void;
|
handleToggleEventPreview: () => void;
|
||||||
selectedCalendars: string[];
|
|
||||||
setSelectedCalendars: React.Dispatch<React.SetStateAction<string[]>>;
|
|
||||||
}) {
|
}) {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const tempcalendars =
|
const tempcalendars =
|
||||||
useAppSelector((state) => state.calendars.templist) ?? {};
|
useAppSelector((state) => state.calendars.templist) ?? {};
|
||||||
const calendars = useAppSelector((state) => state.calendars.list);
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
@@ -48,14 +43,9 @@ export function TempCalendarsInput({
|
|||||||
|
|
||||||
prevUsersRef.current = users;
|
prevUsersRef.current = users;
|
||||||
|
|
||||||
const { calendarsToImport, calendarsToToggle } = getCalendarsFromUsersDelta(
|
if (addedUsers.length > 0) {
|
||||||
addedUsers,
|
dispatch(setView("calendar"));
|
||||||
buildEmailToCalendarMap(calendars),
|
for (const user of addedUsers) {
|
||||||
selectedCalendars
|
|
||||||
);
|
|
||||||
|
|
||||||
if (calendarsToImport.length > 0) {
|
|
||||||
for (const user of calendarsToImport) {
|
|
||||||
const controller = new AbortController();
|
const controller = new AbortController();
|
||||||
requestControllers.set(user.email, controller);
|
requestControllers.set(user.email, controller);
|
||||||
|
|
||||||
@@ -70,19 +60,12 @@ export function TempCalendarsInput({
|
|||||||
light: lightColor,
|
light: lightColor,
|
||||||
dark: getAccessiblePair(lightColor, theme),
|
dark: getAccessiblePair(lightColor, theme),
|
||||||
};
|
};
|
||||||
dispatch(setView("calendar"));
|
|
||||||
dispatch(
|
dispatch(
|
||||||
getTempCalendarsListAsync(user, { signal: controller.signal })
|
getTempCalendarsListAsync(user, { signal: controller.signal })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (calendarsToToggle.length > 0) {
|
|
||||||
setSelectedCalendars((prev: string[]) => [
|
|
||||||
...new Set([...prev, ...calendarsToToggle]),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const user of removedUsers) {
|
for (const user of removedUsers) {
|
||||||
const controller = requestControllers.get(user.email);
|
const controller = requestControllers.get(user.email);
|
||||||
if (controller) {
|
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>) {
|
function buildEmailToCalendarMap(calRecord: Record<string, Calendar>) {
|
||||||
const map = new Map<string, string[]>();
|
const map = new Map<string, string[]>();
|
||||||
for (const [id, cal] of Object.entries(calRecord)) {
|
for (const [id, cal] of Object.entries(calRecord)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user