Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor editor organizer #540

Open
wants to merge 29 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3728fd6
feat: update card title for private appointments
nubsthead Nov 11, 2024
94dd625
test(titleRow): add test cases to display title
nubsthead Nov 12, 2024
102e316
refactor: split organizer data from organizer editor field
nubsthead Nov 14, 2024
ea284d3
Merge remote-tracking branch 'origin/devel' into refactor-editor-orga…
nubsthead Nov 15, 2024
4b454df
Merge branch 'devel' into refactor-editor-organizer
nubsthead Nov 15, 2024
06552bc
feat: update card title for private appointments
nubsthead Nov 11, 2024
b23333c
test(titleRow): add test cases to display title
nubsthead Nov 12, 2024
ff86d57
refactor: split organizer data from organizer editor field
nubsthead Nov 14, 2024
5100989
revert: undo changes introduce in react-18 migrations (#512)
frisonisland Nov 6, 2024
a87ef36
feat: get location from extensions (#513)
gnekoz Nov 6, 2024
fdc6d9f
test: add new tests (#503)
gnekoz Nov 13, 2024
1d64af8
fix: add bold to appointment cards title
nubsthead Nov 14, 2024
e355768
fix: remove sensible data
nubsthead Nov 15, 2024
34b8c45
chore: merge
nubsthead Nov 15, 2024
4bf23dd
fix: remove title-row changes
nubsthead Nov 15, 2024
af72777
test: implement tests for editor sender field
nubsthead Nov 15, 2024
e3770d8
chore: merge conflicts resolution
nubsthead Nov 15, 2024
02b3d83
Merge branch 'devel' into refactor-editor-organizer
nubsthead Nov 21, 2024
3c88824
fix: organizer and sender types fix
nubsthead Dec 10, 2024
4869883
fix: fix generate editor in reminder modal
nubsthead Dec 10, 2024
de35a99
chore: merge with devel
nubsthead Dec 10, 2024
4b35873
fix: update common submodule
nubsthead Dec 10, 2024
1c7cb34
fix: update reminder-modal setNewTime function
nubsthead Dec 10, 2024
f0e5e59
fix: setNewTime function in reminder-modal
nubsthead Dec 10, 2024
42e535c
Merge remote-tracking branch 'origin/devel' into refactor-editor-orga…
nubsthead Dec 24, 2024
86f5a83
chore: merge with devel
nubsthead Dec 24, 2024
ed012d5
fix: revert calendar event normalization
nubsthead Jan 2, 2025
ed2e1d8
Merge remote-tracking branch 'origin/devel' into refactor-editor-orga…
nubsthead Jan 3, 2025
04ad7b7
Merge branch 'devel' into refactor-editor-organizer
nubsthead Jan 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/actions/appointment-actions-fn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const createCopy =
folders: availableFolders,
dispatch: context.dispatch,
panel: context.panel ?? true,
organizer,
organizer: { email: organizer?.address ?? '', fullName: organizer?.fullName ?? '' },
recur: isSeries ? invite.recurrenceRule : undefined,
exceptId: undefined,
isInstance,
Expand Down
43 changes: 4 additions & 39 deletions src/commons/editor-generator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,8 @@ describe('Editor generator', () => {
// expect a default calendar is selected
expect(editor.calendar).toBeDefined();

// expect organizer to be defined and to be the default
expect(editor.organizer).toBeDefined();
expect(editor.organizer.fullName).toBe(identity1.fullName);
expect(editor.organizer.identityName).toBe('DEFAULT');

// all parameters are the default ones
expect(editor.allDay).toBe(false);
Expand Down Expand Up @@ -169,18 +167,14 @@ describe('Editor generator', () => {
}
],
organizer: {
address: '[email protected]',
fullName: 'Francesco Gottardi',
identityName: 'DEFAULT',
label: 'DEFAULT Francesco Gottardi (<[email protected]>) ',
type: undefined,
value: '0'
email: '[email protected]',
fullName: 'user fullName'
},
title: 'Single istance',
location: 'Location',
room: {
label: 'Room name',
link: 'https://mail.zextras.com/meeting/meet-now/ZWFGRAOJ'
link: 'https://room.link.com/meeting/meet-now/ZWFGRAOJ'
},
attendees: [],
optionalAttendees: [],
Expand Down Expand Up @@ -235,18 +229,11 @@ describe('Editor generator', () => {
expect(editor.plainText).toBe('test content');
expect(editor.richText).toBe('<p>test content</p>');
expect(editor.organizer).toBeDefined();
expect(editor.organizer).toHaveProperty(
'label',
'DEFAULT Francesco Gottardi (<[email protected]>) '
);
expect(editor.title).toBe('Single istance');
expect(editor.location).toBe('Location');
expect(editor.room).toBeDefined();
expect(editor.room).toHaveProperty('label', 'Room name');
expect(editor.room).toHaveProperty(
'link',
'https://mail.zextras.com/meeting/meet-now/ZWFGRAOJ'
);
expect(editor.room).toHaveProperty('link', 'https://room.link.com/meeting/meet-now/ZWFGRAOJ');
expect(editor.attendees).toStrictEqual([]);
expect(editor.optionalAttendees).toStrictEqual([]);
expect(editor.freeBusy).toBe('F');
Expand All @@ -266,26 +253,4 @@ describe('Editor generator', () => {
expect(editor.attachmentFiles[0].disposition).toBe('attachment');
});
});
describe('Edit event', () => {
test('event without organizer has the calendar owner as default', () => {
const store = configureStore({ reducer: combineReducers(reducers) });

const event = mockedData.getEvent({
resource: {
organizer: undefined,
calendar: folder
}
});
const invite = mockedData.getInvite({ event });

const context = { folders, dispatch: store.dispatch };
const editor = generateEditor({
context,
invite,
event
});
expect(editor.organizer.address).toBe(identity1.email);
expect(editor.organizer.fullName).toBe(identity1.fullName);
});
});
});
15 changes: 11 additions & 4 deletions src/commons/editor-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { getUserAccount } from '@zextras/carbonio-shell-ui';
import { find, isEmpty, isNaN, omit, startsWith } from 'lodash';
import moment from 'moment';
import momentLocalizer from 'react-widgets-moment';
Expand All @@ -12,9 +13,10 @@ import { getIdentityItems } from './get-identity-items';
import { Folders, LinkFolder } from '../carbonio-ui-commons/types';
import { getPrefs } from '../carbonio-ui-commons/utils/get-prefs';
import { PREFS_DEFAULTS } from '../constants';
import { EventPropType, normalizeEditor } from '../normalizations/normalize-editor';
import { normalizeEditor } from '../normalizations/normalize-editor';
import { createNewEditor } from '../store/slices/editor-slice';
import { Editor } from '../types/editor';
import { EventType } from '../types/event';
import { Invite } from '../types/store/invite';
import { getNewId } from '../utils/event';

Expand Down Expand Up @@ -64,7 +66,12 @@ export const createEmptyEditor = (id: string, folders: Folders): Editor => {
zimbraPrefCalendarApptReminderWarningTime,
zimbraPrefDefaultCalendarId
} = getPrefs();
const defaultOrganizer = find(identities, ['identityName', 'DEFAULT']);
const account = getUserAccount();
const defaultOrganizerIdentity = find(identities, ['identityName', 'DEFAULT']);
const defaultOrganizer = {
email: defaultOrganizerIdentity?.address ?? account?.name ?? '',
fullName: defaultOrganizerIdentity?.fullName
};
const defaultCalendar = find(folders, [
'id',
zimbraPrefDefaultCalendarId ?? PREFS_DEFAULTS.DEFAULT_CALENDAR_ID
Expand Down Expand Up @@ -128,7 +135,7 @@ export const applyContextToEditor = ({
context
}: {
editor: Editor;
context: any;
context: EditorContext;
}): Editor => {
const contextObj = omit(context, ['disabled', 'folders', 'dispatch']);
let editorWithContext = { ...editor };
Expand Down Expand Up @@ -161,7 +168,7 @@ export const generateEditor = ({
invite,
context
}: {
event?: EventPropType;
event?: EventType;
invite?: Invite;
context: EditorContext;
}): Editor => {
Expand Down
2 changes: 1 addition & 1 deletion src/commons/get-appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const getAppointmentAndInvite = async ({
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
export const normalizeFromGetAppointment = (appt: any): Appointment => <Appointment>omitBy(
{
id: appt?.apptId,
id: appt?.id,
l: appt.ciFolder,
alarm: appt?.inv?.[0]?.comp?.[0]?.alarm,
alarmData: appt?.inv?.[0]?.comp?.[0]?.alarmData,
Expand Down
9 changes: 7 additions & 2 deletions src/normalizations/normalize-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { CALENDAR_RESOURCES, PREFS_DEFAULTS } from '../constants';
import { PARTICIPANT_ROLE } from '../constants/api';
import { CRB_XPARAMS, CRB_XPROPS } from '../constants/xprops';
import { CalendarEditor, Editor } from '../types/editor';
import { DateType } from '../types/event';
import { DateType, EventType } from '../types/event';
import { Attendee, Invite } from '../types/store/invite';

// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
Expand Down Expand Up @@ -187,10 +187,14 @@ export const normalizeEditor = ({
}: {
emptyEditor: Editor;
invite?: Invite;
event?: EventPropType;
event?: EventType;
context: any;
}): Editor => {
if (event && invite) {
const organizer = {
email: event.resource.organizer?.email ?? '',
fullName: event.resource.organizer?.name
};
const isSeries = event?.resource?.isRecurrent;
const isInstance = context?.isInstance ?? !!event?.resource?.ridZ;
const isException = event?.resource?.isException ?? false;
Expand Down Expand Up @@ -228,6 +232,7 @@ export const normalizeEditor = ({
isInstance,
isSeries,
isException,
organizer,
exceptId: invite?.exceptId,
title: event?.title,
location: event?.resource?.location,
Expand Down
26 changes: 12 additions & 14 deletions src/normalizations/normalize-soap-message-from-editor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ import {
} from '../carbonio-ui-commons/test/mocks/accounts/fakeAccounts';
import { generateEditor } from '../commons/editor-generator';
import { getIdentityItems } from '../commons/get-identity-items';
import mockedData from '../test/generators';
import { ParticipationStatus } from '../types/store/invite';
import { Editor } from '../types/editor';

const mainAccount = createFakeIdentity();
const identity = createFakeIdentity();
Expand Down Expand Up @@ -197,7 +195,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: mainAccountEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -232,7 +230,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: mainAccountEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -277,7 +275,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: mainAccountEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -315,7 +313,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: mainAccountEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -415,7 +413,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -449,7 +447,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -486,7 +484,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -525,7 +523,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedEditorFolder,
sender: identities[0]
sender: { email: identities[0].address ?? '', fullName: identities[0].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -558,7 +556,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedEditorFolder,
sender: identities[0]
sender: { email: identities[0].address ?? '', fullName: identities[0].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -591,7 +589,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -686,7 +684,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedAccountEditorFolder,
sender: identities[1]
sender: { email: identities[1].address ?? '', fullName: identities[1].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down Expand Up @@ -720,7 +718,7 @@ describe('normalize soap message from editor', () => {
folders: {},
dispatch: jest.fn(),
calendar: sharedAccountEditorFolder,
sender: identities[2]
sender: { email: identities[2].address ?? '', fullName: identities[2].fullName }
}
});
const body = normalizeSoapMessageFromEditor(editor);
Expand Down
22 changes: 10 additions & 12 deletions src/normalizations/normalize-soap-message-from-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,14 @@ type Participants = {
t: string;
};

const isEventSentFromOrganizer = (organizer: string, sender: { address: string }): boolean =>
organizer === sender.address;
const isEventSentFromOrganizer = (organizer: string, sender: { email: string }): boolean =>
organizer === sender.email;

const isTheSameIdentity = (
organizer: { identityName: string },
sender: { identityName: string }
): boolean => organizer.identityName === sender.identityName;
const isTheSameIdentity = (organizer: CalendarOrganizer, sender: CalendarSender): boolean =>
organizer.email === sender.email && organizer.fullName === sender.fullName;

const isTheSameEmail = (organizer: string, sender: { address: string }): boolean =>
organizer === sender.address;
const isTheSameEmail = (organizer: string, sender: { email: string }): boolean =>
organizer === sender.email;

const setResourceDate = ({
time,
Expand Down Expand Up @@ -126,7 +124,7 @@ export const generateParticipantInformation = (resource: Editor): Array<Partial<

const sender = omitBy<Participants>(
{
a: resource?.sender?.address ?? resource?.sender?.label,
a: resource?.sender?.email ?? resource?.sender?.fullName,
p: resource?.sender?.fullName,
t: 's'
},
Expand Down Expand Up @@ -183,7 +181,7 @@ const getOrganizer = ({
{
email: user?.name,
name: organizer.fullName,
sentBy: isSameEmail ? undefined : sender.address
sentBy: isSameEmail ? undefined : sender.email
},
isNil
);
Expand All @@ -192,7 +190,7 @@ const getOrganizer = ({
{
email: user?.name,
name: sender.fullName,
sentBy: isSameEmail ? undefined : sender.address
sentBy: isSameEmail ? undefined : sender.email
},
isNil
);
Expand All @@ -205,7 +203,7 @@ const getOrganizer = ({
}
return {
email: calendar.owner,
sentBy: sender.address
sentBy: sender.email
};
};

Expand Down
2 changes: 1 addition & 1 deletion src/soap/counter-appointment-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const counterAppointmentRequest = async ({
d: moment(moment(appt.end)).format('YYYYMMDDTHHmm00')
},
exceptId: appt.exceptId,
or: { a: appt.organizer?.address },
or: { a: appt.organizer?.email },
s: {
tz: appt?.timezone,
d: moment(moment(appt.start)).format('YYYYMMDDTHHmm00')
Expand Down
4 changes: 2 additions & 2 deletions src/store/reducers/editor-reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import type { PayloadAction } from '@reduxjs/toolkit';
import { isNil, union } from 'lodash';

import type { CalendarEditor, Resource, IdentityItem, Editor, Room } from '../../types/editor';
import { CalendarEditor, Resource, Editor, Room, CalendarSender } from '../../types/editor';
import { EditorChipAttendees, InviteClass, InviteFreeBusy } from '../../types/store/invite';
import type { EditorSlice } from '../../types/store/store';

type SenderPayload = {
id: string | undefined;
sender: IdentityItem;
sender: CalendarSender;
};

type TitlePayload = {
Expand Down
Loading